MCPcopy Create free account
hub / github.com/geekcomputers/Python / pieces

Class pieces

Checker_game_by_dz/modules/pieces.py:10–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8
9
10class pieces:
11 padding = 17
12 outline = 2
13
14 def __init__(self, row, col, color):
15 self.row = row
16 self.col = col
17 self.color = color
18 self.king = False
19
20 """if (self.color == yellow):
21 self.direction = -1
22 else:
23 self.direction = 1"""
24
25 self.x = self.y = 0
26 self.calculate_pos()
27
28 # calculate the positions
29 def calculate_pos(self):
30 self.x = (sq_size * self.col) + (sq_size // 2)
31 self.y = (sq_size * self.row) + (sq_size // 2)
32
33 # for making king
34 def make_king(self):
35 self.king = True
36
37 def draw(self, window):
38 radd = (sq_size // 2) - self.padding
39 pg.draw.circle(window, gray, (self.x, self.y), radd + self.outline)
40 pg.draw.circle(window, self.color, (self.x, self.y), radd)
41 if self.king:
42 window.blit(
43 crown,
44 ((self.x - crown.get_width() // 2), (self.y - crown.get_height() // 2)),
45 )
46
47 def move(self, row, col):
48 self.row = row
49 self.col = col
50 self.calculate_pos()
51
52 # represtation as a string
53 def __repr__(self):
54 return str(self.color)

Callers 1

create_boardMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected