Erreur de code sur mon tic-tac-toe

royalex101 Messages postés 1 Date d'inscription lundi 7 mai 2007 Statut Membre Dernière intervention 14 mai 2007 - 14 mai 2007 à 16:05
jmfmarques Messages postés 7666 Date d'inscription samedi 5 novembre 2005 Statut Membre Dernière intervention 22 août 2014 - 14 mai 2007 à 19:12
Bonjour, je suis étudiant en secondaire 5 et j'ai choisit comme projet 1 tic-tac-toe, rien de plus simple. Je le pencait mais j'ai maintenant un problême quand vient le temps de regarder si un tic-tac-toe a été crée Selon moi c'est la derniere partie qui ne marche pas (alignement). J'ai beau cliquer sur n'importe où, il me sort des ligne qui n'ont aucun rapport  Merci de m'aider!!. Voici mon code :

Dim aqui As Integer


Private Sub Form_Load()
aqui = 1
trait123.Visible = False
trait456.Visible = False
trait789.Visible = False
trait147.Visible = False
trait258.Visible = False
trait369.Visible = False
trait159.Visible = False
trait357.Visible = False
End Sub


Private Sub Lblaqui_Click()
If aqui = 1 Then
lblaqui = "1"
Else
lblaqui = "2"
aqui = "1"
End If
alignement
End Sub


Private Sub Lbl1_Click()
If aqui = 1 Then
Lbl1 = "X"
aqui = "2"
Else
Lbl1 = "O"
aqui = "1"
End If
alignement
End Sub


Private Sub Lbl2_Click()
If aqui = 1 Then
Lbl2 = "X"
aqui = "2"
Else
Lbl2 = "O"
aqui = "1"
End If
alignement
End Sub


Private Sub Lbl3_Click()
If aqui = 1 Then
Lbl3 = "X"
aqui = "2"
Else
Lbl3 = "O"
aqui = "1"
End If
alignement
End Sub


Private Sub Lbl4_Click()
If aqui = 1 Then
Lbl4 = "X"
aqui = "2"
Else
Lbl4 = "O"
aqui = "1"
End If
alignement
End Sub


Private Sub Lbl5_Click()
If aqui = 1 Then
Lbl5 = "X"
aqui = "2"
Else
Lbl5 = "O"
aqui = "1"
End If
alignement
End Sub


Private Sub Lbl6_Click()
If aqui = 1 Then
Lbl6 = "X"
aqui = "2"
Else
Lbl6 = "O"
aqui = "1"
End If
alignement
End Sub


Private Sub Lbl7_Click()
If aqui = 1 Then
Lbl7 = "X"
aqui = "2"
Else
Lbl7 = "O"
aqui = "1"
End If
alignement
End Sub


Private Sub Lbl8_Click()
If aqui = 1 Then
Lbl8 = "X"
aqui = "2"
Else
Lbl8 = "O"
aqui = "1"
End If
alignement
End Sub


Private Sub Lbl9_Click()
If aqui = 1 Then
Lbl9 = "X"
aqui = "2"
Else
Lbl9 = "O"
aqui = "1"
End If
alignement
End Sub


