Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- pygame.init()
- white = (255,255,255)
- black = (0,0,0)
- red = (255,0,0)
- blue = (0,0,255)
- width, height = 601, 601
- screen = pygame.display.set_mode((width,height))
- class Board:
- def __init__(self, i, j, w):
- self.i = i
- self.j = j
- self.x = i * w
- self.y = j * w
- self.w = w
- self.taken = False
- self.won = False
- def getBoard(self):
- pygame.draw.rect(screen, black, [self.x, self.y, self.w, self.w], 2)
- def playerMove(self, player):
- len = 10
- if player == 'X' and not self.taken:
- pygame.draw.line(screen, red, (self.x+len, self.y+len), (self.x+self.w-1-len, self.y+self.w-1-len), 8)
- pygame.draw.line(screen, red, (self.x+self.w-len, self.y+len), (self.x+len, self.y+self.w-len), 8)
- self.taken = True
- elif(player != 'X' and not self.taken):
- 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)
- self.taken = True
- def contains(self, x, y):
- return (x >= self.x and x < self.x+self.w and y >= self.y and y < self.y+self.w)
- def isWinner(self, grid):
- for i in range(1, -1, -1):
- for j in range(1, -1, -1):
- neighbor = grid[self.i+i][self.j+j]
- if neighbor == 3:
- print('Has Won')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement