Advertisement
Guest User

PYTHON MORPION 1.1

a guest
Dec 7th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.36 KB | None | 0 0
  1. from tkinter import*
  2. from time import*
  3.  
  4. col=0
  5. lig=0
  6. tour= 0
  7. win=0
  8.  
  9. LV=[[0,0,0],
  10. [0,0,0],
  11. [0,0,0]
  12. ]
  13.  
  14. #Affichage de l'action du joueur
  15. def cliquer(event):
  16. global col,lig,tour,LV,win
  17. abs=event.x
  18. ord=event.y
  19. col=abs//200
  20. lig=ord//200
  21. #Alterance de jeu
  22. if tour==0 :
  23. if LV[lig][col]==0:
  24. #Joueur 1 avec X
  25. texte=Can.create_text(col*200+100,lig*200+100,text="X",font="Helvetica 120 bold",fill='blue')
  26. LV[lig][col]=2
  27. print(LV,tour)
  28.  
  29. if tour==1:
  30. if LV[lig][col]==0:
  31. #Joueur 2 avec O
  32. texte=Can.create_text(col*200+100,lig*200+100,text="O", font="Helvetica 120 bold",fill='red')
  33. LV[lig][col]=1
  34. print(LV,tour)
  35. if tour==0:
  36. tour=1
  37. elif tour==1:
  38. tour=0
  39.  
  40. for i in range(0,3):
  41. if(LV[i][0]==LV[i][1]==LV[i][2]==1):
  42. Can.create_text(300, 175, text = 'Les ronds ont gagnés !', font = 'Arial 20 bold')
  43. Can.unbind('<Button-1>')
  44. win=1
  45. # Lignes
  46. for i in range(0,3):
  47. if(LV[0][i]==LV[1][i]==LV[2][i]==1):
  48. Can.create_text(300, 175, text = 'Les ronds ont gagnés !', font = 'Arial 20 bold')
  49. Can.unbind('<Button-1>')
  50. win=1
  51.  
  52. # Diagonales
  53. if(LV[0][0]==LV[1][1]==LV[2][2]==1):
  54. Can.create_text(300, 175, text = 'Les ronds ont gagnés !', font = 'Arial 20 bold')
  55. Can.unbind('<Button-1>')
  56.  
  57. win=1
  58.  
  59. if(LV[0][2]==LV[1][1]==LV[2][0]==1):
  60. Can.create_text(300, 175, text = 'Les ronds ont gagnés !', font = 'Arial 20 bold')
  61. Can.unbind('<Button-1>')
  62. win=1
  63.  
  64.  
  65. # Croix
  66. # Colonne
  67. for i in range(0,3):
  68. if(LV[i][0]==LV[i][1]==LV[i][2]==2):
  69. Can.create_text(300, 175, text = 'Les croix ont gagnés !', font = 'Arial 20 bold')
  70. Can.unbind('<Button-1>')
  71. win=1
  72.  
  73.  
  74. #lignes
  75. for i in range(0,3):
  76. if(LV[0][i]==LV[1][i]==LV[2][i]==2):
  77. Can.create_text(300, 175, text = 'Les croix ont gagnés !', font = 'Arial 20 bold')
  78. Can.unbind('<Button-1>')
  79. win=1
  80.  
  81. #diagonales
  82. if(LV[0][0]==LV[1][1]==LV[2][2]==2):
  83. Can.create_text(300, 175, text = 'Les croix ont gagnés !', font = 'Arial 20 bold')
  84. Can.unbind('<Button-1>')
  85. win=1
  86.  
  87. if(LV[0][2]==LV[1][1]==LV[2][0]==2):
  88. Can.create_text(300, 175, text = 'Les croix ont gagnés !', font = 'Arial 20 bold')
  89. Can.unbind('<Button-1>')
  90. win=1
  91.  
  92. egalite = 9
  93. #vide
  94. for i in range(0,3):
  95. for j in range(0,3):
  96. if(LV[i][j]!=0):
  97. egalite -= 1
  98. print(egalite,win)
  99.  
  100. if egalite == 0 and win==0:
  101. Can.create_text(300, 175, text = 'Egalité !', font = 'Arial 20 bold')
  102. Can.unbind('<Button-1>')
  103.  
  104.  
  105.  
  106.  
  107. #restart
  108. def restart():
  109. global tour,LV,col,lig,Can
  110. tour=0
  111. LV=[[0,0,0],
  112. [0,0,0],
  113. [0,0,0]
  114. ]
  115. lig=0
  116. col=0
  117. Can.destroy()
  118. Can =Canvas(f1,width=600,height=600, bg='white')
  119. Can.create_line(200,0,200,600, fill='black')
  120. Can.create_line(400,0,400,600, fill='black')
  121. Can.create_line(0,200,600,200, fill='black')
  122. Can.create_line(0,400,600,400, fill='black')
  123. Can.pack()
  124. Can.bind('<Button-1>',cliquer)
  125.  
  126.  
  127.  
  128.  
  129. #Affichage grille
  130. def Jouer():
  131. global b1,b2
  132. Can.create_line(200,0,200,600, fill='black')
  133. Can.create_line(400,0,400,600, fill='black')
  134. Can.create_line(0,200,600,200, fill='black')
  135. Can.create_line(0,400,600,400, fill='black')
  136. Can.pack()
  137. Can.bind('<Button-1>',cliquer)
  138.  
  139. #Bouton restart
  140. b2=Button(f1,text='Restart',command=restart)
  141. b2.pack(side=BOTTOM)
  142.  
  143. #Bouton quitter
  144. b1=Button(f1,text='Quitter',command=f1.destroy)
  145. b1.pack(side=BOTTOM)
  146.  
  147. #Destruction du menu
  148. b3.pack_forget()
  149. Menu.pack_forget()
  150.  
  151.  
  152.  
  153. #fenetre principale
  154. f1=Tk()
  155. f1.geometry('700x650+400+150')
  156. f1['bg']='black'
  157. Can = Canvas(f1,width=600,height=600, bg='white')
  158.  
  159.  
  160.  
  161. Menu=Label(f1,width=50,height=0,text=' Bienvenue sur le meilleur MORPION du monde ',font = 'Revue 15 bold',bg='white')
  162. Menu.pack(padx=100,pady=100)
  163.  
  164.  
  165.  
  166. #Bouton jouer
  167. b3=Button(f1,width=75,height=100,text='JOUER',command=Jouer)
  168. b3.pack(padx=200,pady=200)
  169.  
  170. #Bouton retour
  171.  
  172.  
  173.  
  174.  
  175. f1.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement