-
Notifications
You must be signed in to change notification settings - Fork 0
/
cell.py
64 lines (51 loc) · 1.6 KB
/
cell.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
" Cells module"
import cellstates
class AbstractStateObserver:
def onCellStateChanged(self, state):
pass
class Cell:
x = 0
y = 0
def __init__(self, x, y):
self.x, self.y = x, y
self.__state = cellstates.defaultState
self.__hidden = False
self.deactivated = False
self.stateObservers = []
self.activeObservers = []
self.decorators = {}
def deactivate(self):
self.deactivated = True
for observer in self.activeObservers:
observer.onDeactivated()
def activate(self):
self.deactivated = False
for observer in self.activeObservers:
observer.onActivated()
def addActivateObserver(self, observer):
if self.deactivated:
observer.onDeactivated()
self.activeObservers.append(observer)
def hide(self):
""" State will be shown as default"""
self.__hidden = True
def unhide(self):
""" State will be shown as is"""
self.__hidden = False
def setUnit(self, unit):
self.decorators["unit_type"] = unit
self.setState(cellstates.UnitCellState())
def pushOn(self):
self.setState(self.__state.transfer(self))
@property
def state(self):
"""Return name of current state"""
if self.__hidden:
return "default"
return self.__state.name
def setState(self, newState):
if self.__state == newState:
return
self.__state = newState
for observer in self.stateObservers:
observer.onCellStateChanged(self, self.state)