Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPublic Class Fenetre Public couleur As Color Public Rand As System.Random = New System.Random Public c1 As Color Public Resultat As String Public BtnOrdonnée = 80 Public NbreEssai, j, NbreCouleur As Integer Public txtAbcisse = 318 Public txtOrdonnee = 80 Dim i As Integer Public TableauProposition(3) As Color Public TableauDeSolution(3) As Color Public TableauJuste(3) As Integer Public TableauMauvais(3) As Integer Dim y As Integer Private Sub NouvellePartieToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NouvellePartieToolStripMenuItem.Click If btnEssai.Tag = 0 Then 'NbreEssai = InputBox("Quelle est votre nombre d'essai") 'NbreEssai = 5 'BtnSolutiona.Hide() 'BtnSolutionb.Hide() 'BtnSolutionc.Hide() 'BtnSolutiond.Hide() BtnSolutiona.BackColor = Couleuraléatoire() BtnSolutionb.BackColor = Couleuraléatoire() BtnSolutionc.BackColor = Couleuraléatoire() BtnSolutiond.BackColor = Couleuraléatoire() End If If NbreCouleur = 4 Then BtnJaune.Visible = False BtnVert.Visible = False BtnNoir.Visible = False BtnViolet.Visible = False End If If NbreCouleur = 5 Then BtnVert.Visible = False BtnNoir.Visible = False BtnViolet.Visible = False End If If NbreCouleur = 6 Then BtnNoir.Visible = False BtnViolet.Visible = False End If If NbreCouleur = 7 Then BtnViolet.Visible = False End If btnEssai.Visible = True btnAgain.Visible = True GenererDesBoutons() BtnOrdonnée = BtnOrdonnée + 40 btnEssai.Tag = btnEssai.Tag + 1 btnEssai.Text = "Essai " + Str(btnEssai.Tag) End Sub Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEssai.Click TableauDeSolution(0) = BtnSolutiona.BackColor TableauDeSolution(1) = BtnSolutionb.BackColor TableauDeSolution(2) = BtnSolutionc.BackColor TableauDeSolution(3) = BtnSolutiond.BackColor Dim x As Integer For x = 0 To 3 For Each ctrl As Control In Me.Controls If ctrl.Name = "btn" + Trim(Str(x)) + Str(((NbreEssai - 1) * 4)) Then TableauProposition(x) = ctrl.BackColor End If Next Next If btnEssai.Tag <= NbreEssai Then GenereTextBox(VerificationCouleur()) End If If btnEssai.Tag < NbreEssai Then GenererDesBoutons() BtnOrdonnée = BtnOrdonnée + 40 btnEssai.Tag = btnEssai.Tag + 1 btnEssai.Text = "Essai " + Str(btnEssai.Tag) End If End Sub Private Sub GenererDesBoutons() Dim BtnAbcisse = 26 Dim i As Integer For i = 0 To 3 Dim btn As New Button btn.Location = New Drawing.Point(BtnAbcisse, BtnOrdonnée) btn.Size = New Size(47, 37) btn.Name = "btn" + Trim(Str(i)) + Str(((NbreEssai - 1) * 4)) Me.Controls.Add(btn) AddHandler btn.Click, AddressOf CouleurClick TableauProposition(i) = couleur BtnAbcisse = BtnAbcisse + 68 Next End Sub Public Sub GenereTextBox(ByVal rep As String) Dim txt As New TextBox Dim fnt As Font fnt = Me.Font txt.Location = New Drawing.Point(txtAbcisse, txtOrdonnee) txt.Font = New Font(fnt.Name, 40, FontStyle.Regular) txt.Size = New Size(130, 37) txt.Multiline = True txt.Name = "textb" + Str((NbreEssai - 1) * 4) Me.Controls.Add(txt) txt.Text = rep txtOrdonnee = txtOrdonnee + 40 End Sub Public Function Couleuraléatoire() As System.Drawing.Color Dim Alea As Integer Alea = Rand.Next(1, NbreCouleur) If Alea 1 Then Couleuraléatoire Color.Red If Alea 2 Then Couleuraléatoire Color.White If Alea 3 Then Couleuraléatoire Color.FromArgb(0, 0, 192) If Alea 4 Then Couleuraléatoire Color.FromArgb(255, 128, 0) If Alea 5 Then Couleuraléatoire Color.Yellow If Alea 6 Then Couleuraléatoire Color.Lime If Alea 7 Then Couleuraléatoire Color.Black If Alea 8 Then Couleuraléatoire Color.FromArgb(192, 0, 192) End Function Private Sub Btna_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnRouge.Click, BtnBlanc.Click, BtnBleu.Click, BtnOrange.Click, BtnJaune.Click, BtnVert.Click, BtnNoir.Click, BtnViolet.Click couleur = sender.backcolor End Sub Private Sub CouleurClick(ByVal sender As System.Object, ByVal e As System.EventArgs) sender.backcolor = couleur End Sub Private Sub ChoixDeLaDifficultéToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChoixDeLaDifficultéToolStripMenuItem.Click Difficulté.Show() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Close() End Sub Private Sub btnAgain_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAgain.Click BtnSolutiona.BackColor = Couleuraléatoire() BtnSolutionb.BackColor = Couleuraléatoire() BtnSolutionc.BackColor = Couleuraléatoire() BtnSolutiond.BackColor = Couleuraléatoire() End Sub Private Function VerificationCouleur() Dim i As Integer 'Initialisation des tableaux For t = 0 To 3 TableauJuste(t) = 0 Next For t = 0 To 3 TableauMauvais(t) = 0 Next 'verification couleur For i = 0 To 3 If TableauProposition(i) TableauDeSolution(i) Then TableauJuste(i) 1 Next For o As Integer = 0 To 3 If TableauJuste(o) = 0 Then For j As Integer = 0 To 3 If TableauJuste(j) 0 And TableauProposition(o) TableauDeSolution(j) Then TableauMauvais(j) = 2 Exit For End If Next End If Next Dim resultat As String For t = 0 To 3 If TableauJuste(t) 1 Then resultat resultat + "*" Next For t = 0 To 3 If TableauMauvais(t) 2 Then resultat resultat + "°" Next Return resultat End Function End Class
For x = 0 To 3 For Each ctrl As Control In Me.Controls If ctrl.Name = "btn" + Trim(Str(x)) + Str(((NbreEssai - 1) * 4)) Then TableauProposition(x) = ctrl.BackColor End If Next Next
If NbreCouleur = 4 Then