Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. import pygame, sys
  2. from board import Board
  3.  
  4.  
  5. pygame.init()
  6.  
  7.  
  8. white = (255, 255, 255)
  9. black = (0, 0, 0)
  10. width, height = 601, 601
  11. cols, rows = 3, 3
  12. if width < height:
  13.   w = width/cols
  14. else:
  15.   w = height/rows
  16.  
  17.  
  18. screen = pygame.display.set_mode((width,height))
  19. pygame.display.set_caption('TicTacToe')
  20. clock = pygame.time.Clock()
  21. screen.fill(white)
  22.  
  23.  
  24. def main():
  25.   game = [[Board(i, j, w) for i in range(cols)] for j in range(rows)]
  26.   for i in range(cols):
  27.     for j in range(rows):
  28.       game[i][j].getBoard()
  29.  
  30.   player = 'X'
  31.  
  32.   while True:
  33.     for event in pygame.event.get():
  34.       if event.type == pygame.QUIT:
  35.         pygame.quit()
  36.         sys.exit()
  37.  
  38.       if event.type == pygame.MOUSEBUTTONDOWN:
  39.         mouseX, mouseY = pygame.mouse.get_pos()
  40.        
  41.         for i in range(cols):
  42.           for j in range(rows):
  43.             if(game[i][j].contains(mouseX, mouseY)):
  44.               if player == 'X':
  45.                 game[i][j].playerMove(player)
  46.                 player = 'O'
  47.              
  48.               else:
  49.                 game[i][j].playerMove(player)
  50.                 player = 'X'
  51.    
  52.     game.isWinner(game)
  53.  
  54.             #game[i][j].printMouseCoordinates(str(pygame.mouse.get_pos()))
  55.     pygame.display.update()
  56.  
  57.  
  58.  
  59.  
  60.  
  61. if __name__ == "__main__":
  62.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement