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
|
from tkinter import *
import tkinter as tk
import time
import time as t
def cercle(x, y, r, coul ='coul'):
can.create_oval(x-r, y-r, x+r, y+r, fill=coul, outline=coul)
def remplir(y):
x=0
liste=[]
while x<400:
liste.append([x,y,x+40,y+40,0])
x=x+40
return liste
def fig_1():
global x,y,damier
x=0
y=0
can.delete(ALL)
damier=[]
while y<400:
damier.append(remplir(y))
y=y+40
a=0
while a<10:
al=damier[a]
b=0
while b<10:
al1=al[b]
can.create_rectangle(al1[0],al1[+1],al1[2],al1[3],fill='black')
b=b+2
a=a+2
a=1
while a<10:
al=damier[a]
b=1
while b<10:
al1=al[b]
can.create_rectangle(al1[0],al1[+1],al1[2],al1[3],fill='black')
b=b+2
a=a+2
print (damier)
def fig_2():
global haut,bas,x,y,r
def P_J1():
x=20
y=20
J1=[[1,0,0],[1,0,0],[1,0,0],[1,0,0],[1,0,0],[1,0,0],[1,0,0],[1,0,0],[1,0,0],[1,0,0]]
n=0
for i in range (2):
for k in range (5):
J1[n+k]=[1,x,y]
cercle(x,y,r,'red')
x=x+80
n=5
x=60
y=y+40
print (J1)
def P_J2():
x=20
y=340
J2=[[2,0,0],[2,0,0],[2,0,0],[2,0,0],[2,0,0],[2,0,0],[2,0,0],[2,0,0],[2,0,0],[2,0,0]]
n=0
for j in range (2):
for l in range (5):
J2[n+l]=[2,x,y]
cercle(x,y,r,'dimgrey')
x=x+80
n=5
x=60
y=y+40
print (J2)
P_J1()
P_J2()
def P_Gris(event):
global r
x=event.x%40
x=(event.x-x)+20
y=event.y%40
y=(event.y-y)+20
cercle(x,y,r,'dimgrey')
def P_Rouge(event):
global r
x=event.x%40
x=(event.x-x)+20
y=event.y%40
y=(event.y-y)+20
cercle(x,y,r,'red')
def mouvement (event):
global x,y,r
x=event.x
y=event.y
print (x,y)
def P_Corrige(event):
global r
x=event.x%40
x=(event.x-x)+20
y=event.y%40
y=(event.y-y)+20
cercle(x,y,r,'Black')
def P_Dame(event):
global r
x=event.x%40
x=(event.x-x)+20
y=event.y%40
y=(event.y-y)+20
cercle(x,y,r,'mediumvioletred')
def P_Corrige2(event):
global r
x=event.x%40
x=(event.x-x)+20
y=event.y%40
y=(event.y-y)+20
cercle(x,y,r,'white')
def start2():
global temps1, temps2, chron
temps1= t.time()
chrono()
def chrono():
global temps1, temps2, chron
temps2= t.time()
chron=15-temps2+temps1
lab.config(text=int(chron))
if (chron>=0):
fen.after(100,chrono)
else:
start2()
def update_label(data, index):
cha=[n,p]
n=('Les Rouges jouent... (Clic Droit)', 'red' )
p=('Les Blanc jouent...(Clic Gauche)', 'dimgray')
text, color = data[index]
label.configure(text=text, fg=color)
index = (index + 1) % len(data)
fen.after(15000, update_label, data, index)
for n in cha:
can.bind("<Button-1>", P_Rouge)
can.bind("<Button-3>", P_Corrige)
for p in cha:
can.bind("<Button-1>", P_Gris)
can.bind("<Button-3>", P_Corrige)
def start_update_label():
n=('Les Rouges jouent... (Clic Droit)', 'red' )
p=('Les Blanc jouent...(Clic Gauche)', 'dimgray')
i=1
btn['state'] = 'disabled'
data = [n,p]
update_label(data, 0)
start2()
def start():
fig_1()
fig_2()
r=20
fen = tk.Tk()
fen.title('Jeu de Dame')
fen.resizable(width=False, height=False)
can = Canvas(fen, width =400, height =400, bg ='white')
can.bind("<Button-2>", P_Corrige)
can.bind("<Double-Button-1>", P_Dame)
can.bind("<Double-Button-3>",P_Corrige2)
can.pack(side =TOP, padx =5, pady =5)
b1 = Button(fen, text ='Damier', command =start)
b1.pack(side =LEFT, padx =3, pady =3)
b3 = Button(fen, text ='Quitter', command =fen.destroy)
b3.pack(side =BOTTOM,padx =3, pady =3)
btn=tk.Button(fen, text="Start",command=start_update_label)
btn.pack(side =RIGHT, padx =3, pady =3)
label = tk.Label(fen, text=' ')
label.pack()
lab=tk.Label(fen, text="")
lab.pack() |
Partager