Private Sub alignement()If (Lbl1 x) And (Lbl2 x) And (Lbl3 = x) Then
trait123.Visible = True
trait456.Visible = False
trait789.Visible = False
trait147.Visible = False
trait258.Visible = False
trait369.Visible = False
trait159.Visible = False
trait357.Visible = False
End IfIf (Lbl1 O) And (Lbl2 O) And (Lbl3 = O) Then
trait123.Visible = True
trait456.Visible = False
trait789.Visible = False
trait147.Visible = False
trait258.Visible = False
trait369.Visible = False
trait159.Visible = False
trait357.Visible = False
End IfIf (Lbl1 x) And (Lbl5 x) And (Lbl9 = x) Then
trait123.Visible = False
trait456.Visible = False
trait789.Visible = False
trait147.Visible = False
trait258.Visible = False
trait369.Visible = False
trait159.Visible = True
trait357.Visible = False
End IfIf (Lbl1 O) And (Lbl5 O) And (Lbl9 = O) Then
trait123.Visible = True
trait456.Visible = False
trait789.Visible = False
trait147.Visible = False
trait258.Visible = False
trait369.Visible = False
trait159.Visible = True
trait357.Visible = False
End IfIf (Lbl1 x) And (Lbl4 x) And (Lbl7 = x) Then
trait123.Visible = False
trait456.Visible = False
trait789.Visible = False
trait147.Visible = True
trait258.Visible = False
trait369.Visible = False
trait159.Visible = False
trait357.Visible = False
End IfIf (Lbl1 O) And (Lbl4 O) And (Lbl7 = O) Then
trait123.Visible = False
trait456.Visible = False
trait789.Visible = False
trait147.Visible = True
trait258.Visible = False
trait369.Visible = False
trait159.Visible = False
trait357.Visible = False
End IfIf (Lbl2 x) And (Lbl5 x) And (Lbl8 = x) Then
trait123.Visible = False
trait456.Visible = False
trait789.Visible = False
trait147.Visible = False
trait258.Visible = True
trait369.Visible = False
trait159.Visible = False
trait357.Visible = False
End IfIf (Lbl2 O) And (Lbl5 O) And (Lbl8 = O) Then
trait123.Visible = False
trait456.Visible = False
trait789.Visible = False
trait147.Visible = False
trait258.Visible = True
trait369.Visible = False
trait159.Visible = False
trait357.Visible = False
End IfIf (Lbl3 x) And (Lbl6 x) And (Lbl9 = x) Then
trait123.Visible = False
trait456.Visible = False
trait789.Visible = False
trait147.Visible = False
trait258.Visible = False
trait369.Visible = True
trait159.Visible = False
trait357.Visible = False
End IfIf (Lbl3 O) And (Lbl6 O) And (Lbl9 = O) Then
trait123.Visible = False
trait456.Visible = False
trait789.Visible = False
trait147.Visible = False
trait258.Visible = False
trait369.Visible = True
trait159.Visible = False
trait357.Visible = False
End IfIf (Lbl3 x) And (Lbl5 x) And (Lbl7 = x) Then
trait123.Visible = False
trait456.Visible = False
trait789.Visible = False
trait147.Visible = False
trait258.Visible = False
trait369.Visible = False
trait159.Visible = False
trait357.Visible = True
End IfIf (Lbl3 O) And (Lbl5 O) And (Lbl7 = O) Then
trait123.Visible = False
trait456.Visible = False
trait789.Visible = False
trait147.Visible = False
trait258.Visible = False
trait369.Visible = False
trait159.Visible = False
trait357.Visible = True
End IfIf (Lbl4 x) And (Lbl5 x) And (Lbl6 = x) Then
trait123.Visible = False
trait456.Visible = True
trait789.Visible = False
trait147.Visible = False
trait258.Visible = False
trait369.Visible = False
trait159.Visible = False
trait357.Visible = False
End IfIf (Lbl4 O) And (Lbl5 O) And (Lbl6 = O) Then
trait123.Visible = False
trait456.Visible = True
trait789.Visible = False
trait147.Visible = False
trait258.Visible = False
trait369.Visible = False
trait159.Visible = False
trait357.Visible = False
End IfIf (Lbl7 x) And (Lbl8 x) And (Lbl9 = x) Then
trait123.Visible = False
trait456.Visible = False
trait789.Visible = True
trait147.Visible = False
trait258.Visible = False
trait369.Visible = False
trait159.Visible = False
trait357.Visible = False
End IfIf (Lbl7 O) And (Lbl8 O) And (Lbl9 = O) Then
trait123.Visible = False
trait456.Visible = False
trait789.Visible = True
trait147.Visible = False
trait258.Visible = False
trait369.Visible = False
trait159.Visible = False
trait357.Visible = False
End If
End Sub

5 réponses

jrivet Messages postés 7392 Date d'inscription mercredi 23 avril 2003 Statut Membre Dernière intervention 6 avril 2012 60
14 mai 2007 à 16:09
SAlut,
Pour une aide répode et précise il faut que tu nous dise de quel type sont les différents contrôle à utiliser.
Note je pense que tu devrais apprendre à te servir de groupe de contrôle.

@+: Ju£i?n
Pensez: Réponse acceptée
0
jmfmarques Messages postés 7666 Date d'inscription samedi 5 novembre 2005 Statut Membre Dernière intervention 22 août 2014 27
14 mai 2007 à 16:17
Ouais...

Et moi, je ne connais pas le "tic-tac-toe", mais, en lisant son code et toutes ces redondances, je ne peux m'empêcher de penser qu'il ferait mieux de tout reprendre à zéro ...


Déjà, de toutes façons : on voit bien qu'il définit toujoures les mêmes tr'aits sauf un seul comme invisibles ! Il y gagnerait déjà beaucoup à envoyer vers une sous-routine (toujours la même) avec comme seul argument le trait à rendre visible, tous les autres étant à passer en invisibles !...


Il reste tout - à - fait certain de ce qu'il aurait largement intérêt à se servir de groupes de contrôles.... pour sur ...
0
jrivet Messages postés 7392 Date d'inscription mercredi 23 avril 2003 Statut Membre Dernière intervention 6 avril 2012 60
14 mai 2007 à 16:22
re,
Autre chose est ce que O et x sont des constante de type string?

@+: Ju£i?n
Pensez: Réponse acceptée
0
Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
14 mai 2007 à 16:29
effectivement jrivet, vaudrait mieux ^^
If (Lbl7 O) And (Lbl8 O) And (Lbl9 = O) Then

ne voulais tu pas dire :
If (Lbl7 "O") And (Lbl8 "O") And (Lbl9 = "O") Then

??

