-
Notifications
You must be signed in to change notification settings - Fork 1
/
Grid.py
48 lines (35 loc) · 975 Bytes
/
Grid.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
class Grid:
EMPTY = 0
PILL = 1
POWER_UP = 2
CHERRY = 3
WALL = 4
def __init__(self, x, y, T=EMPTY):
self.x = x
self.y = y
self.__type = T
self.objects_on_top = []
def get_x(self):
return self.x
def get_y(self):
return self.y
def get_type(self):
return self.__type
def get_objects_on_top(self):
return self.objects_on_top
def insert_object_on_top(self, obj):
self.objects_on_top.append(obj)
def remove_object_on_top(self, obj):
self.objects_on_top.remove(obj)
def set_type(self, T):
self.__type = T
def consume(self):
if self.__type == Grid.WALL:
raise Exception('You cannot consume wall!')
T = self.__type
self.__type = Grid.EMPTY
return T
def __repr__(self):
return str(self.__type)
def __str__(self):
return str(self.__type)