1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
| Public Class Form1
Inherits System.Windows.Forms.Form
Dim tableau1(5, 5) As Button
Dim tableau2(5, 5) As Button
Dim i, j, k, l As Integer
Dim ibouton1, jbouton1, ibouton2, jbouton2 As Integer
Dim clicbouton2 As Boolean = False
Dim couleur As Boolean = True
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Size = New Size(850, 700)
Me.StartPosition = FormStartPosition.CenterScreen
For i As Integer = 0 To 5
For j As Integer = 0 To 5
tableau1(i, j) = New Button
tableau1(i, j).Visible = True
Me.Controls.Add(tableau1(i, j))
tableau1(i, j).Tag = i.ToString + ";" + j.ToString
AddHandler tableau1(i, j).Click, AddressOf tableau_Click
tableau1(i, j).Top = i * 100
tableau1(i, j).Left = j * 100
tableau1(i, j).Width = 90
tableau1(i, j).Height = 90
tableau1(i, j).BackColor = Color.Gray
Next
Next
For i As Integer = 0 To 5
For j As Integer = 0 To 5
tableau2(i, j) = New Button
tableau2(i, j).Visible = True
Me.Controls.Add(tableau2(i, j))
tableau2(i, j).Top = i * 100
tableau2(i, j).Left = j * 100
tableau2(i, j).Width = 90
tableau2(i, j).Height = 90
Next
Next
tableau2(0, 0).BackColor = Color.Yellow
tableau2(0, 1).BackColor = Color.Yellow
tableau2(0, 2).BackColor = Color.Blue
tableau2(0, 3).BackColor = Color.Blue
tableau2(0, 4).BackColor = Color.Red
tableau2(0, 5).BackColor = Color.Red
tableau2(1, 0).BackColor = Color.White
tableau2(1, 1).BackColor = Color.White
tableau2(1, 2).BackColor = Color.Black
tableau2(1, 3).BackColor = Color.Black
tableau2(1, 4).BackColor = Color.DarkMagenta
tableau2(1, 5).BackColor = Color.DarkMagenta
tableau2(2, 0).BackColor = Color.Maroon
tableau2(2, 1).BackColor = Color.Maroon
tableau2(2, 2).BackColor = Color.Orange
tableau2(2, 3).BackColor = Color.Orange
tableau2(2, 4).BackColor = Color.Cyan
tableau2(2, 5).BackColor = Color.Cyan
tableau2(3, 0).BackColor = Color.Green
tableau2(3, 1).BackColor = Color.Green
tableau2(3, 2).BackColor = Color.HotPink
tableau2(3, 3).BackColor = Color.HotPink
tableau2(3, 4).BackColor = Color.DarkKhaki
tableau2(3, 5).BackColor = Color.DarkKhaki
tableau2(4, 0).BackColor = Color.Violet
tableau2(4, 1).BackColor = Color.Violet
tableau2(4, 2).BackColor = Color.DarkGray
tableau2(4, 3).BackColor = Color.DarkGray
tableau2(4, 4).BackColor = Color.DarkRed
tableau2(4, 5).BackColor = Color.DarkRed
tableau2(5, 0).BackColor = Color.Honeydew
tableau2(5, 1).BackColor = Color.Honeydew
tableau2(5, 2).BackColor = Color.DeepSkyBlue
tableau2(5, 3).BackColor = Color.DeepSkyBlue
tableau2(5, 4).BackColor = Color.Fuchsia
tableau2(5, 5).BackColor = Color.Fuchsia
For i As Integer = 0 To 5
For j As Integer = 0 To 5
Randomize()
Dim value1 As Integer = CInt(Int((6 * Rnd())))
Dim value2 As Integer = CInt(Int((6 * Rnd())))
Dim button1 As Color = tableau2(i, j).BackColor
tableau2(i, j).BackColor = tableau2(value1, value2).BackColor
tableau2(value1, value2).BackColor = button1
Next
Next
JOUER.Visible = False
If couleur = True Then
JOUER.Visible = True
End If
End Sub
Private Sub tableau_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim coord() As String
' Variable que restera à True si toutes
' les couleurs ont été trouvées
coord = Split(sender.tag, ";")
' Si c'est le premier bouton qu'on clic
If clicbouton2 = False Then
' On récupère les coordonnées
ibouton1 = CInt(coord(0))
jbouton1 = CInt(coord(1))
' On rend invisible le bouton gris
tableau1(ibouton1, jbouton1).Visible = False
' On met cette variable à True pour dire que le
' prochain clic sera celui du 2° bouton
clicbouton2 = True
' C'est le clic sur le deuxième bouton
ElseIf clicbouton2 = True Then
' Avec les 2 boucles For, on désactive
' le clic sur un autre bouton jusqu'à ce
' que les boutons soit vérifiés et correct
' soit qu'ils sont pas correct et remis en
' gris
For nb1 As Integer = 0 To 5
For nb2 As Integer = 0 To 5
tableau1(nb1, nb2).Enabled = False
Next
Next
' On récupère les coordonnées
ibouton2 = CInt(coord(0))
jbouton2 = CInt(coord(1))
' On rend invisible le bouton gris
tableau1(ibouton2, jbouton2).Visible = False
' Si les couleurs entre le 1° bouton cliqué et le 2° bouton sont identiques
If tableau2(ibouton1, jbouton1).BackColor = tableau2(ibouton2, jbouton2).BackColor Then
' On ne fait rien
' On remet juste clicbouton2 à False
' pour dire que le prochain clic sera de
' nouveau le 1° bouton
clicbouton2 = False
Else
' Les couleurs ne sont pas identiques
' Création d'une attente de 2 secondes
hbwait(500)
' On affiche de nouveau les 2 boutons gris
tableau1(ibouton1, jbouton1).Visible = True
tableau1(ibouton2, jbouton2).Visible = True
' On remet juste clicbouton2 à False
' pour dire que le prochain clic sera de
' nouveau le 1° bouton
clicbouton2 = False
End If
End If
' Avec les 2 boucles For, on réactive
' le clic sur un autre bouton
For nb1 As Integer = 0 To 5
For nb2 As Integer = 0 To 5
tableau1(nb1, nb2).Enabled = True
Next
Next
' Avec ces 2 boucles, on teste si toutes les couleurs
' ont été trouvées si ce n'est pas le cas, la variable
' colorsfound passe à False
For nb1 As Integer = 0 To 3
For nb2 As Integer = 0 To 3
If tableau1(nb1, nb2).Visible = True Then
couleur = False
End If
Next
Next
If couleur = True Then
MsgBox("Félicitation, vous avez gagné!")
End If
End Sub
Friend Sub hbwait(ByVal ms_to_wait As Long)
Dim endwait As Double
endwait = Environment.TickCount + ms_to_wait
While Environment.TickCount < endwait
System.Threading.Thread.Sleep(1)
Application.DoEvents()
End While
End Sub
Private Sub JOUER_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles JOUER.Click
For i As Integer = 0 To 5
For j As Integer = 0 To 5
Randomize()
Dim value1 As Integer = CInt(Int((6 * Rnd())))
Dim value2 As Integer = CInt(Int((6 * Rnd())))
Dim button1 As Color = tableau2(i, j).BackColor
tableau2(i, j).BackColor = tableau2(value1, value2).BackColor
tableau2(value1, value2).BackColor = button1
Next
Next
If couleur = True Then
tableau2(i, j).Visible = False
End If
End Sub
End Class |
Partager