Public Class Form1
Dim BoardHuman(4, 4) As PictureBox
Dim BoardPC(4, 4) As PictureBox
Dim Barche_Restanti As Int16 = 4
Dim HumanCount As Int16
Dim PCCount As Int16
Dim turno As Boolean = True
Dim rndx As New Random
Dim rndy As New Random
Dim a, b As String
Dim c, d As Integer
Dim g, f As New Random
Dim one, two, three, four As String
Dim MDODICI As Integer
Private Sub Add_Handler()
'Aggiungi eventi a tutte le caselle BoardHuman
AddHandler BoardHuman(1, 1).Click, AddressOf BoardHuman11_Click
AddHandler BoardHuman(1, 2).Click, AddressOf BoardHuman12_Click
AddHandler BoardHuman(1, 3).Click, AddressOf BoardHuman13_Click
AddHandler BoardHuman(1, 4).Click, AddressOf BoardHuman14_Click
AddHandler BoardHuman(2, 1).Click, AddressOf BoardHuman21_Click
AddHandler BoardHuman(2, 2).Click, AddressOf BoardHuman22_Click
AddHandler BoardHuman(2, 3).Click, AddressOf BoardHuman23_Click
AddHandler BoardHuman(2, 4).Click, AddressOf BoardHuman24_Click
AddHandler BoardHuman(3, 1).Click, AddressOf BoardHuman31_Click
AddHandler BoardHuman(3, 2).Click, AddressOf BoardHuman32_Click
AddHandler BoardHuman(3, 3).Click, AddressOf BoardHuman33_Click
AddHandler BoardHuman(3, 4).Click, AddressOf BoardHuman34_Click
AddHandler BoardHuman(4, 1).Click, AddressOf BoardHuman41_Click
AddHandler BoardHuman(4, 2).Click, AddressOf BoardHuman42_Click
AddHandler BoardHuman(4, 3).Click, AddressOf BoardHuman43_Click
AddHandler BoardHuman(4, 4).Click, AddressOf BoardHuman44_Click
AddHandler BoardPC(1, 1).Click, AddressOf BoardPC11_Click
AddHandler BoardPC(1, 2).Click, AddressOf BoardPC12_Click
AddHandler BoardPC(1, 3).Click, AddressOf BoardPC13_Click
AddHandler BoardPC(1, 4).Click, AddressOf BoardPC14_Click
AddHandler BoardPC(2, 1).Click, AddressOf BoardPC21_Click
AddHandler BoardPC(2, 2).Click, AddressOf BoardPC22_Click
AddHandler BoardPC(2, 3).Click, AddressOf BoardPC23_Click
AddHandler BoardPC(2, 4).Click, AddressOf BoardPC24_Click
AddHandler BoardPC(3, 1).Click, AddressOf BoardPC31_Click
AddHandler BoardPC(3, 2).Click, AddressOf BoardPC32_Click
AddHandler BoardPC(3, 3).Click, AddressOf BoardPC33_Click
AddHandler BoardPC(3, 4).Click, AddressOf BoardPC34_Click
AddHandler BoardPC(4, 1).Click, AddressOf BoardPC41_Click
AddHandler BoardPC(4, 2).Click, AddressOf BoardPC42_Click
AddHandler BoardPC(4, 3).Click, AddressOf BoardPC43_Click
AddHandler BoardPC(4, 4).Click, AddressOf BoardPC44_Click
End Sub
Private Sub Resetta_variabili()
Barche_Restanti = 4
PCCount = 0
HumanCount = 0
Label5.Text = "Barche restanti: 4"
Label6.Text = "Posiziona la tua flotta"
MDODICI = 0
For i = 1 To 4
For j = 1 To 4
BoardHuman(i, j).BackColor = Color.White
BoardPC(i, j).BackColor = Color.White
Next
Next
turno = True
Calcola_4_posizioni()
End Sub
Private Sub Calcola_4_posizioni()
'Prima posizione scelta dal PC
c = g.Next(1, 5)
f.Next(1, 5)
d = f.Next(1, 5)
one = c & " " & d
'Seconda posizione scelta dal PC
c = g.Next(1, 5)
f.Next(1, 5)
d = f.Next(1, 5)
two = c & " " & d
'Terza posizione scelta dal PC
c = g.Next(1, 5)
f.Next(1, 5)
d = f.Next(1, 5)
three = c & " " & d
'Quarta posizione scelta dal PC
c = g.Next(1, 5)
f.Next(1, 5)
d = f.Next(1, 5)
four = c & " " & d
If one = two Or one = three Or one = four _
Or two = one Or two = three Or two = four _
Or three = one Or three = two Or three = four _
Or four = one Or four = two Or four = three Then
Calcola_4_posizioni()
End If
turno = True
End Sub
Private Sub posizione_A_caso()
If Label3.Visible = True Then
Exit Sub
End If
If PCCount = 4 Then
Exit Sub
End If
'Se è il turno del computer
If turno = False Then
'Se hai posizionato tutte le barche
If MDODICI >= 12 Then
MsgBox("Hai sprecato tutti i tentativi, hai perso!", MsgBoxStyle.Exclamation)
Resetta_variabili()
Exit Sub
End If
If Not Label6.Text = "Buon gioco" Then
MsgBox("Posizionare prima le navi", MsgBoxStyle.Critical)
Exit Sub
End If
'Posizione a caso
a = rndy.Next(1, 5)
rndx.Next(1, 5)
b = rndx.Next(1, 5)
'Se va sul colore bianco o sul colore verde
If BoardHuman(a, b).BackColor = Color.White Then
If RadioButton1.Checked = True Then
BoardHuman(a, b).BackColor = Color.Red
My.Computer.Audio.Play(My.Resources.Boink1, AudioPlayMode.Background)
turno = True
ElseIf RadioButton2.Checked = True Then
If MDODICI >= 12 Then
MsgBox("Hai sprecato tutti i tentativi, hai perso!", MsgBoxStyle.Critical)
Resetta_variabili()
End If
MDODICI += 1
BoardHuman(a, b).BackColor = Color.Red
My.Computer.Audio.Play(My.Resources.Boink1, AudioPlayMode.Background)
turno = True
End If
ElseIf BoardHuman(a, b).BackColor = Color.Lime Then
If RadioButton1.Checked = True Then
My.Computer.Audio.Play(My.Resources.Boink2, AudioPlayMode.Background)
BoardHuman(a, b).BackColor = Color.Red
'Conta come nave distrutta
PCCount += 1
'Se ha abbattuto tutte e 4 le navi
If PCCount >= 4 Then
MsgBox("Hai perso", MsgBoxStyle.Exclamation)
'Resetta le variabili
Resetta_variabili()
Return
End If
ElseIf RadioButton2.Checked = True Then
If BoardHuman(a, b).BackColor = Color.Lime Then
posizione_A_caso()
End If
End If
'Se ha colpito una sua casella, tenta di nuovo
ElseIf BoardHuman(a, b).BackColor = Color.Red Then
posizione_A_caso()
Exit Sub
End If
turno = True
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label1.Visible = False
Label2.Visible = False
End Sub
#Region "Colora BoardHuman"
Private Sub BoardHuman31_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Barche_Restanti > 0 Then
If BoardHuman(3, 1).BackColor = Color.Lime Then
Exit Sub
End If
BoardHuman(3, 1).BackColor = Color.Lime
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
Barche_Restanti -= 1
Label5.Text = "Barche restanti: " & Barche_Restanti
If Barche_Restanti = 0 Then
Label6.Text = "Buon gioco"
End If
End If
End Sub
Private Sub BoardHuman32_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If BoardHuman(3, 2).BackColor = Color.Lime Then
Exit Sub
End If
If Barche_Restanti > 0 Then
BoardHuman(3, 2).BackColor = Color.Lime
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
Barche_Restanti -= 1
Label5.Text = "Barche restanti: " & Barche_Restanti
If Barche_Restanti = 0 Then
Label6.Text = "Buon gioco"
End If
End If
End Sub
Private Sub BoardHuman33_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Barche_Restanti > 0 Then
If BoardHuman(3, 3).BackColor = Color.Lime Then
Exit Sub
End If
BoardHuman(3, 3).BackColor = Color.Lime
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
Barche_Restanti -= 1
Label5.Text = "Barche restanti: " & Barche_Restanti
If Barche_Restanti = 0 Then
Label6.Text = "Buon gioco"
End If
End If
End Sub
Private Sub BoardHuman34_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Barche_Restanti > 0 Then
If BoardHuman(3, 4).BackColor = Color.Lime Then
Exit Sub
End If
BoardHuman(3, 4).BackColor = Color.Lime
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
Barche_Restanti -= 1
Label5.Text = "Barche restanti: " & Barche_Restanti
If Barche_Restanti = 0 Then
Label6.Text = "Buon gioco"
End If
End If
End Sub
Private Sub BoardHuman41_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Barche_Restanti > 0 Then
If BoardHuman(4, 1).BackColor = Color.Lime Then
Exit Sub
End If
BoardHuman(4, 1).BackColor = Color.Lime
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
Barche_Restanti -= 1
Label5.Text = "Barche restanti: " & Barche_Restanti
If Barche_Restanti = 0 Then
Label6.Text = "Buon gioco"
End If
End If
End Sub
Private Sub BoardHuman42_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Barche_Restanti > 0 Then
If BoardHuman(4, 2).BackColor = Color.Lime Then
Exit Sub
End If
BoardHuman(4, 2).BackColor = Color.Lime
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
Barche_Restanti -= 1
Label5.Text = "Barche restanti: " & Barche_Restanti
If Barche_Restanti = 0 Then
Label6.Text = "Buon gioco"
End If
End If
End Sub
Private Sub BoardHuman43_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Barche_Restanti > 0 Then
If BoardHuman(4, 3).BackColor = Color.Lime Then
Exit Sub
End If
BoardHuman(4, 3).BackColor = Color.Lime
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
Barche_Restanti -= 1
Label5.Text = "Barche restanti: " & Barche_Restanti
If Barche_Restanti = 0 Then
Label6.Text = "Buon gioco"
End If
End If
End Sub
Private Sub BoardHuman44_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Barche_Restanti > 0 Then
If BoardHuman(4, 4).BackColor = Color.Lime Then
Exit Sub
End If
BoardHuman(4, 4).BackColor = Color.Lime
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
Barche_Restanti -= 1
Label5.Text = "Barche restanti: " & Barche_Restanti
If Barche_Restanti = 0 Then
Label6.Text = "Buon gioco"
End If
End If
End Sub
Private Sub BoardHuman11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Barche_Restanti > 0 Then
If BoardHuman(1, 1).BackColor = Color.Lime Then
Exit Sub
End If
BoardHuman(1, 1).BackColor = Color.Lime
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
Barche_Restanti -= 1
Label5.Text = "Barche restanti: " & Barche_Restanti
If Barche_Restanti = 0 Then
Label6.Text = "Buon gioco"
End If
End If
End Sub
Private Sub BoardHuman12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Barche_Restanti > 0 Then
If BoardHuman(1, 2).BackColor = Color.Lime Then
Exit Sub
End If
BoardHuman(1, 2).BackColor = Color.Lime
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
Barche_Restanti -= 1
Label5.Text = "Barche restanti: " & Barche_Restanti
If Barche_Restanti = 0 Then
Label6.Text = "Buon gioco"
End If
End If
End Sub
Private Sub BoardHuman13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Barche_Restanti > 0 Then
If BoardHuman(1, 3).BackColor = Color.Lime Then
Exit Sub
End If
BoardHuman(1, 3).BackColor = Color.Lime
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
Barche_Restanti -= 1
Label5.Text = "Barche restanti: " & Barche_Restanti
If Barche_Restanti = 0 Then
Label6.Text = "Buon gioco"
End If
End If
End Sub
Private Sub BoardHuman14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Barche_Restanti > 0 Then
If BoardHuman(1, 4).BackColor = Color.Lime Then
Exit Sub
End If
BoardHuman(1, 4).BackColor = Color.Lime
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
Barche_Restanti -= 1
Label5.Text = "Barche restanti: " & Barche_Restanti
If Barche_Restanti = 0 Then
Label6.Text = "Buon gioco"
End If
End If
End Sub
Private Sub BoardHuman21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Barche_Restanti > 0 Then
If BoardHuman(2, 1).BackColor = Color.Lime Then
Exit Sub
End If
BoardHuman(2, 1).BackColor = Color.Lime
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
Barche_Restanti -= 1
Label5.Text = "Barche restanti: " & Barche_Restanti
If Barche_Restanti = 0 Then
Label6.Text = "Buon gioco"
End If
End If
End Sub
Private Sub BoardHuman22_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Barche_Restanti > 0 Then
If BoardHuman(2, 2).BackColor = Color.Lime Then
Exit Sub
End If
BoardHuman(2, 2).BackColor = Color.Lime
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
Barche_Restanti -= 1
Label5.Text = "Barche restanti: " & Barche_Restanti
If Barche_Restanti = 0 Then
Label6.Text = "Buon gioco"
End If
End If
End Sub
Private Sub BoardHuman23_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Barche_Restanti > 0 Then
If BoardHuman(2, 3).BackColor = Color.Lime Then
Exit Sub
End If
BoardHuman(2, 3).BackColor = Color.Lime
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
Barche_Restanti -= 1
Label5.Text = "Barche restanti: " & Barche_Restanti
If Barche_Restanti = 0 Then
Label6.Text = "Buon gioco"
End If
End If
End Sub
Private Sub BoardHuman24_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Barche_Restanti > 0 Then
If BoardHuman(2, 4).BackColor = Color.Lime Then
Exit Sub
End If
BoardHuman(2, 4).BackColor = Color.Lime
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
Barche_Restanti -= 1
Label5.Text = "Barche restanti: " & Barche_Restanti
If Barche_Restanti = 0 Then
Label6.Text = "Buon gioco"
End If
End If
End Sub
#End Region
#Region "Colora BoardPC"
Private Sub BoardPC31_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Barche_Restanti = 0 Then
If BoardPC(3, 1).BackColor = Color.Yellow Or BoardPC(3, 1).BackColor = Color.Lime Then
Exit Sub
End If
If turno = True Then
BoardPC(3, 1).BackColor = Color.Yellow
If one = "3 1" Or two = "3 1" Or three = "3 1" Or four = "3 1" Then
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
BoardPC(3, 1).BackColor = Color.Lime
HumanCount += 1
If HumanCount = 4 Then
MsgBox("Hai vinto!", MsgBoxStyle.Exclamation)
Resetta_variabili()
Exit Sub
End If
Else
My.Computer.Audio.Play(My.Resources.Boink1, AudioPlayMode.Background)
End If
End If
turno = False
posizione_A_caso()
End If
End Sub
Private Sub BoardPC32_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Barche_Restanti = 0 Then
If BoardPC(3, 2).BackColor = Color.Yellow Or BoardPC(3, 2).BackColor = Color.Lime Then
Exit Sub
End If
If turno = True Then
BoardPC(3, 2).BackColor = Color.Yellow
If one = "3 2" Or two = "3 2" Or three = "3 2" Or four = "3 2" Then
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
BoardPC(3, 2).BackColor = Color.Lime
HumanCount += 1
If HumanCount = 4 Then
Resetta_variabili()
Exit Sub
End If
Else
My.Computer.Audio.Play(My.Resources.Boink1, AudioPlayMode.Background)
End If
End If
turno = False
posizione_A_caso()
End If
End Sub
Private Sub BoardPC33_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If BoardPC(3, 3).BackColor = Color.Yellow Or BoardPC(3, 3).BackColor = Color.Lime Then
Exit Sub
End If
If Barche_Restanti = 0 Then
If turno = True Then
BoardPC(3, 3).BackColor = Color.Yellow
If one = "3 3" Or two = "3 3" Or three = "3 3" Or four = "3 3" Then
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
BoardPC(3, 3).BackColor = Color.Lime
HumanCount += 1
If HumanCount = 4 Then
MsgBox("Hai vinto!", MsgBoxStyle.Exclamation)
Resetta_variabili()
Exit Sub
End If
Else
My.Computer.Audio.Play(My.Resources.Boink1, AudioPlayMode.Background)
End If
End If
turno = False
posizione_A_caso()
End If
End Sub
Private Sub BoardPC34_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If BoardPC(3, 4).BackColor = Color.Yellow Or BoardPC(3, 4).BackColor = Color.Lime Then
Exit Sub
End If
If Barche_Restanti = 0 Then
If turno = True Then
BoardPC(3, 4).BackColor = Color.Yellow
If one = "3 4" Or two = "3 4" Or three = "3 4" Or four = "3 4" Then
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
BoardPC(3, 4).BackColor = Color.Lime
HumanCount += 1
If HumanCount = 4 Then
MsgBox("Hai vinto!", MsgBoxStyle.Exclamation)
Resetta_variabili()
Exit Sub
End If
Else
My.Computer.Audio.Play(My.Resources.Boink1, AudioPlayMode.Background)
End If
End If
turno = False
posizione_A_caso()
End If
End Sub
Private Sub BoardPC41_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If BoardPC(4, 1).BackColor = Color.Yellow Or BoardPC(4, 1).BackColor = Color.Lime Then
Exit Sub
End If
If Barche_Restanti = 0 Then
If turno = True Then
BoardPC(4, 1).BackColor = Color.Yellow
If one = "4 1" Or two = "4 1" Or three = "4 1" Or four = "4 1" Then
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
BoardPC(4, 1).BackColor = Color.Lime
HumanCount += 1
If HumanCount = 4 Then
MsgBox("Hai vinto!", MsgBoxStyle.Exclamation)
Resetta_variabili()
Exit Sub
End If
Else
My.Computer.Audio.Play(My.Resources.Boink1, AudioPlayMode.Background)
End If
End If
turno = False
posizione_A_caso()
End If
End Sub
Private Sub BoardPC42_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If BoardPC(4, 2).BackColor = Color.Yellow Or BoardPC(4, 2).BackColor = Color.Lime Then
Exit Sub
End If
If Barche_Restanti = 0 Then
If turno = True Then
BoardPC(4, 2).BackColor = Color.Yellow
If one = "4 2" Or two = "4 2" Or three = "4 2" Or four = "4 2" Then
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
BoardPC(4, 2).BackColor = Color.Lime
HumanCount += 1
If HumanCount = 4 Then
MsgBox("Hai vinto!", MsgBoxStyle.Exclamation)
Resetta_variabili()
Exit Sub
End If
Else
My.Computer.Audio.Play(My.Resources.Boink1, AudioPlayMode.Background)
End If
End If
turno = False
posizione_A_caso()
End If
End Sub
Private Sub BoardPC43_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If BoardPC(4, 3).BackColor = Color.Yellow Or BoardPC(4, 3).BackColor = Color.Lime Then
Exit Sub
End If
If Barche_Restanti = 0 Then
If turno = True Then
If BoardPC(4, 3).BackColor = Color.Yellow Or BoardPC(4, 3).BackColor = Color.Lime Then
Exit Sub
End If
BoardPC(4, 3).BackColor = Color.Yellow
If one = "4 3" Or two = "4 3" Or three = "4 3" Or four = "4 3" Then
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
BoardPC(4, 3).BackColor = Color.Lime
HumanCount += 1
If HumanCount = 4 Then
MsgBox("Hai vinto!", MsgBoxStyle.Exclamation)
Resetta_variabili()
Exit Sub
End If
Else
My.Computer.Audio.Play(My.Resources.Boink1, AudioPlayMode.Background)
End If
End If
turno = False
posizione_A_caso()
End If
End Sub
Private Sub BoardPC44_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If BoardPC(4, 4).BackColor = Color.Yellow Or BoardPC(4, 4).BackColor = Color.Lime Then
Exit Sub
End If
If Barche_Restanti = 0 Then
If turno = True Then
BoardPC(4, 4).BackColor = Color.Yellow
If one = "4 4" Or two = "4 4" Or three = "4 4" Or four = "4 4" Then
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
BoardPC(4, 4).BackColor = Color.Lime
HumanCount += 1
If HumanCount = 4 Then
MsgBox("Hai vinto!", MsgBoxStyle.Exclamation)
Resetta_variabili()
Exit Sub
End If
Else
My.Computer.Audio.Play(My.Resources.Boink1, AudioPlayMode.Background)
End If
End If
turno = False
posizione_A_caso()
End If
End Sub
Private Sub BoardPC11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If BoardPC(1, 1).BackColor = Color.Yellow Or BoardPC(1, 1).BackColor = Color.Lime Then
Exit Sub
End If
If Barche_Restanti = 0 Then
If turno = True Then
BoardPC(1, 1).BackColor = Color.Yellow
If one = "1 1" Or two = "1 1" Or three = "1 1" Or four = "1 1" Then
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
BoardPC(1, 1).BackColor = Color.Lime
HumanCount += 1
If HumanCount = 4 Then
MsgBox("Hai vinto!", MsgBoxStyle.Exclamation)
Resetta_variabili()
Exit Sub
End If
Else
My.Computer.Audio.Play(My.Resources.Boink1, AudioPlayMode.Background)
End If
End If
turno = False
posizione_A_caso()
End If
End Sub
Private Sub BoardPC12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If BoardPC(1, 2).BackColor = Color.Yellow Or BoardPC(1, 2).BackColor = Color.Lime Then
Exit Sub
End If
If Barche_Restanti = 0 Then
If turno = True Then
BoardPC(1, 2).BackColor = Color.Yellow
If one = "1 2" Or two = "1 2" Or three = "1 2" Or four = "1 2" Then
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
BoardPC(1, 2).BackColor = Color.Lime
HumanCount += 1
If HumanCount = 4 Then
MsgBox("Hai vinto!", MsgBoxStyle.Exclamation)
Resetta_variabili()
Exit Sub
End If
Else
My.Computer.Audio.Play(My.Resources.Boink1, AudioPlayMode.Background)
End If
End If
turno = False
posizione_A_caso()
End If
End Sub
Private Sub BoardPC13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If BoardPC(1, 3).BackColor = Color.Yellow Or BoardPC(1, 3).BackColor = Color.Lime Then
Exit Sub
End If
If Barche_Restanti = 0 Then
If turno = True Then
BoardPC(1, 3).BackColor = Color.Yellow
If one = "1 3" Or two = "1 3" Or three = "1 3" Or four = "1 3" Then
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
BoardPC(1, 3).BackColor = Color.Lime
HumanCount += 1
If HumanCount = 4 Then
MsgBox("Hai vinto!", MsgBoxStyle.Exclamation)
Resetta_variabili()
Exit Sub
End If
Else
My.Computer.Audio.Play(My.Resources.Boink1, AudioPlayMode.Background)
End If
End If
turno = False
posizione_A_caso()
End If
End Sub
Private Sub BoardPC14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If BoardPC(1, 4).BackColor = Color.Yellow Or BoardPC(1, 4).BackColor = Color.Lime Then
Exit Sub
End If
If Barche_Restanti = 0 Then
If turno = True Then
BoardPC(1, 4).BackColor = Color.Yellow
If one = "1 4" Or two = "1 4" Or three = "1 4" Or four = "1 4" Then
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
BoardPC(1, 4).BackColor = Color.Lime
HumanCount += 1
If HumanCount = 4 Then
MsgBox("Hai vinto!", MsgBoxStyle.Exclamation)
Resetta_variabili()
Exit Sub
End If
Else
My.Computer.Audio.Play(My.Resources.Boink1, AudioPlayMode.Background)
End If
End If
turno = False
posizione_A_caso()
End If
End Sub
Private Sub BoardPC21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Barche_Restanti = 0 Then
If BoardPC(2, 1).BackColor = Color.Yellow Or BoardPC(2, 1).BackColor = Color.Lime Then
Exit Sub
End If
If turno = True Then
BoardPC(2, 1).BackColor = Color.Yellow
If one = "2 1" Or two = "2 1" Or three = "2 1" Or four = "2 1" Then
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
BoardPC(2, 1).BackColor = Color.Lime
HumanCount += 1
If HumanCount = 4 Then
MsgBox("Hai vinto!", MsgBoxStyle.Exclamation)
Resetta_variabili()
Exit Sub
End If
Else
My.Computer.Audio.Play(My.Resources.Boink1, AudioPlayMode.Background)
End If
End If
turno = False
posizione_A_caso()
End If
End Sub
Private Sub BoardPC22_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If BoardPC(2, 2).BackColor = Color.Yellow Or BoardPC(2, 2).BackColor = Color.Lime Then
Exit Sub
End If
If Barche_Restanti = 0 Then
If turno = True Then
BoardPC(2, 2).BackColor = Color.Yellow
If one = "2 2" Or two = "2 2" Or three = "2 2" Or four = "2 2" Then
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
BoardPC(2, 2).BackColor = Color.Lime
HumanCount += 1
If HumanCount = 4 Then
MsgBox("Hai vinto!", MsgBoxStyle.Exclamation)
Resetta_variabili()
Exit Sub
End If
Else
My.Computer.Audio.Play(My.Resources.Boink1, AudioPlayMode.Background)
End If
End If
turno = False
posizione_A_caso()
End If
End Sub
Private Sub BoardPC23_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If BoardPC(2, 3).BackColor = Color.Yellow Or BoardPC(2, 3).BackColor = Color.Lime Then
Exit Sub
End If
If Barche_Restanti = 0 Then
If turno = True Then
BoardPC(2, 3).BackColor = Color.Yellow
If one = "2 3" Or two = "2 3" Or three = "2 3" Or four = "2 3" Then
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
BoardPC(2, 3).BackColor = Color.Lime
HumanCount += 1
If HumanCount = 4 Then
MsgBox("Hai vinto!", MsgBoxStyle.Exclamation)
Resetta_variabili()
Exit Sub
End If
Else
My.Computer.Audio.Play(My.Resources.Boink1, AudioPlayMode.Background)
End If
End If
turno = False
posizione_A_caso()
End If
End Sub
Private Sub BoardPC24_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If BoardPC(2, 4).BackColor = Color.Yellow Or BoardPC(2, 4).BackColor = Color.Lime Then
Exit Sub
End If
If Barche_Restanti = 0 Then
If turno = True Then
BoardPC(2, 4).BackColor = Color.Yellow
If one = "2 4" Or two = "2 4" Or three = "2 4" Or four = "2 4" Then
My.Computer.Audio.Play(My.Resources.Beep, AudioPlayMode.Background)
BoardPC(2, 4).BackColor = Color.Lime
HumanCount += 1
If HumanCount = 4 Then
MsgBox("Hai vinto!", MsgBoxStyle.Exclamation)
Resetta_variabili()
Exit Sub
End If
Else
My.Computer.Audio.Play(My.Resources.Boink1, AudioPlayMode.Background)
End If
End If
turno = False
posizione_A_caso()
End If
End Sub
#End Region
Private Sub BoardPC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Not Label6.Text = "Buon gioco" Then
MsgBox("Posizionare prima le navi", MsgBoxStyle.Critical)
Exit Sub
End If
End Sub
Private Sub Starta()
Label1.Visible = True
Label2.Visible = True
Label3.Visible = False
Label4.Visible = False
Label5.Visible = True
Label6.Visible = True
For i = 1 To 4
For j = 1 To 4
BoardHuman(i, j) = New PictureBox
BoardHuman(i, j).Size = New Size(22, 22)
BoardHuman(i, j).BorderStyle = BorderStyle.FixedSingle
BoardHuman(i, j).Location = New Point(i * 21, j * 21 + 10)
BoardHuman(i, j).BackColor = Color.White
Me.Controls.Add(BoardHuman(i, j))
Next
Next
For i = 1 To 4
For j = 1 To 4
BoardPC(i, j) = New PictureBox
BoardPC(i, j).Size = New Size(22, 22)
BoardPC(i, j).BorderStyle = BorderStyle.FixedSingle
BoardPC(i, j).Location = New Point(i * 21, j * 21 + 130)
BoardPC(i, j).BackColor = Color.White
Me.Controls.Add(BoardPC(i, j))
AddHandler BoardPC(i, j).Click, AddressOf BoardPC_Click
Next
Next
Add_Handler()
Calcola_4_posizioni()
End Sub
Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click
Starta()
End Sub
Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click
Me.Close()
End Sub
Private Sub Label3_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label3.MouseDown
Label3.ForeColor = Color.DarkRed
End Sub
Private Sub Label3_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label3.MouseEnter
Label3.ForeColor = Color.Red
End Sub
Private Sub Label3_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label3.MouseLeave
Label3.ForeColor = Color.Black
End Sub
Private Sub Label4_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label4.MouseDown
Label4.ForeColor = Color.DarkRed
End Sub
Private Sub Label4_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label4.MouseEnter
Label4.ForeColor = Color.Red
End Sub
Private Sub Label4_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label4.MouseLeave
Label4.ForeColor = Color.Black
End Sub
Private Sub Label7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label7.Click
AboutBox1.ShowDialog()
End Sub
Private Sub Label7_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label7.MouseDown
Label7.BackColor = Color.Goldenrod
End Sub
Private Sub Label7_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label7.MouseEnter
Label7.BackColor = Color.Gold
End Sub
Private Sub Label7_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label7.MouseLeave
Label7.BackColor = Color.Transparent
End Sub
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
For I = 1 To 4
For J = 1 To 4
Controls.Remove(BoardHuman(I, J))
Controls.Remove(BoardPC(I, J))
Next
Next
Resetta_variabili()
Starta()
End Sub
Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click
Close()
End Sub
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
MenuItem7.Checked = True
MenuItem8.Checked = False
End Sub
Private Sub MenuItem7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem7.Click
If RadioButton2.Checked = True Then
RadioButton1.Checked = True
MenuItem7.Checked = True
MenuItem8.Checked = True
Else
RadioButton2.Checked = True
MenuItem7.Checked = False
MenuItem8.Checked = True
End If
End Sub
Private Sub MenuItem8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem8.Click
If RadioButton2.Checked = True Then
RadioButton1.Checked = True
MenuItem7.Checked = True
MenuItem8.Checked = True
Else
RadioButton2.Checked = True
MenuItem7.Checked = False
MenuItem8.Checked = True
End If
End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
MenuItem7.Checked = False
MenuItem8.Checked = True
End Sub
Private Sub MenuItem9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem9.Click
AboutBox1.ShowDialog()
End Sub
Private Sub MenuItem10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem10.Click
Try
Process.Start("Ship Battle Tutorial.rtf")
Catch ex As Exception
MsgBox("Il file Ship Battle Tutorial.rtf non è stato trovato, può essere stato spostato o rinominato", MsgBoxStyle.Critical)
End Try
End Sub
Private Sub MenuItem12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem12.Click
If MenuItem12.Checked = False Then
MenuItem12.Checked = True
Label10.Visible = True
TextBox1.Visible = True
Else
MenuItem12.Checked = False
Label10.Visible = False
TextBox1.Visible = False
End If
End Sub
Private Sub Verifica_Trucco_Seeall()
If one = "1 1" Or two = "1 1" Or three = "1 1" Or four = "1 1" Then
If Not BoardPC(1, 1).BackColor = Color.Lime Then BoardPC(1, 1).BackColor = Color.Blue
End If
If one = "1 2" Or two = "1 2" Or three = "1 2" Or four = "1 2" Then
If Not BoardPC(1, 2).BackColor = Color.Lime Then BoardPC(1, 2).BackColor = Color.Blue
End If
If one = "1 3" Or two = "1 3" Or three = "1 3" Or four = "1 3" Then
If Not BoardPC(1, 3).BackColor = Color.Lime Then BoardPC(1, 3).BackColor = Color.Blue
End If
If one = "1 4" Or two = "1 4" Or three = "1 4" Or four = "1 4" Then
If Not BoardPC(1, 4).BackColor = Color.Lime Then BoardPC(1, 4).BackColor = Color.Blue
End If
'
'
If one = "2 1" Or two = "2 1" Or three = "2 1" Or four = "2 1" Then
If Not BoardPC(2, 1).BackColor = Color.Lime Then BoardPC(2, 1).BackColor = Color.Blue
End If
If one = "2 2" Or two = "2 2" Or three = "2 2" Or four = "2 2" Then
If Not BoardPC(2, 2).BackColor = Color.Lime Then BoardPC(2, 2).BackColor = Color.Blue
End If
If one = "2 3" Or two = "2 3" Or three = "2 3" Or four = "2 3" Then
If Not BoardPC(2, 3).BackColor = Color.Lime Then BoardPC(2, 3).BackColor = Color.Blue
End If
If one = "2 4" Or two = "2 4" Or three = "2 4" Or four = "2 4" Then
If Not BoardPC(2, 4).BackColor = Color.Lime Then BoardPC(2, 4).BackColor = Color.Blue
End If
'
'
If one = "3 1" Or two = "3 1" Or three = "3 1" Or four = "3 1" Then
If Not BoardPC(3, 1).BackColor = Color.Lime Then BoardPC(3, 1).BackColor = Color.Blue
End If
If one = "3 2" Or two = "3 2" Or three = "3 2" Or four = "3 2" Then
If Not BoardPC(3, 2).BackColor = Color.Lime Then BoardPC(3, 2).BackColor = Color.Blue
End If
If one = "3 3" Or two = "3 3" Or three = "3 3" Or four = "3 3" Then
If Not BoardPC(3, 3).BackColor = Color.Lime Then BoardPC(3, 3).BackColor = Color.Blue
End If
If one = "3 4" Or two = "3 4" Or three = "3 4" Or four = "3 4" Then
If Not BoardPC(3, 4).BackColor = Color.Lime Then BoardPC(3, 4).BackColor = Color.Blue
End If
'
'
If one = "4 1" Or two = "4 1" Or three = "4 1" Or four = "4 1" Then
If Not BoardPC(4, 1).BackColor = Color.Lime Then BoardPC(4, 1).BackColor = Color.Blue
End If
If one = "4 2" Or two = "4 2" Or three = "4 2" Or four = "4 2" Then
If Not BoardPC(4, 2).BackColor = Color.Lime Then BoardPC(4, 2).BackColor = Color.Blue
End If
If one = "4 3" Or two = "4 3" Or three = "4 3" Or four = "4 3" Then
If Not BoardPC(4, 3).BackColor = Color.Lime Then BoardPC(4, 3).BackColor = Color.Blue
End If
If one = "4 4" Or two = "4 4" Or three = "4 4" Or four = "4 4" Then
If Not BoardPC(4, 4).BackColor = Color.Lime Then BoardPC(4, 4).BackColor = Color.Blue
End If
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
If TextBox1.Text = "" Then
Exit Sub
End If
If TextBox1.Text = "seeall" Then
TextBox1.Clear()
Verifica_Trucco_Seeall()
Exit Sub
End If
If TextBox1.Text = "deseeall" Then
TextBox1.Clear()
For i = 1 To 4
For j = 1 To 4
If BoardPC(i, j).BackColor = Color.Blue Then
BoardPC(i, j).BackColor = Color.White
End If
Next
Next
End If
End Sub
End Class