-
Notifications
You must be signed in to change notification settings - Fork 12
/
tile.py
57 lines (50 loc) · 1.49 KB
/
tile.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
from settings import *
class Tile:
def __init__(self, piece, x, y):
self.piece = piece
self.x = x
self.y = y
self.color = BLACK
self.surface = pygame.Surface((TILE_SIZE, TILE_SIZE))
def fill(self, color):
"""
Fills tile with specified color
:param color: color to fill tile with (tuple)
:return: None
"""
self.surface.fill(color)
def select(self):
"""
Applies highlighted effect to tile, indicating selection
:return: None
"""
if self.contains_piece():
self.fill(HIGHLIGHT_COLOR)
self.draw()
def draw(self):
"""
Draws tile and the piece it contains (if applicable)
:return: None
"""
SCREEN.blit(self.surface, to_coords(self.x, self.y))
if self.piece:
self.piece.draw()
def contains_piece(self):
"""
Checks if tile contains a piece
:return: bool representing whether or not tile contains piece
"""
if self.piece.image is None:
return False
return True
def copy(self):
"""
Creates a deep copy of the current tile
:return: reference to a new Tile object
"""
piece = None
if self.piece:
piece = self.piece.copy()
copy = Tile(piece, self.x, self.y)
copy.fill(self.color)
return copy