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
| from tkinter import*
from random import*
from time import*
from pygame.locals import *
from sys import*
import pygame
win=Tk()
win.title("Simon's")
win.geometry("800x400")
canv=Canvas(win,bg="black",height=400,width=800)
canv.place(y=0,x=0)
i=1
a=0
rr=0
#fonction qui initialise un tableau
def intab(tab,n):
for j in range(n):
tab[j]=randint(1,4)
#print("t2[j]=",tab[j])
def test(i):
print("i=",i)
if t2[i]==1:
pygame.time.wait(1000)
vertfluo()
elif t2[i]==2:
pygame.time.wait(1000)
jaunefluo()
elif t2[i]==3:
pygame.time.wait(1000)
rougefluo()
else:
pygame.time.wait(1000)
bleufluo()
def bleufluo():
print
for b in range (80):
canv.create_line(400,320+b,800,320+b,width=1,fill=bleu_fluo)
for b1 in range (200):
canv.create_line(640,200+b1,800,200+b1,width=1,fill=bleu_fluo)
for b2 in range (120):
canv.create_line(400,320,640,200+b2,width=1,fill=bleu_fluo)
#canv.after(500,bleuclair)
pygame.time.wait(1000)
bleuclair()
def bleuclair():
for b in range (80):
canv.create_line(400,320+b,800,320+b,width=1,fill=bleu_clair)
for b1 in range (200):
canv.create_line(640,200+b1,800,200+b1,width=1,fill=bleu_clair)
for b2 in range (120):
canv.create_line(400,320,640,200+b2,width=1,fill=bleu_clair)
def bleufluo1():
bleufluo()
global z
z=4
if t2[i]==z:
L=Label(win,text="Bien")
L.place(x=400,y=100)
else:
L=Label(win,text="raté")
L.place(x=400,y=100)
def vertfluo():
for v in range(200):
canv.create_line(0,v,160,v,width=1,fill=vert_fluo)
for v1 in range(80):
canv.create_line(0,v1,400,v1,width=1,fill=vert_fluo)
for v2 in range(200):
canv.create_line(160,v2,400,80,width=1,fill=vert_fluo)
#canv.after(500,vertclair)
pygame.time.wait(1000)
vertclair()
def vertclair():
for v in range(200):
canv.create_line(0,v,160,v,width=1,fill=vert_clair)
for v1 in range(80):
canv.create_line(0,v1,400,v1,width=1,fill=vert_clair)
for v2 in range(200):
canv.create_line(160,v2,400,80,width=1,fill=vert_clair)
def vertfluo1():
vertfluo()
global z
z=1
if t2[i]==z:
L=Label(win,text="Bien")
L.place(x=400,y=100)
else:
L=Label(win,text="raté")
L.place(x=400,y=100)
def jaunefluo():
for j in range (200):
canv.create_line(0,320+j,400,320+j,width=1,fill=jaune_fluo)
for j1 in range (200):
canv.create_line(0,200+j1,160,200+j1,width=1,fill=jaune_fluo)
for j2 in range (200):
canv.create_line(160,200+j2,400,320,width=1,fill=jaune_fluo)
#canv.after(500,jauneclair)
pygame.time.wait(1000)
jauneclair()
def jauneclair():
for j in range (200):
canv.create_line(0,320+j,400,320+j,width=1,fill=jaune_clair)
for j1 in range (200):
canv.create_line(0,200+j1,160,200+j1,width=1,fill=jaune_clair)
for j2 in range (200):
canv.create_line(160,200+j2,400,320,width=1,fill=jaune_clair)
def jaunefluo1():
jaunefluo()
global z
z=2
if t2[i]==z:
L=Label(win,text="Bien")
L.place(x=400,y=100)
else:
L=Label(win,text="raté")
L.place(x=400,y=100)
def rougefluo():
for r in range(80):
canv.create_line(400,r,800,r,width=1,fill=rouge_fluo)
for r1 in range(200):
canv.create_line(640,r1,800,r1,width=1,fill=rouge_fluo)
for r2 in range(200):
canv.create_line(400,80,640,r2,width=1,fill=rouge_fluo)
#canv.after(500,rougeclair)
pygame.time.wait(1000)
rougeclair()
def rougeclair():
for r in range(80):
canv.create_line(400,r,800,r,width=1,fill=rouge_clair)
for r1 in range(200):
canv.create_line(640,r1,800,r1,width=1,fill=rouge_clair)
for r2 in range(200):
canv.create_line(400,80,640,r2,width=1,fill=rouge_clair)
def rougefluo1():
rougefluo()
global z
z=3
if t2[i]==z:
L=Label(win,text="Bien")
L.place(x=400,y=100)
else:
L=Label(win,text="raté")
L.place(x=400,y=100)
#liste de toute les couleurs
vert_clair="pale green"
rouge_clair="pale violet red"
bleu_clair="SteelBlue1"
jaune_clair="goldenrod1"
vert_fluo="green"
rouge_fluo="red"
bleu_fluo="blue"
jaune_fluo="yellow"
#La coloration du canvas lorsque le jeu n'est pas commencé
for v in range(200):
canv.create_line(0,v,160,v,width=1,fill=vert_clair)
for v1 in range(80):
canv.create_line(0,v1,400,v1,width=1,fill=vert_clair)
for v2 in range(200):
canv.create_line(160,v2,400,80,width=1,fill=vert_clair)
for b in range (80):
canv.create_line(400,320+b,800,320+b,width=1,fill=bleu_clair)
for b1 in range (200):
canv.create_line(640,200+b1,800,200+b1,width=1,fill=bleu_clair)
for b2 in range (120):
canv.create_line(400,320,640,200+b2,width=1,fill=bleu_clair)
for r in range(80):
canv.create_line(400,r,800,r,width=1,fill=rouge_clair)
for r1 in range(200):
canv.create_line(640,r1,800,r1,width=1,fill=rouge_clair)
for r2 in range(200):
canv.create_line(400,80,640,r2,width=1,fill=rouge_clair)
for j in range (200):
canv.create_line(0,320+j,400,320+j,width=1,fill=jaune_clair)
for j1 in range (200):
canv.create_line(0,200+j1,160,200+j1,width=1,fill=jaune_clair)
for j2 in range (200):
canv.create_line(160,200+j2,400,320,width=1,fill=jaune_clair)
txt=canv.create_text(400,200,text="SIMON",\
fill="yellow",font=("Arial",20))
# fonction qui créer un tableau, où se trouve la séquence à jouer, de taille i
def mon_tableau(i):
t2=list(range(i))
return t2
# fonction jouer qui est appelée quand on clique sur jouer
def jouer():
for i in range(10):
print("t2[i]=",t2[i])
#canv.after(1000,test(i))
#pygame.time.wait(500)
test(i)
# Variables globales
global t2
t2=mon_tableau(10)
intab(t2,10)
print(t2)
P=Button(win,bg=vert_fluo,width=10,height=5,command=vertfluo1)
P.place(x=150,y=50)
F=Button(win,bg=jaune_fluo,width=10,height=5,command=jaunefluo1)
F.place(x=150,y=280)
C=Button(win,bg=rouge_fluo,width=10,height=5,command=rougefluo1)
C.place(x=600,y=50)
O=Button(win,bg=bleu_fluo,width=10,height=5,command=bleufluo1)
O.place(x=600,y=280)
S=Button(win,bg="black",fg="green",width=7,height=3,text="JOUER",command=jouer)
S.place(x=375,y=240)
win.mainloop() |
Partager