j3lllo
Messages postés3Date d'inscriptionlundi 12 août 2013StatutMembreDernière intervention13 août 2013
-
12 août 2013 à 23:46
cs_ShayW
Messages postés3253Date d'inscriptionjeudi 26 novembre 2009StatutMembreDernière intervention 3 décembre 2019
-
13 août 2013 à 08:09
Bonjour, je dois avoir terminé un jeu MasterMind pour mercredi soir et j'ai un peu de difficulté avec différentes choses... Je n'ai jamais vraiment programmé en VB donc j'éprouve un peu de difficulté. En faite, je veux qu'après 4 cases, je ne puisse plus ajouter de couleur aux picturebox jusqu'à ce que j'aie valider avec le bouton «Valider»... C'est d'ailleurs pour cela que j'ai fait un compteur, mais je ne sais pas trop comment m'y prendre pour le reste. J'imagine que ça doit être avec une valeur booléenne?
Merci de votre aide.
Public Class Form1
Dim boardWidth As Integer = 4
Dim boardHeight As Integer = 2
Dim template(boardWidth, boardHeight) As Integer
Dim jeu(boardWidth, boardHeight) As Integer
Dim validatingRow As Integer = 0
Dim compteurPb As Integer = 0
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim rnd As Random
For j As Integer = 0 To boardHeight - 1
For i As Integer = 0 To boardWidth - 1
template(i, j) = rnd.Next(1, 7)
Next
Next
For j As Integer = 0 To boardHeight - 1
For i As Integer = 0 To boardWidth - 1
jeu(i, j) = 0
Next
Next
End Sub
Private Sub pb1_DoubleClick(sender As System.Object, e As System.EventArgs) Handles pb1.DoubleClick
jeu(0, 0) = 0
pb1.BackColor = Color.White
compteurPb = compteurPb - 1
End Sub
Private Sub pbBlack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pbBlack.Click
For j As Integer = 0 To boardHeight - 1
For i As Integer = 0 To boardWidth - 1
If jeu(i, j) = 0 Then
jeu(i, j) = 3
ElseIf i = 0 And j = 0 Then
pb1.BackColor = Color.Black
ElseIf i = 1 And j = 0 Then
pb2.BackColor = Color.Black
ElseIf i = 2 And j = 0 Then
pb3.BackColor = Color.Black
ElseIf i = 3 And j = 0 Then
pb4.BackColor = Color.Black
ElseIf i = 0 And j = 1 Then
pb5.BackColor = Color.Black
ElseIf i = 1 And j = 1 Then
pb6.BackColor = Color.Black
ElseIf i = 2 And j = 1 Then
pb7.BackColor = Color.Black
Else : i = 3 And j = 1
pb8.BackColor = Color.Black
End If
compteurPb = compteurPb + 1
Exit Sub
Next
Next
End Sub
Private Sub pb2_Click(sender As System.Object, e As System.EventArgs) Handles pb2.Click
If validatingRow = 0 Then
jeu(1, 0) = 0
pb2.BackColor = Color.White
compteurPb = compteurPb - 1
End If
End Sub
Private Sub pb3_Click(sender As System.Object, e As System.EventArgs) Handles pb3.Click
If validatingRow = 0 Then
jeu(2, 0) = 0
pb3.BackColor = Color.White
compteurPb = compteurPb - 1
End If
End Sub
Private Sub pbGreen_Click(sender As System.Object, e As System.EventArgs) Handles pbGreen.Click
For j As Integer = 0 To boardHeight - 1
For i As Integer = 0 To boardWidth - 1
If jeu(i, j) = 0 Then
jeu(i, j) = 2
If i = 0 And j = 0 Then
pb1.BackColor = Color.Green
ElseIf i = 1 And j = 0 Then
pb2.BackColor = Color.Green
ElseIf i = 2 And j = 0 Then
pb3.BackColor = Color.Green
ElseIf i = 3 And j = 0 Then
pb4.BackColor = Color.Green
ElseIf i = 0 And j = 1 Then
pb5.BackColor = Color.Green
ElseIf i = 1 And j = 1 Then
pb6.BackColor = Color.Green
ElseIf i = 2 And j = 1 Then
pb7.BackColor = Color.Green
Else : i = 3 And j = 1
pb8.BackColor = Color.Green
End If
compteurPb = compteurPb + 1
Exit Sub
End If
Next
Next
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
For i As Integer = 0 To boardWidth - 1
If jeu(0, 0) = jeu(1, 0) Or jeu(0, 0) = jeu(2, 0) Or jeu(0, 0) = jeu(3, 0) Then
MsgBox("Il ne peut y avoir deux couleurs identiques ou plus dans votre solution")
Exit Sub
End If
If jeu(1, 0) = jeu(2, 0) Or jeu(1, 0) = jeu(3, 0) Then
MsgBox("Il ne peut y avoir deux couleurs identiques ou plus dans votre solution")
Exit Sub
End If
If jeu(2, 0) = jeu(3, 0) Then
MsgBox("Il ne peut y avoir deux couleurs identiques ou plus dans votre solution")
Exit Sub
End If
If template(i, validatingRow) <> jeu(i, validatingRow) Then
MessageBox.Show("Pas bon à (" & i & ", " & validatingRow & ")")
End If
Next
validatingRow += 1
End Sub
Private Sub pbBlue_Click(sender As System.Object, e As System.EventArgs) Handles pbBlue.Click
For j As Integer = 0 To boardHeight - 1
For i As Integer = 0 To boardWidth - 1
If jeu(i, j) = 0 Then
jeu(i, j) = 1
If i = 0 And j = 0 Then
pb1.BackColor = Color.Blue
ElseIf i = 1 And j = 0 Then
pb2.BackColor = Color.Blue
ElseIf i = 2 And j = 0 Then
pb3.BackColor = Color.Blue
ElseIf i = 3 And j = 0 Then
pb4.BackColor = Color.Blue
ElseIf i = 0 And j = 1 Then
pb5.BackColor = Color.Blue
ElseIf i = 1 And j = 1 Then
pb6.BackColor = Color.Blue
ElseIf i = 2 And j = 1 Then
pb7.BackColor = Color.Blue
Else : i = 3 And j = 1
pb8.BackColor = Color.Blue
End If
compteurPb = compteurPb + 1
Exit Sub
End If
Next
Next
End Sub
Private Sub pbYellow_Click(sender As System.Object, e As System.EventArgs) Handles pbYellow.Click
For j As Integer = 0 To boardHeight - 1
For i As Integer = 0 To boardWidth - 1
If jeu(i, j) = 0 Then
jeu(i, j) = 4
If i = 0 And j = 0 Then
pb1.BackColor = Color.Yellow
ElseIf i = 1 And j = 0 Then
pb2.BackColor = Color.Yellow
ElseIf i = 2 And j = 0 Then
pb3.BackColor = Color.Yellow
ElseIf i = 3 And j = 0 Then
pb4.BackColor = Color.Yellow
ElseIf i = 0 And j = 1 Then
pb5.BackColor = Color.Yellow
ElseIf i = 1 And j = 1 Then
pb6.BackColor = Color.Yellow
ElseIf i = 2 And j = 1 Then
pb7.BackColor = Color.Yellow
Else : i = 3 And j = 1
pb8.BackColor = Color.Yellow
End If
compteurPb = compteurPb + 1
Exit Sub
End If
Next
Next
End Sub
Private Sub pbPurple_Click(sender As System.Object, e As System.EventArgs) Handles pbPurple.Click
For j As Integer = 0 To boardHeight - 1
For i As Integer = 0 To boardWidth - 1
If jeu(i, j) = 0 Then
jeu(i, j) = 5
If i = 0 And j = 0 Then
pb1.BackColor = Color.Purple
ElseIf i = 1 And j = 0 Then
pb2.BackColor = Color.Purple
ElseIf i = 2 And j = 0 Then
pb3.BackColor = Color.Purple
ElseIf i = 3 And j = 0 Then
pb4.BackColor = Color.Purple
ElseIf i = 0 And j = 1 Then
pb5.BackColor = Color.Purple
ElseIf i = 1 And j = 1 Then
pb6.BackColor = Color.Purple
ElseIf i = 2 And j = 1 Then
pb7.BackColor = Color.Purple
Else : i = 3 And j = 1
pb8.BackColor = Color.Purple
End If
compteurPb = compteurPb + 1
Exit Sub
End If
Next
Next
End Sub
Private Sub pbRed_Click(sender As System.Object, e As System.EventArgs) Handles pbRed.Click
For j As Integer = 0 To boardHeight - 1
For i As Integer = 0 To boardWidth - 1
If jeu(i, j) = 0 Then
jeu(i, j) = 6
If i = 0 And j = 0 Then
pb1.BackColor = Color.Red
ElseIf i = 1 And j = 0 Then
pb2.BackColor = Color.Red
ElseIf i = 2 And j = 0 Then
pb3.BackColor = Color.Red
ElseIf i = 3 And j = 0 Then
pb4.BackColor = Color.Red
ElseIf i = 0 And j = 1 Then
pb5.BackColor = Color.Red
ElseIf i = 1 And j = 1 Then
pb6.BackColor = Color.Red
ElseIf i = 2 And j = 1 Then
pb7.BackColor = Color.Red
Else : i = 3 And j = 1
pb8.BackColor = Color.Red
End If
compteurPb = compteurPb + 1
Exit Sub
End If
Next
Next
End Sub
Private Sub pb4_Click(sender As System.Object, e As System.EventArgs) Handles pb4.Click
If validatingRow = 0 Then
jeu(3, 0) = 0
pb4.BackColor = Color.White
compteurPb = compteurPb - 1
End If
End Sub
Private Sub pb5_Click(sender As System.Object, e As System.EventArgs) Handles pb5.Click
If validatingRow = 0 Then
jeu(0, 1) = 0
pb5.BackColor = Color.White
compteurPb = compteurPb - 1
End If
End Sub
Private Sub pb6_Click(sender As System.Object, e As System.EventArgs) Handles pb6.Click
If validatingRow = 0 Then
jeu(1, 1) = 0
pb6.BackColor = Color.White
compteurPb = compteurPb - 1
End If
End Sub
Private Sub pb7_Click(sender As System.Object, e As System.EventArgs) Handles pb7.Click
If validatingRow = 0 Then
jeu(2, 1) = 0
pb7.BackColor = Color.White
compteurPb = compteurPb - 1
End If
End Sub
Private Sub pb8_Click(sender As System.Object, e As System.EventArgs) Handles pb8.Click
If validatingRow = 0 Then
jeu(3, 1) = 0
pb8.BackColor = Color.White
compteurPb = compteurPb - 1
End If
End Sub
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
jordane45
Messages postés38145Date d'inscriptionmercredi 22 octobre 2003StatutModérateurDernière intervention25 avril 2024344 12 août 2013 à 23:53
Bonjour.
Vu que tu n'as pas utilisé les balises de code je n'ai pas tout regardé.
Mais bon vu ta question, je dirais que :
- a chaque ajout de case tu testes si ton compteur est <= 4.
Si oui tu executes ton code. Sinon tu sors de ta fonction.
cs_ShayW
Messages postés3253Date d'inscriptionjeudi 26 novembre 2009StatutMembreDernière intervention 3 décembre 201957 13 août 2013 à 08:09
Salut
"Bonjour, je dois avoir terminé un jeu MasterMind pour mercredi soir"
bien sur que tu dois avoir déja terminé si tu dois le rendre mercredi
soir mais si on vient au dernier moment il faut subir les conséquences
si tu veux de l'aide au moins commente ton code et sers toi des balises de code et ce code n'a pas été écrit avec l'éditeur du vb
aucune indentation
En informatique : l'indentation consiste en l'ajout de tabulations ou d'espaces dans un fichier, pour une meilleure lecture et compréhension du code. ce n'est pas au membre du forum à décoder ton code
reviens après avoir fait un petit effort