self._title.pos = (300, 100)
self._nav = ActorNavigator()
self._menu = [
- TextButton("Play", action=self.change_to_level),
- TextButton("View Last Generated Level",
- action=self.change_to_viewer),
- TextButton("Manage Roaches",
- action=self.change_to_roach_management),
+ TextButton("New Game", action=self.change_to_new_game),
+ TextButton("Resume", action=self.change_to_resume),
TextButton("Credits", action=self.change_to_credits),
TextButton("Quit", action=self.quit),
]
wrap=True)
self._nav.current.select()
- def change_to_level(self):
+ def change_to_resume(self):
from .level import GameLevelScene
return [ChangeSceneEvent(GameLevelScene())]
- def change_to_viewer(self):
- from .viewlevel import ViewLevelScene
+ def change_to_new_game(self):
+ from .level import GameLevelScene
return [
- WorldEvent("set", {"level.name": "map"}),
- ChangeSceneEvent(ViewLevelScene())
+ WorldEvent("reset"),
+ ChangeSceneEvent(GameLevelScene())
]
- def change_to_roach_management(self):
- from .roach_management import RoachesScene
- return [ChangeSceneEvent(RoachesScene())]
-
def change_to_credits(self):
from .credits import CreditsScene
return [ChangeSceneEvent(CreditsScene())]
roach.update(kw)
return roach
- def _apply_set(self, updates):
+ def _apply_set(self, action, updates):
for name, value in updates.items():
parts = name.split(".")
obj = self._state
raise KeyError("%r not found in world" % (name,))
obj[parts[-1]] = value
+ def _apply_reset(self, action):
+ self._state = self._build_initial_state()
+
+ def _apply_unknown(self, action, *args, **kw):
+ raise ValueError("Unknown world event action: %r" % (action,))
+
def proxy(self):
return WorldDictProxy(self._state)
break
def apply_event(self, action, *args, **kw):
- if action == "set":
- return self._apply_set(*args, **kw)
- raise ValueError("Unknown world event action: %r" % (action,))
+ handler = getattr(self, "_apply_%s" % (action,))
+ return handler(action, *args, **kw)
def _maybe_subproxy(proxy, name, value):