Renfield
Admin CodeS-SourceS- MVP Visual Basic
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
jmfmarques Messages postés 7666 Date d'inscription samedi 5 novembre 2005 Statut Membre Dernière intervention 22 août 2014 27
14 mai 2007 à 19:12
Déjà, et sans même vouloir tenter :


1) ni d'utiliser des groupes de contrôles indexés (ce qui simplifierait beaucoup)
2) ni corriger les nombreuses incohérences que l'on peut déceler (contrôles sur lesquels on clique, dont on suppose donc qu'il contiennent un texte mais sans que l'on en précise la propriété utilisée et auquel on attribue une valeur ici mais une chaîne là !! !... des variables elles aussi traitée (aqui en est un bon exemple) ici en chaine et là en valeur numérique !!!...etc...etc...)

Bref en me contentant de reprendre (avec toutes ses fautes et incohérences) ce qui a été écrit, voilà donc ce que c'est, au bout du compte :

J'ai quand même mis en rouge tout ce qui est suspect ...

Dim aqui As Integer




Private Sub Form_Load()
  aqui = 1
  trait123.Visible = False
  trait456.Visible = False
  trait789.Visible = False
  trait147.Visible = False
  trait258.Visible = False
  trait369.Visible = False
  trait159.Visible = False
  trait357.Visible = False
End Sub


Private Sub Lblaqui_Click()
  If aqui = 1 Then
    lblaqui = "1"
  Else
    lblaqui = "2"
    aqui = "1"
  End If
  alignement
End Sub


Private Sub Lbl1_Click()
  decidons Me.ActiveControl
End Sub


Private Sub Lbl2_Click()
  decidons Me.ActiveControl
End Sub


Private Sub Lbl3_Click()
  decidons Me.ActiveControl
End Sub


Private Sub Lbl4_Click()
  decidons Me.ActiveControl
End Sub


Private Sub Lbl5_Click()
  decidons Me.ActiveControl
End Sub


Private Sub Lbl6_Click()
  decidons Me.ActiveControl
End Sub


Private Sub Lbl7_Click()
  decidons Me.ActiveControl
End Sub


Private Sub Lbl8_Click()
  decidons Me.ActiveControl
End Sub


Private Sub Lbl9_Click()
  decidons Me.activecontrole
End Sub
Private Sub decidons(ctrl As Control)
  If aqui = 1 Then
    ctrl = "X"  ' (ici j'ai bien été obligé de reprendre la faute puisque j'ignore le type de contrôle...)
    aqui = "2"
  Else
    ctrl = "O"' (ici j'ai bien été obligé de reprendre la faute puisque j'ignore le type de contrôle...)
    aqui = "1"
  End If
  alignement
End Sub


Private Sub alignement()  If (Lbl1 x) And (Lbl2 x) And (Lbl3 = x) Then alig trait123
' et de même pour tout ce qui suit (je ne vais pas passer mon temps à tout colorer  If (Lbl1 O) And (Lbl2 O) And (Lbl3 = O) Then alig trait123  If (Lbl1 x) And (Lbl5 x) And (Lbl9 = x) Then alig trait159  If (Lbl1 O) And (Lbl5 O) And (Lbl9 = O) Then alig trait159  If (Lbl1 x) And (Lbl4 x) And (Lbl7 = x) Then alig trait147  If (Lbl1 O) And (Lbl4 O) And (Lbl7 = O) Then alig trait147  If (Lbl2 x) And (Lbl5 x) And (Lbl8 = x) Then alig trait258  If (Lbl2 O) And (Lbl5 O) And (Lbl8 = O) Then alig trait258  If (Lbl3 x) And (Lbl6 x) And (Lbl9 = x) Then alig trait369  If (Lbl3 O) And (Lbl6 O) And (Lbl9 = O) Then alig trait369  If (Lbl3 x) And (Lbl5 x) And (Lbl7 = x) Then alig trait357  If (Lbl3 O) And (Lbl5 O) And (Lbl7 = O) Then alig trait357  If (Lbl4 x) And (Lbl5 x) And (Lbl6 = x) Then alig trait456  If (Lbl4 O) And (Lbl5 O) And (Lbl6 = O) Then alig trait456  If (Lbl7 x) And (Lbl8 x) And (Lbl9 = x) Then alig trait789  If (Lbl7 O) And (Lbl8 O) And (Lbl9 = O) Then alig trait789
End Sub


Sub alig(ctrl As Control)
  trait123.Visible = False
  trait456.Visible = False
  trait789.Visible = True
  trait147.Visible = False
  trait258.Visible = False
  trait369.Visible = False
  trait159.Visible = False
  trait357.Visible = False
  ctrl.Visible = True
End Sub

Bref ....
Celà irait encore mieux avec :
1) les corrections nécessaires (nombreuses)
2) des contrôles indexés.

Tout celà, par ailleurs, sans préjudice de la justesse de son raisonnement et de la conformité avec son jeu. Je me suis contenté là de réécrire (avec ses fautes) autrement ce qu'il a écrit !!!
0
Rejoignez-nous