-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions.py
57 lines (45 loc) · 1.4 KB
/
actions.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
class Action:
def __init__(self, data) -> None:
self.action = None
self.game_id = data['game_id']
self.turn_token = data['turn_token']
def to_dict(self):
return {
'action': self.action,
'data': {
'game_id': self.game_id,
'turn_token': self.turn_token,
},
}
class Move(Action):
def __init__(self, data, from_row, from_col,to_row, to_col) -> None:
super().__init__(data)
self.action = 'move'
self.from_row = from_row
self.to_row = to_row
self.from_col = from_col
self.to_col = to_col
def to_dict(self):
ret = super().to_dict()
ret['data'].update({
'from_row': self.from_row,
'to_row': self.to_row,
'from_col': self.from_col,
'to_col': self.to_col,
})
return ret
class WallAction(Action):
def __init__(self, data, row, col, orientation) -> None:
super().__init__(data)
self.action = 'wall'
self.row = row
self.col = col
self.orientation = orientation
def to_dict(self):
ret = super().to_dict()
ret['data'].update({
'row': self.row,
'col': self.col,
'orientation': self.orientation,
})
return ret