Guest User

tonperilmangedesburgers

a guest
Dec 11th, 2019
108
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import tkinter as tk
  2. c=0
  3. e=1
  4. coupsjr1=[]
  5. coupsjr2=[]
  6. xjr1={}
  7. xjr2={}
  8. yjr1={}
  9. yjr2={}
  10. def remise_a_plat(event):
  11. global c,xjr1,yjr1,xjr2,yjr2,coupsjr1,coupsjr2,e
  12. coupsjr1=[]
  13. coupsjr2=[]
  14. xjr1={}
  15. xjr2={}
  16. yjr1={}
  17. yjr2={}
  18. 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)]
  19. comm.config(text='')
  20. comm2.config(text='')
  21. c=0
  22. e=1
  23. def clic(event):
  24. global c,e
  25. comm.config(text='')
  26. j=event.x//100
  27. i=event.y//100
  28. a=(j,i)
  29. if c==0:
  30. if a in coupsjr1 or a in coupsjr2:
  31. comm.config(text='pas possible')
  32. else:
  33. e=e*-1
  34. if e==1:
  35. comm2.config(text='au joueur rond')
  36. coupsjr2.append(a)
  37. terrain.create_oval(j*100,i*100,(j+1)*100,(i+1)*100,fill='#FFFFFF')
  38. if j in xjr2.keys():
  39. xjr2[j]=xjr2[j]+1
  40. else:
  41. xjr2[j]=1
  42. if i in yjr2.keys():
  43. yjr2[i]=yjr2[i]+1
  44. else:
  45. yjr2[i]=1
  46. comm2.config(text='au joueur croix')
  47. else:
  48. coupsjr1.append(a)
  49. terrain.create_line(j*100,i*100,(j+1)*100,(i+1)*100,fill='#000000')
  50. terrain.create_line(j*100,(i+1)*100,(j+1)*100,i*100,fill='#000000')
  51. if j in xjr1.keys():
  52. xjr1[j]=xjr1[j]+1
  53. else:
  54. xjr1[j]=1
  55. if i in yjr1.keys():
  56. yjr1[i]=yjr1[i]+1
  57. else:
  58. yjr1[i]=1
  59. comm2.config(text='au joueur rond')
  60. if 3 in xjr1.values() or 3 in yjr1.values():
  61. comm.config(text='les croix ont gagné')
  62. c=c+1
  63. elif 3 in xjr2.values() or 3 in yjr2.values():
  64. comm.config(text='les ronds ont gagné')
  65. c=c+1
  66. elif ((0,0) in coupsjr1) and ((1,1) in coupsjr1) and ((2,2) in coupsjr1):
  67. comm.config(text='les croix ont gagné')
  68. c=c+1
  69. elif ((0,0) in coupsjr2) and ((1,1) in coupsjr2) and ((2,2) in coupsjr2):
  70. comm.config(text='les ronds ont gagné')
  71. c=c+1
  72. elif ((0,2) in coupsjr1) and ((1,1) in coupsjr1) and ((2,0) in coupsjr1):
  73. comm.config(text='les croix ont gagné')
  74. c=c+1
  75. elif ((0,2) in coupsjr2) and ((1,1) in coupsjr2) and ((2,0) in coupsjr2):
  76. comm.config(text='les ronds ont gagné')
  77. c=c+1
  78. elif len(coupsjr1)+len(coupsjr2)==9:
  79. comm.config(text='match nul')
  80. c=c+1
  81. else:
  82. comm2.config(text='le match est fini')
  83. fenetre=tk.Tk()
  84.  
  85. fenetre.title("jeu du morpion")
  86. terrain=tk.Canvas(fenetre,height=300,width=300)
  87. terrain.pack()
  88. 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)]
  89. terrain.bind('<Button>',clic)
  90. comm=tk.Label(fenetre,text='')
  91. comm.pack()
  92. comm2=tk.Label(text='au joueur croix')
  93. comm2.pack()
  94. coord=tk.Label(fenetre)
  95. coord.pack(pady='10px')
  96. retry=tk.Button(fenetre,text='refaire')
  97. retry.pack()
  98. retry.bind('<Button-1>',remise_a_plat)
  99. fenetre.mainloop()
RAW Paste Data