-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
71 lines (52 loc) · 1.82 KB
/
main.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
import kivy
kivy.require('1.0.6') # replace with your current kivy version !
from kivy.app import App
from game import Game
from fieldwidget import FieldWidget
from hellowidget import HelloWidget
from kivy.uix.widget import Widget
import weakref
class RootWidget(Widget):
pass
class UnitWidget(Widget):
pass
class GameStatesObserver:
def __init__(self, RootWidget):
self.RootWidget = RootWidget
self.units = []
self.__fieldSize = 5
def onGameStart(self, game):
self.current.onGameStart(game)
def onGameOver(self, game):
self.current.onGameOver(game)
def onLevelUp(self, game):
self.current.onLevelUp(game)
def onGamePrepare(self, game):
self.RootWidget.rootLayout.clear_widgets()
self.current = FieldWidget(game)
self.current.onFieldSizeChanged(self.__fieldSize)
self.current.onUnitsCountChange(self.units)
self.units = []
self.current.onGamePrepare(game)
self.RootWidget.rootLayout.add_widget(self.current)
def onGameInit(self, game):
self.RootWidget.rootLayout.clear_widgets()
self.current = HelloWidget(game, self)
self.current.onGameInit(game)
self.RootWidget.rootLayout.add_widget(self.current)
def onUnitsCountChange(self, units):
self.current.onUnitsCountChange(units)
def onFieldSizeChanged(self, size):
self.current.onFieldSizeChanged(size)
self.__fieldSize = size
def onScoreChanged(self, bonus):
self.current.onScoreChanged(bonus)
class OceanApp(App):
'''Main appliaction class'''
def build(self):
rootWidget = RootWidget()
observer = GameStatesObserver(rootWidget)
rootWidget.game = Game(gameStatesObserver=observer)
return rootWidget
if __name__ == '__main__':
OceanApp().run()