Bonjour, je suis en terminal S spécialité ISN, et j'ai un problème avec mon mastermind je n'arrive pas à crée les couleur dans la grille de vérification et à changer de ligne une fois la première rempli voici mon programme
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
#~#######################################IMPORTATION##################################
 
from tkinter import *
import random
from random import *
 
########################################DEFINITION####################################
 
def caseClicG( event ):
 
    global ligne_coul
 
    # mettre les coordonnées du clic dans x et y
    x, y = event.x, event.y
 
    # calculer la ligne et la colonne correspondant au clic
    colonne = int((x-x0)/c)
    ligne_coul = int((y-y0)/c)
    print (ligne_coul, colonne)
    texte1 = Label(fenetre, text='Cliquer sur une couleur')
    texte1.pack()
 
    #si 0 <= colonne < nb et que 0 <= ligne < nb, on peut traiter le clic
    if (x > 350 and x < 420) and ( y > 100 and y < 450) :
        placement_pion ()
 
    else :
        texte1.delete("0.0",END)
        texte1 = Label(fenetre, text='Cliquer sur une couleur')
 
 
 
def placement_pion ():
    global ligne_coul,case,comb
 
    case = case+1
 
    if case == 4 :
        case = 0
        comb = comb+1
 
 
    if ligne_coul == 0 :
        print(ligne_coul)
        tableau[comb][case]=1 #modifie la valeur de la case dans le tableau
        print (tableau)
        can1.create_rectangle(30+(40*case),460-(40*comb),(40*case)+70,460-(40*comb)+40,fill='blue')
 
    if ligne_coul == 1 :
        print(ligne_coul)
        tableau[comb][case]=2 #modifie la valeur de la case dans le tableau
        print (tableau)
        can1.create_rectangle(30+(40*case),460-(40*comb),(40*case)+70,460-(40*comb)+40,fill='yellow')    
 
    if ligne_coul == 2 :
        print(ligne_coul)
        tableau[comb][case]=3 #modifie la valeur de la case dans le tableau
        print (tableau)
        can1.create_rectangle(30+(40*case),460-(40*comb),(40*case)+70,460-(40*comb)+40,fill='green')
 
    if ligne_coul == 3 :
        print (ligne_coul)
        tableau[comb][case]=4 #modifie la valeur de la case dans le tableau
        print (tableau)
        can1.create_rectangle(30+(40*case),460-(40*comb),(40*case)+70,460-(40*comb)+40,fill='red')
 
    if ligne_coul == 4 :
        print (ligne_coul)
        tableau[comb][case]=5 #modifie la valeur de la case dans le tableau
        print (tableau)
        can1.create_rectangle(30+(40*case),460-(40*comb),(40*case)+70,460-(40*comb)+40,fill='black')
    if comb == 3 :
        colonne-1
 
#####################################VARIABLE######################################
 
case = -1
comb = 0
 
# crée un tableau de nb lignes contenant nb 0
tableau = [[0,0,0,0],
           [0,0,0,0],
           [0,0,0,0],
           [0,0,0,0],
           [0,0,0,0],
           [0,0,0,0],
           [0,0,0,0],
           [0,0,0,0],
           [0,0,0,0],
           [0,0,0,0]]
 
print(tableau)
 
####################################CANVAS####################################
 
fenetre = Tk()
 
can1 = Canvas( fenetre, height = 600, width = 600, bg = "light blue" )
can1.pack( side = LEFT )
 
 
#grille solution :
nbLignes = 1	  # nb de lignes
nbColonnes = 4	  # nb de colonnes
c = 40		  # taille d'une case
x0, y0 = 30, 40   # coordonnées du point en haut à gauche de la grille
 
#solution aléatoire 
 
listcoul = ["blue","yellow","green","red","black"]
shuffle(listcoul)
del listcoul[4]
print(listcoul)
 
for i in range( nbColonnes+1 ):
    can1.create_line( x0+c*i, y0, x0+c*i, y0 + nbLignes*c )
for i in range( nbLignes+1 ):
    can1.create_line( x0, y0+c*i, x0+nbColonnes*c , y0+c*i )
for i in range( nbColonnes+1 ):
    can1.create_line( x0+c*i, y0, x0+c*i, y0 + nbLignes*c )
for i in range( nbLignes+1) :
    can1.create_line( x0, y0+c*i, x0+nbColonnes*c, y0+c*i )
 
tableau = [[0, 0, 0, 0]]
print (tableau)
 
 
#grille joueur :
# variables 
nbLignes = 10	  # nb de lignes
nbColonnes = 4	  # nb de colonnes
c = 40		  # taille d'une case
x0, y0 = 30, 100   # coordonnées du point en haut à gauche de la grille
 
for i in range( nbColonnes+1 ):
    can1.create_line( x0+c*i, y0, x0+c*i, y0 + nbLignes*c )
for i in range( nbLignes+1 ):
    can1.create_line( x0, y0+c*i, x0+nbColonnes*c , y0+c*i )
for i in range( nbColonnes+1 ):
    can1.create_line( x0+c*i, y0, x0+c*i, y0 + nbLignes*c )
for i in range( nbLignes+1) :
    can1.create_line( x0, y0+c*i, x0+nbColonnes*c, y0+c*i )
 
 
#grille de vérification:
nbLignes = 1	  # nb de lignes
nbColonnes = 4	  # nb de colonnes
c = 20		  # taille d'une case
 
x0, y0 = 200, 100 # coordonnées du point en haut à gauche de la grille
for i in range( nbColonnes+1 ):
    can1.create_line( x0+c*i, y0, x0+c*i, y0 + nbLignes*c )
for i in range( nbLignes+1 ):
    can1.create_line( x0, y0+c*i, x0+nbColonnes*c, y0+c*i )
 
x0, y0 = 200, 140# coordonnées du point en haut à gauche de la grille
for i in range( nbColonnes+1 ):
    can1.create_line( x0+c*i, y0, x0+c*i, y0 + nbLignes*c )
for i in range( nbLignes+1 ):
    can1.create_line( x0, y0+c*i, x0+nbColonnes*c, y0+c*i )
 
x0, y0 = 200, 180# coordonnées du point en haut à gauche de la grille
for i in range( nbColonnes+1 ):
    can1.create_line( x0+c*i, y0, x0+c*i, y0 + nbLignes*c )
for i in range( nbLignes+1 ):
    can1.create_line( x0, y0+c*i, x0+nbColonnes*c, y0+c*i )
 
x0, y0 = 200, 220# coordonnées du point en haut à gauche de la grille
for i in range( nbColonnes+1 ):
    can1.create_line( x0+c*i, y0, x0+c*i, y0 + nbLignes*c )
for i in range( nbLignes+1 ):
    can1.create_line( x0, y0+c*i, x0+nbColonnes*c, y0+c*i )
 
x0, y0 = 200, 260# coordonnées du point en haut à gauche de la grille
for i in range( nbColonnes+1 ):
    can1.create_line( x0+c*i, y0, x0+c*i, y0 + nbLignes*c )
for i in range( nbLignes+1 ):
    can1.create_line( x0, y0+c*i, x0+nbColonnes*c, y0+c*i )
 
x0, y0 = 200, 300# coordonnées du point en haut à gauche de la grille
for i in range( nbColonnes+1 ):
    can1.create_line( x0+c*i, y0, x0+c*i, y0 + nbLignes*c )
for i in range( nbLignes+1 ):
    can1.create_line( x0, y0+c*i, x0+nbColonnes*c, y0+c*i )
 
x0, y0 = 200, 340# coordonnées du point en haut à gauche de la grille
for i in range( nbColonnes+1 ):
    can1.create_line( x0+c*i, y0, x0+c*i, y0 + nbLignes*c )
for i in range( nbLignes+1 ):
    can1.create_line( x0, y0+c*i, x0+nbColonnes*c, y0+c*i )
 
x0, y0 = 200, 380# coordonnées du point en haut à gauche de la grille
for i in range( nbColonnes+1 ):
    can1.create_line( x0+c*i, y0, x0+c*i, y0 + nbLignes*c )
for i in range( nbLignes+1 ):
    can1.create_line( x0, y0+c*i, x0+nbColonnes*c, y0+c*i )
 
x0, y0 = 200, 420# coordonnées du point en haut à gauche de la grille
for i in range( nbColonnes+1 ):
    can1.create_line( x0+c*i, y0, x0+c*i, y0 + nbLignes*c )
for i in range( nbLignes+1 ):
    can1.create_line( x0, y0+c*i, x0+nbColonnes*c, y0+c*i )
 
x0, y0 = 200, 460# coordonnées du point en haut à gauche de la grille
for i in range( nbColonnes+1 ):
    can1.create_line( x0+c*i, y0, x0+c*i, y0 + nbLignes*c )
for i in range( nbLignes+1 ):
    can1.create_line( x0, y0+c*i, x0+nbColonnes*c, y0+c*i )
 
 
#grille de couleur
nbLignes = 5	  # nb de lignes
nbColonnes = 1	  # nb de colonnes
c = 70		  # taille d'une case
x0, y0 = 350, 100 # coordonnées du point en haut à gauche de la grille
 
x1 = can1.create_rectangle(350,100,420,170,fill='blue')
x2 = can1.create_rectangle(350,170,420,240,fill='yellow')
x3 = can1.create_rectangle(350,240,420,310,fill='green')
x4 = can1.create_rectangle(350,310,420,380,fill='red')  
x5 = can1.create_rectangle(350,380,420,450,fill='black')
 
for i in range( nbColonnes+1 ):
    can1.create_rectangle( x0+c*i, y0, x0+c*i, y0 + nbLignes*c,fill='blue' )
for i in range( nbLignes+1 ):
    can1.create_rectangle( x0, y0+c*i, x0+nbColonnes*c, y0+c*i,fill='blue' )
 
 
#choisir la solution
 
 
can1.pack( side = LEFT )    
can1.bind( "<Button-1>", caseClicG )
for i in range( nbColonnes+1 ):
    can1.create_line( x0+c*i, y0, x0+c*i, y0 + nbLignes*c,  )
for i in range( nbLignes+1 ):
    can1.create_line( x0, y0+c*i, x0+nbColonnes*c , y0+c*i )
 
 
#bouton quitter
quitter = Button( fenetre, text = "Quitter", command = fenetre.destroy )
quitter.pack( side = BOTTOM )
 
fenetre.mainloop()