Mercurial > pyntnclick
comparison gamelib/state.py @ 126:f125bb60d7de
Move result handling to result object
author | Neil Muller <neil@dip.sun.ac.za> |
---|---|
date | Tue, 24 Aug 2010 18:05:27 +0200 |
parents | d3ca34a664fd |
children | 9646e7c8bb97 |
comparison
equal
deleted
inserted
replaced
125:d3ca34a664fd | 126:f125bb60d7de |
---|---|
1 """Utilities and base classes for dealing with scenes.""" | 1 """Utilities and base classes for dealing with scenes.""" |
2 | 2 |
3 from albow.resource import get_image | 3 from albow.resource import get_image |
4 from albow.utils import frame_rect | 4 from albow.utils import frame_rect |
5 from widgets import BoomLabel | 5 from widgets import BoomLabel, MessageDialog |
6 from pygame.locals import BLEND_ADD | 6 from pygame.locals import BLEND_ADD |
7 from pygame.rect import Rect | 7 from pygame.rect import Rect |
8 from pygame.color import Color | 8 from pygame.color import Color |
9 | 9 |
10 import constants | 10 import constants |
17 def __init__(self, message=None, soundfile=None): | 17 def __init__(self, message=None, soundfile=None): |
18 self.message = message | 18 self.message = message |
19 self.sound = None | 19 self.sound = None |
20 if soundfile: | 20 if soundfile: |
21 self.sound = get_sound(soundfile) | 21 self.sound = get_sound(soundfile) |
22 | |
23 def process(self, scene): | |
24 """Helper function to do the right thing with a result object""" | |
25 if self.sound: | |
26 self.sound.play() | |
27 if self.message: | |
28 # Display the message as a modal dialog | |
29 MessageDialog(self.message, 60).present() | |
30 # queue a redraw to show updated state | |
31 scene.invalidate() | |
22 | 32 |
23 | 33 |
24 def initial_state(): | 34 def initial_state(): |
25 """Load the initial state.""" | 35 """Load the initial state.""" |
26 state = State() | 36 state = State() |