Mercurial > pyntnclick
comparison pyntnclick/gamescreen.py @ 553:ebb2efcb4ea7 pyntnclick
Create a re-usable main function.
author | Simon Cross <hodgestar+bzr@gmail.com> |
---|---|
date | Sat, 11 Feb 2012 13:40:51 +0200 |
parents | 38fb04728ac5 |
children | 1b1ab71535bd |
comparison
equal
deleted
inserted
replaced
552:15713dfe555d | 553:ebb2efcb4ea7 |
---|---|
9 from pygame import Rect, mouse | 9 from pygame import Rect, mouse |
10 from pygame.color import Color | 10 from pygame.color import Color |
11 | 11 |
12 from pyntnclick.constants import SCREEN, BUTTON_SIZE, SCENE_SIZE, LEAVE | 12 from pyntnclick.constants import SCREEN, BUTTON_SIZE, SCENE_SIZE, LEAVE |
13 from pyntnclick.cursor import CursorWidget | 13 from pyntnclick.cursor import CursorWidget |
14 from pyntnclick.state import initial_state, handle_result | 14 from pyntnclick.state import handle_result |
15 from pyntnclick.widgets import ( | 15 from pyntnclick.widgets import ( |
16 MessageDialog, BoomButton, HandButton, PopupMenu, PopupMenuButton) | 16 MessageDialog, BoomButton, HandButton, PopupMenu, PopupMenuButton) |
17 | 17 |
18 | 18 |
19 class InventoryView(PaletteView): | 19 class InventoryView(PaletteView): |
199 surface.fill(self.bg_color) | 199 surface.fill(self.bg_color) |
200 Row.draw(self, surface) | 200 Row.draw(self, surface) |
201 | 201 |
202 | 202 |
203 class GameScreen(Screen, CursorWidget): | 203 class GameScreen(Screen, CursorWidget): |
204 def __init__(self, shell): | 204 def __init__(self, shell, create_initial_state): |
205 CursorWidget.__init__(self, self) | 205 CursorWidget.__init__(self, self) |
206 Screen.__init__(self, shell) | 206 Screen.__init__(self, shell) |
207 self.running = False | 207 self.running = False |
208 self.create_initial_state = create_initial_state | |
208 | 209 |
209 def _clear_all(self): | 210 def _clear_all(self): |
210 for widget in self.subwidgets[:]: | 211 for widget in self.subwidgets[:]: |
211 self.remove(widget) | 212 self.remove(widget) |
212 | 213 |
213 def start_game(self): | 214 def start_game(self): |
214 self._clear_all() | 215 self._clear_all() |
215 self.state = initial_state() | 216 self.state = self.create_initial_state() |
216 self.state_widget = StateWidget(self) | 217 self.state_widget = StateWidget(self) |
217 self.add(self.state_widget) | 218 self.add(self.state_widget) |
218 | 219 |
219 self.popup_menu = PopupMenu(self) | 220 self.popup_menu = PopupMenu(self) |
220 self.menubutton = PopupMenuButton('Menu', | 221 self.menubutton = PopupMenuButton('Menu', |