Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@member.fsf.org>2009-01-24 17:07:56 (GMT)
committer Aleksey Lim <alsroot@member.fsf.org>2009-01-24 17:07:56 (GMT)
commite8035ee7f48afd893216b63a4bd3931ba65bd612 (patch)
tree9d1166b2e9d127f86c7fe6dbc789ca6a56241ae4
parent64c9869b5d6c79e9445836bccd4f8ff9c71f6f5f (diff)
click breaks wrong-pair-timeout
-rw-r--r--activity.py1
-rw-r--r--cardtable.py7
-rw-r--r--game.py19
-rw-r--r--theme.py1
4 files changed, 24 insertions, 4 deletions
diff --git a/activity.py b/activity.py
index 55a8294..eb0abd7 100644
--- a/activity.py
+++ b/activity.py
@@ -88,6 +88,7 @@ class MemorizeActivity(Activity):
self.table.connect('key-press-event', self.table.key_press_event)
self.table.connect('card-flipped', self.game.card_flipped)
+ self.table.connect('card-overflipped', self.game.card_overflipped)
self.table.connect('card-highlighted', self.game.card_highlighted)
self.game.connect('set-border', self.table.set_border)
diff --git a/cardtable.py b/cardtable.py
index eeb4772..608d8c5 100644
--- a/cardtable.py
+++ b/cardtable.py
@@ -31,6 +31,7 @@ class CardTable(gtk.EventBox):
__gsignals__ = {
'card-flipped': (SIGNAL_RUN_FIRST, None, [int, TYPE_PYOBJECT]),
+ 'card-overflipped': (SIGNAL_RUN_FIRST, None, [int]),
'card-highlighted': (SIGNAL_RUN_FIRST, None, [int, TYPE_PYOBJECT]),
}
@@ -201,8 +202,10 @@ class CardTable(gtk.EventBox):
self.card_flipped(card)
def card_flipped(self, card):
- if not card.is_flipped():
- id = self.cd2id[card]
+ id = self.cd2id[card]
+ if card.is_flipped():
+ self.emit('card-overflipped', id)
+ else:
self.emit('card-flipped', id, False)
def set_border(self, widget, id, stroke_color, fill_color):
diff --git a/game.py b/game.py
index 816ec08..cc70f6f 100644
--- a/game.py
+++ b/game.py
@@ -24,8 +24,10 @@ from sugar import profile
from dbus.service import method, signal
from dbus.gobject_service import ExportedGObject
from gobject import SIGNAL_RUN_FIRST, TYPE_PYOBJECT, GObject, timeout_add
+from gobject import source_remove
from model import Model
+import theme
_logger = logging.getLogger('memorize-activity')
@@ -70,6 +72,7 @@ class MemorizeGame(GObject):
self.sentitive = True
self.model = Model(dirname(__file__))
self.flip_block = False
+ self._flop_cards = None
# create csound instance to play sound files
self.sound = 0
@@ -177,8 +180,15 @@ class MemorizeGame(GObject):
else:
self.cs.perform('i 100 0.0 3.0 "%s" 1 0.9 0'%(sound_file))
+ def card_overflipped(self, widget, id):
+ if self._flop_cards and id in self._flop_cards:
+ self.card_flipped(widget, id)
+
def card_flipped(self, widget, id, signal = False):
-
+ if self._flop_cards:
+ source_remove(self._flop_card_timeout)
+ self.flop_card(self._flop_cards[0], self._flop_cards[1])
+
# Check if is my turn
if (not self.sentitive and not signal) or self.last_flipped == id:
return
@@ -234,10 +244,15 @@ class MemorizeGame(GObject):
else:
self.model.grid[id]['state'] = '1'
self.set_sensitive(False)
- timeout_add(2000, self.flop_card, id, self.last_flipped)
+ self._flop_cards = (id, self.last_flipped)
+ self._flop_card_timeout = timeout_add(theme.FLOP_BACK_TIMEOUT,
+ self.flop_card, id, self.last_flipped)
self.last_flipped = -1
def flop_card(self, id, id2):
+ self._flop_card_timeout = -1
+ self._flop_cards = None
+
self.emit('flop-card', id)
self.model.grid[id]['state'] = '0'
self.emit('flop-card', id2)
diff --git a/theme.py b/theme.py
index eae4a53..4f1cfc0 100644
--- a/theme.py
+++ b/theme.py
@@ -25,3 +25,4 @@ BODY_WIDTH = 45
BODY_HEIGHT = 55
STARS_COLS = 6
SCORE_SIZE = 30
+FLOP_BACK_TIMEOUT = 2000