comparison pyntnclick/main.py @ 655:c77d6aa29bee pyntnclick

Some code to kinda demonstrate the ever so cunning state handling plan
author Neil Muller <neil@dip.sun.ac.za>
date Sun, 12 Feb 2012 13:56:59 +0200
parents b2c2b6f56291
children 5dc866e1d71d
comparison
equal deleted inserted replaced
654:335db68e0db4 655:c77d6aa29bee
47 START_SCREEN = 'menu' 47 START_SCREEN = 'menu'
48 48
49 # resource module 49 # resource module
50 RESOURCE_MODULE = "Resources" 50 RESOURCE_MODULE = "Resources"
51 51
52 def __init__(self): 52 def __init__(self, custom_data_cls=None):
53 if self.INITIAL_SCENE is None: 53 if self.INITIAL_SCENE is None:
54 raise GameDescriptionError("A game must have an initial scene.") 54 raise GameDescriptionError("A game must have an initial scene.")
55 if not self.SCENE_LIST: 55 if not self.SCENE_LIST:
56 raise GameDescriptionError("A game must have a non-empty list" 56 raise GameDescriptionError("A game must have a non-empty list"
57 " of scenes.") 57 " of scenes.")
60 " game itself.") 60 " game itself.")
61 self._initial_scene = self.INITIAL_SCENE 61 self._initial_scene = self.INITIAL_SCENE
62 self._scene_list = self.SCENE_LIST 62 self._scene_list = self.SCENE_LIST
63 self._resource_module = self.RESOURCE_MODULE 63 self._resource_module = self.RESOURCE_MODULE
64 self._debug_rects = False 64 self._debug_rects = False
65 self._custom_data_cls = custom_data_cls
65 self._screens = self.SCREENS.copy() 66 self._screens = self.SCREENS.copy()
66 self._screens['game'] = GameScreen 67 self._screens['game'] = GameScreen
67 self.resource = Resources(self._resource_module) 68 self.resource = Resources(self._resource_module)
68 self.sound = Sound(self.resource) 69 self.sound = Sound(self.resource)
69 self.constants = self.game_constants() 70 self.constants = self.game_constants()
70 self.debug_options = [] 71 self.debug_options = []
71 72
72 def initial_state(self): 73 def initial_state(self):
73 """Create a copy of the initial game state.""" 74 """Create a copy of the initial game state."""
74 initial_state = state.Game(self) 75 initial_state = state.Game(self)
76 if self._custom_data_cls:
77 initial_state.set_custom_data(self._custom_data_cls())
75 initial_state.set_debug_rects(self._debug_rects) 78 initial_state.set_debug_rects(self._debug_rects)
76 for scene in self._scene_list: 79 for scene in self._scene_list:
77 initial_state.load_scenes(scene) 80 initial_state.load_scenes(scene)
78 initial_state.set_current_scene(self._initial_scene) 81 initial_state.set_current_scene(self._initial_scene)
79 initial_state.set_do_enter_leave() 82 initial_state.set_do_enter_leave()