Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import*
- from time import*
- col=0
- lig=0
- tour= 0
- win=0
- e=0
- LS=[0,1]
- LV=[[0,0,0],
- [0,0,0],
- [0,0,0]
- ]
- #Affichage de l'action du joueur
- def cliquer(event):
- global col,lig,tour,LV,win
- abs=event.x
- ord=event.y
- col=abs//200
- lig=ord//200
- #Alterance de jeu
- if tour==0 :
- if LV[lig][col]==0:
- #Joueur 1 avec X
- texte=Can.create_text(col*200+100,lig*200+100,text="X",font="Helvetica 120 bold",fill='blue')
- LV[lig][col]=2
- print(LV,tour)
- if tour==1:
- if LV[lig][col]==0:
- #Joueur 2 avec O
- texte=Can.create_text(col*200+100,lig*200+100,text="O", font="Helvetica 120 bold",fill='red')
- LV[lig][col]=1
- print(LV,tour)
- if tour==0:
- tour=1
- elif tour==1:
- tour=0
- for i in range(0,3):
- if(LV[i][0]==LV[i][1]==LV[i][2]==1):
- Can.create_text(300, 175, text = 'Les ronds ont gagnés !', font = 'Arial 20 bold')
- Can.unbind('<Button-1>')
- win=1
- # Lignes
- for i in range(0,3):
- if(LV[0][i]==LV[1][i]==LV[2][i]==1):
- Can.create_text(300, 175, text = 'Les ronds ont gagnés !', font = 'Arial 20 bold')
- Can.unbind('<Button-1>')
- win=1
- # Diagonales
- if(LV[0][0]==LV[1][1]==LV[2][2]==1):
- Can.create_text(300, 175, text = 'Les ronds ont gagnés !', font = 'Arial 20 bold')
- Can.unbind('<Button-1>')
- win=1
- if(LV[0][2]==LV[1][1]==LV[2][0]==1):
- Can.create_text(300, 175, text = 'Les ronds ont gagnés !', font = 'Arial 20 bold')
- Can.unbind('<Button-1>')
- win=1
- # Croix
- # Colonne
- for i in range(0,3):
- if(LV[i][0]==LV[i][1]==LV[i][2]==2):
- Can.create_text(300, 175, text = 'Les croix ont gagnés !', font = 'Arial 20 bold')
- Can.unbind('<Button-1>')
- win=1
- #lignes
- for i in range(0,3):
- if(LV[0][i]==LV[1][i]==LV[2][i]==2):
- Can.create_text(300, 175, text = 'Les croix ont gagnés !', font = 'Arial 20 bold')
- Can.unbind('<Button-1>')
- win=1
- #diagonales
- if(LV[0][0]==LV[1][1]==LV[2][2]==2):
- Can.create_text(300, 175, text = 'Les croix ont gagnés !', font = 'Arial 20 bold')
- Can.unbind('<Button-1>')
- win=1
- if(LV[0][2]==LV[1][1]==LV[2][0]==2):
- Can.create_text(300, 175, text = 'Les croix ont gagnés !', font = 'Arial 20 bold')
- Can.unbind('<Button-1>')
- win=1
- egalite = 9
- #vide
- for i in range(0,3):
- for j in range(0,3):
- if(LV[i][j]!=0):
- egalite -= 1
- print(egalite,win)
- if egalite == 0 and win==0:
- Can.create_text(300, 175, text = 'Egalité !', font = 'Arial 20 bold')
- Can.unbind('<Button-1>')
- #restart
- def restart():
- global tour,LV,col,lig,Can
- tour=0
- LV=[[0,0,0],
- [0,0,0],
- [0,0,0]
- ]
- lig=0
- col=0
- Can.destroy()
- Can =Canvas(f1,width=600,height=600, bg='white')
- Can.place(x=800,y=750)
- Can.create_line(200,0,200,600, fill='black')
- Can.create_line(400,0,400,600, fill='black')
- Can.create_line(0,200,600,200, fill='black')
- Can.create_line(0,400,600,400, fill='black')
- Can.pack()
- Can.bind('<Button-1>',cliquer)
- #Affichage grille
- def Jouer():
- global b1,b2,Menu,b4,Can
- b3.pack_forget()
- Menu.pack_forget()
- Can.place(x=800,y=750)
- #Bouton retour
- b4=Button(f1,text='Retour',command=retour)
- b4.pack(side=TOP)
- Can.create_line(200,0,200,600, fill='black')
- Can.create_line(400,0,400,600, fill='black')
- Can.create_line(0,200,600,200, fill='black')
- Can.create_line(0,400,600,400, fill='black')
- Can.pack()
- Can.bind('<Button-1>',cliquer)
- #Bouton restart
- b2=Button(f1,text='Restart',command=restart)
- b2.pack(side=BOTTOM)
- #Bouton quitter
- b1=Button(f1,text='Quitter',command=f1.destroy)
- b1.pack(side=BOTTOM)
- #Destruction du menu
- b3.pack_forget()
- Menu.pack_forget()
- #Retour
- def retour():
- global e,LS,b1,b2,b3,b4,Menu
- if e==0 :
- Can.forget()
- b1.forget()
- b2.forget()
- b4.forget()
- Menu=Label(f1,width=50,height=0,text=' Bienvenue sur le meilleur MORPION du monde ',font = 'Revue 15 bold',bg='white')
- Menu.pack(padx=100,pady=100)
- e=1
- b3=Button(f1,width=75,height=100,text='JOUER',command=Jouer)
- b3.pack(padx=200,pady=200)
- b4.forget()
- e=0
- #fenetre principale
- f1=Tk()
- f1.geometry('700x700+400+150')
- f1['bg']='black'
- Can = Canvas(f1,width=600,height=600, bg='white')
- Can.place(x=800,y=750)
- Menu=Label(f1,width=50,height=0,text=' Bienvenue sur le meilleur MORPION du monde ',font = 'Revue 15 bold',bg='white')
- Menu.pack(padx=100,pady=100)
- #Bouton jouer
- b3=Button(f1,width=75,height=100,text='JOUER',command=Jouer)
- b3.pack(padx=200,pady=200)
- f1.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement