comparison pyntnclick/main.py @ 750:ef4bda7d623d pyntnclick

Better state and inventory management.
author Jeremy Thurgood <firxen@gmail.com>
date Sun, 20 Jan 2013 20:20:36 +0200
parents a453731e4531
children f4853f817a7a
comparison
equal deleted inserted replaced
749:a453731e4531 750:ef4bda7d623d
43 43
44 # Modules 44 # Modules
45 RESOURCE_MODULE = 'data' 45 RESOURCE_MODULE = 'data'
46 SCENE_MODULE = 'gamelib.scenes' 46 SCENE_MODULE = 'gamelib.scenes'
47 47
48 def __init__(self, custom_data_cls=None): 48 def __init__(self):
49 if self.INITIAL_SCENE is None: 49 if self.INITIAL_SCENE is None:
50 raise GameDescriptionError("A game must have an initial scene.") 50 raise GameDescriptionError("A game must have an initial scene.")
51 if not self.SCENE_LIST: 51 if not self.SCENE_LIST:
52 raise GameDescriptionError("A game must have a non-empty list" 52 raise GameDescriptionError("A game must have a non-empty list"
53 " of scenes.") 53 " of scenes.")
56 " game itself.") 56 " game itself.")
57 self._initial_scene = self.INITIAL_SCENE 57 self._initial_scene = self.INITIAL_SCENE
58 self._scene_list = self.SCENE_LIST 58 self._scene_list = self.SCENE_LIST
59 self._resource_module = self.RESOURCE_MODULE 59 self._resource_module = self.RESOURCE_MODULE
60 self._debug_rects = False 60 self._debug_rects = False
61 self._custom_data_cls = custom_data_cls
62 self._screens = self.SCREENS.copy() 61 self._screens = self.SCREENS.copy()
63 self._screens['game'] = GameScreen 62 self._screens['game'] = GameScreen
64 self.resource = Resources(self._resource_module) 63 self.resource = Resources(self._resource_module)
65 self.sound = Sound(self.resource) 64 self.sound = Sound(self.resource)
66 self.constants = self.game_constants() 65 self.constants = self.game_constants()
68 self.running = False 67 self.running = False
69 68
70 def initial_state(self): 69 def initial_state(self):
71 """Create a copy of the initial game state.""" 70 """Create a copy of the initial game state."""
72 initial_state = state.Game(self) 71 initial_state = state.Game(self)
73 if self._custom_data_cls:
74 initial_state.set_custom_data(self._custom_data_cls())
75 initial_state.set_debug_rects(self._debug_rects) 72 initial_state.set_debug_rects(self._debug_rects)
76 for scene in self._scene_list: 73 for scene in self._scene_list:
77 initial_state.load_scenes(scene) 74 initial_state.load_scenes(scene)
78 initial_state.change_scene(self._initial_scene) 75 initial_state.change_scene(self._initial_scene)
79 return initial_state 76 return initial_state
77
78 def game_state(self):
79 return state.GameState()
80 80
81 def game_constants(self): 81 def game_constants(self):
82 return GameConstants() 82 return GameConstants()
83 83
84 def option_parser(self): 84 def option_parser(self):