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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
| Imports system.net.sockets
Imports system.net
Imports System.Text
Public Class Form1
Dim udpClient As New UdpClient(2250)
Dim combi As String
Dim Message As [Byte]()
Dim bcontinuer As Boolean
Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)
Private Sub Button41_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b1.Click
rep1 = choose_color(b1)
End Sub
Private trd As New System.Threading.Thread(AddressOf ecoute)
Private Sub ecoute()
'boucle d'ecoute
bcontinuer = True
While bcontinuer
Message = udpClient.Receive(RemoteIpEndPoint)
combi = Encoding.ASCII.GetString(Message)
saisir_jeu(combi)
If combi <> "" Then
bcontinuer = False
End If
End While
'signal
End Sub
' fonction qui defnini la couleur d'un bouton et retourne son statut sous forme d'un entier
Function choose_color(ByVal name_button)
statut = 0
If nbclick = 0 Then
name_button.BackColor = Color.Black
statut = 0
nbclick = nbclick + 1
Else
If nbclick = 1 Then
name_button.BackColor = Color.Red
nbclick = nbclick + 1
statut = 1
Else
If nbclick = 2 Then
name_button.BackColor = Color.Green
nbclick = nbclick + 1
statut = 2
Else
If nbclick = 3 Then
name_button.BackColor = Color.Blue
nbclick = 0
statut = 3
End If
End If
End If
End If
Return statut
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
trd.Start()
End Sub
Private Sub b2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b2.Click
rep2 = choose_color(b2)
End Sub
Private Sub b3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b3.Click
rep3 = choose_color(b3)
End Sub
Private Sub b4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b4.Click
rep4 = choose_color(b4)
End Sub
Private Sub Button41_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button41.Click
'enregistre la tentative dans un tableau
rep(1, 1) = rep1
rep(2, 1) = rep2
rep(3, 1) = rep3
rep(4, 1) = rep4
tentative()
End Sub
'test la combinaison posté
Function tentative()
Dim i As Integer
Dim taux As Integer
Dim test2 As String
taux = 0
If tentatives < 10 Then
For i = 1 To 4
test2 = "t" & nbpassage + i
If solu(i, 1) = rep(i, 1) Then
taux = taux + 1
End If
Controls.Item(test2).BackColor = get_color(rep(i, 1))
If taux = 4 Then
' parti reussie on quitte la boucle
MsgBox("vous avez gagné")
Button41.Visible = False
Button2.Visible = True
Exit For
End If
Next
nbpassage = nbpassage + i - 1
'on test le nombre de tentatives
tentatives = tentatives + 1
Else
MsgBox("partie terminé")
Button41.Visible = False
Button2.Visible = True
End If
Return 1
End Function
' fonction qui met en mémoire la bonne combinaison
Function saisir_jeu(ByVal combi As String)
Dim solubrut() As String
solubrut = Split(combi, "#")
solu(1, 1) = CInt(solubrut(0))
solu(2, 1) = CInt(solubrut(1))
solu(3, 1) = CInt(solubrut(2))
solu(4, 1) = CInt(solubrut(3))
MsgBox(solu(1, 1))
MsgBox(solu(2, 1))
MsgBox(solu(3, 1))
MsgBox(solu(4, 1))
Return 1
End Function
Private Sub r1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles r1.Click
rr1 = choose_color(r1)
End Sub
Private Sub r2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles r2.Click
rr2 = choose_color(r2)
End Sub
Private Sub r3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles r3.Click
rr3 = choose_color(r3)
End Sub
Private Sub r4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles r4.Click
rr4 = choose_color(r4)
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' saisir_jeu()
Button1.Visible = False
Button41.Visible = True
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
' fonction qui retourne la couleur d'un controle selon son statut
Function get_color(ByVal testcol As Integer)
Dim col As Color
If testcol = 0 Then
col = Color.Black
Else
If testcol = 1 Then
col = Color.Red
Else
If testcol = 2 Then
col = Color.Green
Else
If testcol = 3 Then
col = Color.Blue
End If
End If
End If
End If
Return col
End Function
' fonction qui redonne couleur originel des boutons
Function efface_bouton()
Dim test2 As String
Dim i As Integer
For i = 1 To 40
test2 = "t" & i
Controls.Item(test2).BackColor() = Color.Empty
Next
r1.BackColor = Color.Empty
r2.BackColor = Color.Empty
r3.BackColor = Color.Empty
r4.BackColor = Color.Empty
b1.BackColor = Color.Empty
b2.BackColor = Color.Empty
b3.BackColor = Color.Empty
b4.BackColor = Color.Empty
Button2.Visible = False
Button1.Visible = True
tentatives = 0
nbpassage = 0
Return 1
End Function
Private Sub Button2_Click_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
trd.Abort()
serveur1.Show()
' efface_bouton()
' Dim combi As String
' Dim Message As [Byte]()
' Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)
' Message = udpClient.Receive(RemoteIpEndPoint)
' combi = Encoding.ASCII.GetString(Message)
' saisir_jeu(combi)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim udpClient As New UdpClient(2251)
Dim combi As String
Dim Message As [Byte]()
Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)
Message = udpClient.Receive(RemoteIpEndPoint)
combi = Encoding.ASCII.GetString(Message)
saisir_jeu(combi)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim hostNameOrAddress As String
Dim ip As IPAddress()
hostNameOrAddress = Dns.GetHostName
ip = Dns.GetHostAddresses(hostNameOrAddress)
MsgBox(ip)
End Sub
Private Sub t1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles t1.Click
End Sub
End Class |
Partager