Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- c=0
- e=1
- coupsjr1=[]
- coupsjr2=[]
- xjr1={}
- xjr2={}
- yjr1={}
- yjr2={}
- def remise_a_plat(event):
- global c,xjr1,yjr1,xjr2,yjr2,coupsjr1,coupsjr2,e
- coupsjr1=[]
- coupsjr2=[]
- xjr1={}
- xjr2={}
- yjr1={}
- yjr2={}
- carreau=[[terrain.create_rectangle(i*100,j*100,(i+1)*100,(j+1)*100,fill="#FFFFFF") for i in range(3)] for j in range(3)]
- comm.config(text='')
- comm2.config(text='')
- c=0
- e=1
- def clic(event):
- global c,e
- comm.config(text='')
- j=event.x//100
- i=event.y//100
- a=(j,i)
- if c==0:
- if a in coupsjr1 or a in coupsjr2:
- comm.config(text='pas possible')
- else:
- e=e*-1
- if e==1:
- comm2.config(text='au joueur rond')
- coupsjr2.append(a)
- terrain.create_oval(j*100,i*100,(j+1)*100,(i+1)*100,fill='#FFFFFF')
- if j in xjr2.keys():
- xjr2[j]=xjr2[j]+1
- else:
- xjr2[j]=1
- if i in yjr2.keys():
- yjr2[i]=yjr2[i]+1
- else:
- yjr2[i]=1
- comm2.config(text='au joueur croix')
- else:
- coupsjr1.append(a)
- terrain.create_line(j*100,i*100,(j+1)*100,(i+1)*100,fill='#000000')
- terrain.create_line(j*100,(i+1)*100,(j+1)*100,i*100,fill='#000000')
- if j in xjr1.keys():
- xjr1[j]=xjr1[j]+1
- else:
- xjr1[j]=1
- if i in yjr1.keys():
- yjr1[i]=yjr1[i]+1
- else:
- yjr1[i]=1
- comm2.config(text='au joueur rond')
- if 3 in xjr1.values() or 3 in yjr1.values():
- comm.config(text='les croix ont gagné')
- c=c+1
- elif 3 in xjr2.values() or 3 in yjr2.values():
- comm.config(text='les ronds ont gagné')
- c=c+1
- elif ((0,0) in coupsjr1) and ((1,1) in coupsjr1) and ((2,2) in coupsjr1):
- comm.config(text='les croix ont gagné')
- c=c+1
- elif ((0,0) in coupsjr2) and ((1,1) in coupsjr2) and ((2,2) in coupsjr2):
- comm.config(text='les ronds ont gagné')
- c=c+1
- elif ((0,2) in coupsjr1) and ((1,1) in coupsjr1) and ((2,0) in coupsjr1):
- comm.config(text='les croix ont gagné')
- c=c+1
- elif ((0,2) in coupsjr2) and ((1,1) in coupsjr2) and ((2,0) in coupsjr2):
- comm.config(text='les ronds ont gagné')
- c=c+1
- elif len(coupsjr1)+len(coupsjr2)==9:
- comm.config(text='match nul')
- c=c+1
- else:
- comm2.config(text='le match est fini')
- fenetre=tk.Tk()
- fenetre.title("jeu du morpion")
- terrain=tk.Canvas(fenetre,height=300,width=300)
- terrain.pack()
- carreau=[[terrain.create_rectangle(i*100,j*100,(i+1)*100,(j+1)*100,fill="#FFFFFF") for i in range(3)] for j in range(3)]
- terrain.bind('<Button>',clic)
- comm=tk.Label(fenetre,text='')
- comm.pack()
- comm2=tk.Label(text='au joueur croix')
- comm2.pack()
- coord=tk.Label(fenetre)
- coord.pack(pady='10px')
- retry=tk.Button(fenetre,text='refaire')
- retry.pack()
- retry.bind('<Button-1>',remise_a_plat)
- fenetre.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement