forked from geekcomputers/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpieces.py
More file actions
55 lines (42 loc) · 1.24 KB
/
pieces.py
File metadata and controls
55 lines (42 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
Author : Dhruv B Kakadiya
"""
from .statics import *
import pygame as pg
class pieces:
padding = 17
outline = 2
def __init__(self, row, col, color):
self.row = row
self.col = col
self.color = color
self.king = False
"""if (self.color == yellow):
self.direction = -1
else:
self.direction = 1"""
self.x = self.y = 0
self.calculate_pos()
# calculate the positions
def calculate_pos(self):
self.x = (sq_size * self.col) + (sq_size // 2)
self.y = (sq_size * self.row) + (sq_size // 2)
# for making king
def make_king(self):
self.king = True
def draw(self, window):
radd = (sq_size // 2) - self.padding
pg.draw.circle(window, gray, (self.x, self.y), radd + self.outline)
pg.draw.circle(window, self.color, (self.x, self.y), radd)
if self.king:
window.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.calculate_pos()
# represtation as a string
def __repr__(self):
return str(self.color)