import pygame.draw from utilities.constants import SQUARE_SIZE, GREY, CROWN class Piece: def __init__(self, row, col, colour): self.row = row self.col = col self.colour = colour self.king = False self.x = 0 self.y = 0 self.calcPosition() self.padding = 20 self.border = 2 def calcPosition(self): self.x = SQUARE_SIZE * self.col + SQUARE_SIZE // 2 self.y = SQUARE_SIZE * self.row + SQUARE_SIZE // 2 def makeKing(self): self.king = True def draw(self, win): radius = SQUARE_SIZE // 2 - self.padding pygame.draw.circle(win, GREY, (self.x, self.y), radius + self.border) pygame.draw.circle(win, self.colour, (self.x, self.y), radius) if self.king: win.blit(CROWN, (self.x - CROWN.get_width() // 2, self.y - CROWN.get_height() // 2)) def move(self, row, col): self.row = row self.col = col self.calcPosition() def __repr__(self): return str(self.colour)