diff options
author | Laurent Bernabé <laurent.bernabe@gmail.com> | 2013-09-27 06:56:27 (GMT) |
---|---|---|
committer | Laurent Bernabé <laurent.bernabe@gmail.com> | 2013-09-27 06:56:27 (GMT) |
commit | bdc86499c79bd490425bd743847c1c6cc35b3f4a (patch) | |
tree | baf695cb272a25c8463249d3fc301b763105eb12 | |
parent | d5030c557d78a3a9b9f6477619ad87e03e6496b2 (diff) |
Fixed a bug with the activity version : I came to call pygame.init() twice, one directly and one indirectly.
-rw-r--r-- | main_game.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/main_game.py b/main_game.py index 7ea2b1e..eb6296c 100644 --- a/main_game.py +++ b/main_game.py @@ -31,6 +31,15 @@ class Game: """ Constructor. """ + self._initialized = False + + def _lazy_init(self): + """ + Lazy initialization : main code is only called once, thanks to + an internal flag. + """ + if self._initialized: + return pygame.init() self._LEFT_BUTTON = 1 self._FPS = 40 @@ -95,6 +104,7 @@ class Game: self._MENU_LEVELS_RECTS_WIDTH, self._MENU_LEVELS_RECTS_HEIGHT) for y in range(len(self._levels))] + self._initialized = True def _get_result_at_pos(self, point, balls_list): """ @@ -230,6 +240,7 @@ class Game: """ Manages the main menu. """ + self._lazy_init() while True: self._screen.fill(self._MENU_BACKGROUND) for box_index in range(len(self._levels)): |