-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.py
80 lines (66 loc) · 2.03 KB
/
action.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from externs import *
class Action(object):
'''
This class describes a thing being done, such as an apple being eaten.
'''
audio = None
def __init__(self, board, *toperform):
self.board = board
self.toperform = toperform
pass
def perform(self):
pass
class EatAppleAction(Action):
def __init__(self, board, *toperform):
self.board = board
self.toperform = toperform
def perform(self, y, x):
for f in self.toperform:
f()
self.board.board[y][x] = SPACE
self.board.grow_snake()
class EatMoneyAction(Action):
def __init__(self, board, *toperform):
self.board = board
self.toperform = toperform
def perform(self, y, x):
for f in self.toperform:
f()
self.board.board[y][x] = SPACE
class HitBlockAction(Action):
def __init__(self, board, *toperform):
self.board = board
self.toperform = toperform
def perform(self, y, x):
for f in self.toperform:
f()
class EatLifeAction(Action):
def __init__(self, board, *toperform):
self.board = board
self.toperform = toperform
def perform(self, y, x):
for f in self.toperform:
f()
if self.board[y][x] == SECRETLIFE:
self.board[y][x] = SECRET
else:
self.board.board[y][x] = SPACE
self.board.lives += 1
class GameOverAction(Action):
# TODO: Animate the final game over scene
def __init__(self, board, screen, *toperform):
self.board = board
self.screen = screen
self.toperform = toperform
def perform(self, y, x):
for f in self.toperform:
f()
class LevelWinAction(Action):
# TODO: Animate the final game over scene
def __init__(self, board, screen, *toperform):
self.board = board
self.screen = screen
self.toperform = toperform
def perform(self, y, x):
for f in self.toperform:
f()