-
Notifications
You must be signed in to change notification settings - Fork 0
/
piece.py
65 lines (53 loc) · 2.44 KB
/
piece.py
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
56
57
58
59
60
61
62
63
64
65
from handletablemove import HandlerTableMove
class Piece:
def __init__(self, posx: int, posy: int, table_map, p_type: str ="N", text_color: tuple =(0,0,0), move = [], rangelen: int = 1, color: tuple = ()):
self.posx = posx
self.posy = posy
self.table_map = table_map
self.higthLight = (250, 200, 100)
self.p_type = p_type
self.text_color = text_color
self.is_selected = False
self.move = move
self.color = color
self.rangelen = rangelen
def eat(self):
pass
def render(self, display, py, table_map, font):
if self.is_selected and self.p_type != 'W':
for pos in self.getPositions():
py.draw.rect(display, (255, 0, 0), (50 * pos[0], 50 * pos[1], 50, 50), True)
if self.p_type != 'W':
py.draw.rect(display, self.higthLight if self.isOverSelected(py, self)[0] or self.is_selected else self.color, (50 * self.posx, 50 * self.posy, 50, 50), False)
else:
self.isOverSelected(py, self)
textsurface = font.render(self.p_type, False, self.text_color)
display.blit(textsurface,(53 * self.posx, 50 * self.posy))
def rangeAtackShow(self):
pass
def rangeAtackValidate(self):
pass
def isOverSelected(self, py, piece):
mouseposs = py.mouse.get_pos()
is_over_selected = [False, False]
if mouseposs[0] > (piece.posx * 50) and mouseposs[0] < (piece.posx * 50) + 50 and mouseposs[1] > (piece.posy * 50) and mouseposs[1] < (piece.posy * 50) + 50:
if py.mouse.get_pressed()[0] == 1 and not self.is_selected:
HandlerTableMove.setSelection(HandlerTableMove, (piece.posx, piece.posy, piece))
HandlerTableMove.table_map = self.table_map
HandlerTableMove.select(HandlerTableMove)
self.is_selected = True
is_over_selected[0] = True
else:
if py.mouse.get_pressed()[0] == 1:
self.is_selected = False
is_over_selected[0] = False
return is_over_selected
def getPositions(self):
positions = []
for x in self.move:
m = x(self, self.rangelen)
if m is not None:
for n in m:
if self.table_map[n[0]][n[1]].p_type == 'W':
positions.append(n)
return positions