diff options
author | Walter Bender <walter.bender@gmail.com> | 2013-02-14 03:37:13 (GMT) |
---|---|---|
committer | Walter Bender <walter.bender@gmail.com> | 2013-02-14 03:37:13 (GMT) |
commit | 30d7c6a47218763997fd092c30075096ef0cc85c (patch) | |
tree | a8c781722d95560d9f642bea9dc623e704bce120 | |
parent | e716860a9e5db7043db4b886595779e49df734f6 (diff) |
-rw-r--r-- | NEWS | 4 | ||||
-rw-r--r-- | activity/activity.info | 2 | ||||
-rw-r--r-- | game.py | 33 |
3 files changed, 32 insertions, 7 deletions
@@ -1,5 +1,9 @@ NEWS +4 + +* Add alert at end of game + 1 * New project diff --git a/activity/activity.info b/activity/activity.info index 16edc68..1ba81ec 100644 --- a/activity/activity.info +++ b/activity/activity.info @@ -1,6 +1,6 @@ [Activity] name = CookieSearch -activity_version = 1 +activity_version = 4 license = GPLv3 bundle_id = org.sugarlabs.CookieSearchActivity exec = sugar-activity SearchActivity.SearchActivity @@ -22,11 +22,10 @@ from gettext import gettext as _ import logging _logger = logging.getLogger('cookie-search-activity') -try: - from sugar.graphics import style - GRID_CELL_SIZE = style.GRID_CELL_SIZE -except ImportError: - GRID_CELL_SIZE = 0 +from sugar.graphics.alert import Alert +from sugar.graphics.icon import Icon +from sugar.graphics import style +GRID_CELL_SIZE = style.GRID_CELL_SIZE from sprites import Sprites, Sprite @@ -130,6 +129,25 @@ class Game(): dot_list.append(dot.type) return dot_list + def _new_game_alert(self): + alert = Alert() + alert.props.title = _('New game') + alert.props.msg = _('Do you want to play a new game?') + icon = Icon(icon_name='dialog-cancel') + alert.add_button(gtk.RESPONSE_CANCEL, _('Cancel'), icon) + icon.show() + ok_icon = Icon(icon_name='dialog-ok') + alert.add_button(gtk.RESPONSE_OK, _('New game'), ok_icon) + ok_icon.show() + alert.connect('response', self.__game_alert_response_cb) + self._parent.add_alert(alert) + alert.show() + + def __game_alert_response_cb(self, alert, response_id): + self._parent.remove_alert(alert) + if response_id is gtk.RESPONSE_OK: + self.new_game() + def _set_label(self, string): ''' Set the label in the toolbar or the window frame. ''' self._parent.status.set_label(string) @@ -247,14 +265,18 @@ class Game(): gobject.source_remove(self._timeout_id) def _smile(self): + self._stop_timer() for dot in self._dots: if dot.type == 0: dot.set_label('☻') + self._new_game_alert() def _frown(self): + self._stop_timer() for dot in self._dots: if dot.type == 0: dot.set_label('☹') + self._new_game_alert() def _test_game_over(self): ''' Check to see if game is over ''' @@ -265,7 +287,6 @@ class Game(): str(int(gobject.get_current_time() - self._start_time))) _logger.debug(self._parent.all_scores) self._smile() - self._stop_timer() return True def _grid_to_dot(self, pos): |