-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgamestates.py
80 lines (61 loc) · 1.95 KB
/
gamestates.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
"""Game states"""
from abc import ABCMeta, abstractmethod
from mplayer import mplayer
class AbstractGameState:
@abstractmethod
def pushOn(self, game, cell, field):
pass
@abstractmethod
def update(self, game):
pass
class PlayGameState(AbstractGameState):
def __init__(self):
mplayer.startGame()
mplayer.playMusic()
def pushOn(self, game, cell, field):
field.pushOn(game, cell)
def update(self, game):
if game.isGameOver():
game.state = GameOverState()
game.observer.onGameOver(game)
mplayer.stopMusic()
if game.isLevelUp():
game.onLevelUp(game.levelsFactory.next(game.lvl))
game.state = GameLevelUp()
game.observer.onLevelUp(game)
mplayer.stopMusic()
class GameOverState(AbstractGameState):
def __init__(self):
mplayer.gameOver()
def pushOn(self, game, cell, field):
game.state = InitGameState(game)
game.observer.onGameInit(game)
def update(self, game):
pass
class GameLevelUp(AbstractGameState):
def __init__(self):
mplayer.levelUp()
def pushOn(self, game, cell, field):
game.state = InitGameState(game)
game.observer.onGameInit(game)
def update(self, game):
pass
class InitGameState(AbstractGameState):
def __init__(self, game):
game.initPlayers()
def pushOn(self, game, cell, field):
game.state = PrepareGameState()
game.observer.onGamePrepare(game)
def update(self, game):
game.state = PrepareGameState()
game.observer.onGamePrepare(game)
class PrepareGameState(AbstractGameState):
def pushOn(self, game, cell, field):
field.setUnit(cell)
if game.isReadyToPlay():
game.state = PlayGameState()
game.observer.onGameStart(game)
def update(self, game):
pass
def createInitState(game):
return InitGameState(game)