Mercurial > sypikslang
comparison gamelib/engine.py @ 98:e386ec5d179b
The game can end
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Wed, 09 May 2012 22:03:07 +0200 |
parents | 7309392d9ca9 |
children |
comparison
equal
deleted
inserted
replaced
97:069a2d34b8b5 | 98:e386ec5d179b |
---|---|
45 @classmethod | 45 @classmethod |
46 def post(cls): | 46 def post(cls): |
47 super(PopWindow, cls).post() | 47 super(PopWindow, cls).post() |
48 | 48 |
49 | 49 |
50 class GameOver(UserEvent): | |
51 # The game is over | |
52 | |
53 TYPE = "GAME_OVER" | |
54 | |
55 @classmethod | |
56 def post(cls, window): | |
57 super(GameOver, cls).post(window=window) | |
58 | |
59 | |
50 class Engine(object): | 60 class Engine(object): |
51 | 61 |
52 def __init__(self, screen): | 62 def __init__(self, screen): |
53 self._window_stack = [] | 63 self._window_stack = [] |
54 self._running = False | 64 self._running = False |
85 self._running = False | 95 self._running = False |
86 elif AddWindow.matches(event): | 96 elif AddWindow.matches(event): |
87 self._window_stack.append(event.window) | 97 self._window_stack.append(event.window) |
88 elif PopWindow.matches(event): | 98 elif PopWindow.matches(event): |
89 self._window_stack.pop() | 99 self._window_stack.pop() |
100 elif GameOver.matches(event): | |
101 # call game_over method on every item in the stack | |
102 for win in self._window_stack: | |
103 if hasattr(win, 'game_over'): | |
104 win.game_over() | |
105 self._window_stack.append(event.window) |