41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
import pygame.draw
|
|
|
|
from utilities.constants import SQUARE_SIZE, GREY, CROWN, GREEN
|
|
|
|
|
|
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
|
|
self.green = (144, 184, 59)
|
|
self.white = (255, 255, 255)
|
|
|
|
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.green if self.colour == GREEN else self.white, (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)
|