Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter 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)
commit30d7c6a47218763997fd092c30075096ef0cc85c (patch)
treea8c781722d95560d9f642bea9dc623e704bce120
parente716860a9e5db7043db4b886595779e49df734f6 (diff)
add end of game alertv4gtk2
-rw-r--r--NEWS4
-rw-r--r--activity/activity.info2
-rw-r--r--game.py33
3 files changed, 32 insertions, 7 deletions
diff --git a/NEWS b/NEWS
index 8d39d70..cbcb2b8 100644
--- a/NEWS
+++ b/NEWS
@@ -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
diff --git a/game.py b/game.py
index a903a4c..5088a20 100644
--- a/game.py
+++ b/game.py
@@ -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):