Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. import pygame
  2.  
  3. pygame.init()
  4.  
  5. white = (255,255,255)
  6. black = (0,0,0)
  7. red = (255,0,0)
  8. blue = (0,0,255)
  9. width, height = 601, 601
  10. screen = pygame.display.set_mode((width,height))
  11.  
  12.  
  13. class Board:
  14. def __init__(self, i, j, w):
  15. self.i = i
  16. self.j = j
  17. self.x = i * w
  18. self.y = j * w
  19. self.w = w
  20. self.taken = False
  21. self.won = False
  22.  
  23. def getBoard(self):
  24. pygame.draw.rect(screen, black, [self.x, self.y, self.w, self.w], 2)
  25.  
  26.  
  27. def playerMove(self, player):
  28. len = 10
  29. if player == 'X' and not self.taken:
  30. pygame.draw.line(screen, red, (self.x+len, self.y+len), (self.x+self.w-1-len, self.y+self.w-1-len), 8)
  31. pygame.draw.line(screen, red, (self.x+self.w-len, self.y+len), (self.x+len, self.y+self.w-len), 8)
  32. self.taken = True
  33. elif(player != 'X' and not self.taken):
  34. pygame.draw.circle(screen, blue, (int(self.x+self.w*0.5),int(self.y+self.w*0.5)), int(self.w*0.5-len), 8)
  35. self.taken = True
  36.  
  37.  
  38. def contains(self, x, y):
  39. return (x >= self.x and x < self.x+self.w and y >= self.y and y < self.y+self.w)
  40.  
  41. def isWinner(self, grid):
  42. for i in range(1, -1, -1):
  43. for j in range(1, -1, -1):
  44. neighbor = grid[self.i+i][self.j+j]
  45. if neighbor == 3:
  46. print('Has Won')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement