Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2020
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. from guizero import App, TextBox, PushButton, Box, Combo, CheckBox, Slider, MenuBar, info
  2.  
  3.  
  4. go="X"
  5.  
  6. def winner_check():
  7. global board
  8. #rows check
  9. for i in range (3):
  10. print (sum(board[i]))
  11. if sum(board[i])==3:
  12. message.value="win for x in row "
  13. if sum(board[i])==12:
  14. message.value="win for O in row "
  15.  
  16. #column check
  17.  
  18. for col in range (3):
  19. tot=0
  20. for row in range (3):
  21. tot+=board[row][col]
  22.  
  23. if tot==3:
  24. message.value="win for x"
  25. if tot==12:
  26. message.value="win for O"
  27.  
  28. diag=board[0][0]+board[1][1]+board[2][2]
  29. diag2=board[0][2]+board[1][1]+board[2][0]
  30. if diag==3 or diag2==3:
  31. message.value="Diagonal WIN for X"
  32. if diag==12 or diag2==12:
  33. message.value="Diagonal WIN for O"
  34.  
  35.  
  36.  
  37. def newgame():
  38. #this will refill the board with zeros
  39. #reset all the buttons to the numbers
  40. global board
  41. board=[[0,0,0],[0,0,0],[0,0,0]]
  42. print (board)
  43. for i in range (3):
  44. for j in range(3):
  45. z=a[i][j]
  46. z.text="."
  47. message.value="Player X to play!"
  48.  
  49.  
  50. def pr(arg):
  51. global go
  52. global board
  53. global a
  54. x=arg[0]
  55. y=arg[1]
  56. z=a[x][y]
  57. if z.text==".":
  58. z.text=go
  59.  
  60. if go=="X":
  61. go="O"
  62. board[y][x]=1
  63. message.value="O to play"
  64. else:
  65. go="X"
  66. board[y][x]=4
  67. message.value="X to play"
  68. #z.text=board[y][x]
  69. winner_check()
  70.  
  71.  
  72.  
  73.  
  74. app=App("title")
  75. a=[[0,0,0],[0,0,0],[0,0,0]]
  76. board=[[0,0,0],[0,0,0],[0,0,0]]
  77.  
  78. mybox=Box(app,layout="grid", width="600",height="600")
  79. mycol="red"
  80. for row in range(3):
  81. for col in range(3):
  82. mybox2=Box(mybox,grid=[col,row],width="200",height="200")
  83. a[col][row]=PushButton(mybox2,text=".",args=[[col,row]],command=pr)
  84.  
  85. message=TextBox(app,text="Player X Play", width="fill")
  86. new=PushButton(app,text="New", command=newgame)
  87.  
  88. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement