From 541a3ae6908701c5b7d3acd5e43cb4e2152c10b5 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Sun, 29 Nov 2009 15:07:37 +0000 Subject: add three cards when you get stuck --- diff --git a/NEWS b/NEWS index 1f52fd1..098430d 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,7 @@ +4 + +* add 3 cards when you get stuck + 3 * Eliminate naming alert from pre-0.86 toolbar diff --git a/VisualMatchActivity.py b/VisualMatchActivity.py index 28ab914..d7d6b16 100644 --- a/VisualMatchActivity.py +++ b/VisualMatchActivity.py @@ -68,13 +68,21 @@ class VisualMatchActivity(activity.Activity): activity_button.show() # Button 1 - self.button1 = ToolButton( "button1off" ) + self.button1 = ToolButton( "new-game" ) self.button1.set_tooltip(_('New game')) self.button1.props.sensitive = True self.button1.connect('clicked', self._button1_cb, self) toolbar_box.toolbar.insert(self.button1, -1) self.button1.show() + # Button 2 + self.button2 = ToolButton( "plus-3" ) + self.button2.set_tooltip(_('Add three extra cards')) + self.button2.props.sensitive = True + self.button2.connect('clicked', self._button2_cb, self) + toolbar_box.toolbar.insert(self.button2, -1) + self.button2.show() + separator = gtk.SeparatorToolItem() separator.show() toolbar_box.toolbar.insert(separator, -1) @@ -142,11 +150,19 @@ class VisualMatchActivity(activity.Activity): return True def show_button1(self, tw): - self.button1.set_icon("button1on") - self.metadata['status'] = "one" + self.button1.set_icon("new-game-on") tw.deck.shuffle() tw.deck.deal(tw) - # do something here + self.button1.set_icon("new-game") + + def _button2_cb(self, button, activity): + self.show_button2(activity.tw) + return True + + def show_button2(self, tw): + self.button2.set_icon("plus-3on") + tw.deck.deal_3_extra_cards(tw) + self.button2.set_icon("plus-3") def _journal_cb(self, button, path): title_alert = NamingAlert(self, path) @@ -164,8 +180,9 @@ class ProjectToolbar(gtk.Toolbar): gtk.Toolbar.__init__(self) self.activity = pc + # Button 1 - self.activity.button1 = ToolButton( "button1off" ) + self.activity.button1 = ToolButton( "new-game" ) self.activity.button1.set_tooltip(_('New game')) self.activity.button1.props.sensitive = True self.activity.button1.connect('clicked', self.activity._button1_cb, @@ -173,6 +190,15 @@ class ProjectToolbar(gtk.Toolbar): self.insert(self.activity.button1, -1) self.activity.button1.show() + # Button 1 + self.activity.button2 = ToolButton( "plus-3" ) + self.activity.button2.set_tooltip(_('Add three extra cards')) + self.activity.button2.props.sensitive = True + self.activity.button2.connect('clicked', self.activity._button2_cb, + self.activity) + self.insert(self.activity.button2, -1) + self.activity.button2.show() + # Label for showing status self.activity.results_label = gtk.Label(\ _("look for a set")) diff --git a/activity/activity.info b/activity/activity.info index 6c82646..7298b29 100644 --- a/activity/activity.info +++ b/activity/activity.info @@ -1,6 +1,6 @@ [Activity] name = Visual Match -activity_version = 3 +activity_version = 4 license = GPLv3 bundle_id = org.sugarlabs.VisualMatchActivity exec = sugar-activity VisualMatchActivity.VisualMatchActivity diff --git a/grid.py b/grid.py index 2c1653e..2338008 100644 --- a/grid.py +++ b/grid.py @@ -40,6 +40,13 @@ class Grid: self.index = 0 # how many cards are in the deck? self.count = 0 + # how many cards are on the playing field + self.cards = 12 + # card spacing + self.left = int((tw.width-(tw.card_w*5.5*tw.scale))/2) + self.xinc = int(tw.card_w*1.5*tw.scale) + self.top = int((tw.height-(tw.card_h*3*tw.scale))/2) + self.yinc = int(tw.card_h*tw.scale) # Initialize the deck of cards # some loop through all the patterns @@ -53,18 +60,30 @@ class Grid: def deal(self, tw): # layout the initial 12 cards from the deck # find upper left corner of grid - x = int((tw.width-(tw.card_w*5.5*tw.scale))/2) - y = int((tw.height-(tw.card_h*3*tw.scale))/2) + self.cards = 12 + self.grid = [] + x = self.left + y = self.top for r in range(0,3): for c in range(0,4): - # print "dealing card " + str(self.index) - self.deck[self.index].spr.x = x - self.deck[self.index].spr.y = y - self.deck[self.index].draw_card() - self.index += 1 - x += int(tw.card_w*1.5*tw.scale) - x = int((tw.width-(tw.card_w*5.5*tw.scale))/2) - y += int(tw.card_h*tw.scale) + self.draw_a_card(x,y) + self.grid.append(True) + x += self.xinc + self.grid.append(False) # leave a space for the extra cards + x = self.left + y += self.yinc + + def deal_3_extra_cards(self, tw): + # if there are still cards in the deck and only 12 cards in the grid + if self.index < self.count and self.cards == 12: + # add 3 extra cards to the playing field + self.cards = 15 + for r in range(0,3): + i = self.grid.index(False) + self.grid[i] = True + x = self.left+self.xinc*(i%5) + y = self.top+self.yinc*int(i/5) + self.draw_a_card(x,y) # shuffle the deck def shuffle(self): @@ -93,29 +112,32 @@ class Grid: return self.deck[c] return None - # remove a set from positions - def remove_a_set(self, set, tw): - for a in set: - c = self.draw_a_card() - if c is not None: - c.spr.x = a.x - c.spr.y = a.y - # self.spr_to_card(a).hide_card() - a.x = 10 - a.y = set.index(a)*int(tw.card_h*tw.scale) + \ - int((tw.height-(tw.card_h*3*tw.scale))/2) - self.spr_to_card(a).draw_card() - c.draw_card() - if c is None: - return False - else: + # remove a set from grid + # and deal new cards from the deck + def remove_and_replace(self, clicked_set, tw): + for a in clicked_set: + # only add new cards if we are down to 12 cards + if self.cards == 12: + if self.index < self.count: + self.draw_a_card(a.x,a.y) + else: + self.cards -= 1 + # mark grid positions of cards we are not replacing + i = int(5*(a.y-self.top)/self.yinc) + \ + int((a.x-self.left)/self.xinc) + self.grid[i] = False + # move clicked card to the set area + a.x = 10 + a.y = self.top + clicked_set.index(a)*self.yinc + self.spr_to_card(a).draw_card() + # Any more cards in the deck? + if self.index < self.count: return True - - def draw_a_card(self): - self.index += 1 - if self.index == self.count: - return None else: - return self.deck[self.index] - return + return False + def draw_a_card(self,x,y): + self.deck[self.index].spr.x = x + self.deck[self.index].spr.y = y + self.deck[self.index].draw_card() + self.index += 1 diff --git a/icons/new-game-on.svg b/icons/new-game-on.svg new file mode 100644 index 0000000..39cf4c9 --- /dev/null +++ b/icons/new-game-on.svg @@ -0,0 +1,14 @@ + + + + + diff --git a/icons/new-game.svg b/icons/new-game.svg new file mode 100644 index 0000000..db2434d --- /dev/null +++ b/icons/new-game.svg @@ -0,0 +1,14 @@ + + + + + diff --git a/icons/button1off.svg b/icons/plus-3-on.svg index bbc5058..2440e61 100644 --- a/icons/button1off.svg +++ b/icons/plus-3-on.svg @@ -16,7 +16,7 @@ 1 + style="font-size:32px;font-style:normal;font-weight:normal;fill:#ffffff;fill-opacity:1;font-family:Bitstream Vera Sans">+3 diff --git a/icons/button1on.svg b/icons/plus-3.svg index ebe7c37..f44fa21 100644 --- a/icons/button1on.svg +++ b/icons/plus-3.svg @@ -13,8 +13,8 @@ ry="7.0" rx="8.1" /> 1 + style="font-size:32px;font-style:normal;font-weight:normal;fill:#ffffff;fill-opacity:1;font-family:Bitstream Vera Sans">+3 diff --git a/window.py b/window.py index f7b720a..8932c9a 100644 --- a/window.py +++ b/window.py @@ -161,7 +161,7 @@ def _button_release_cb(win, event, tw): tw.activity.results_label.set_text(_("found a set")) # remove the set and # draw three new cards from the deck - if tw.deck.remove_a_set(tw.clicked, tw) is None: + if tw.deck.remove_and_replace(tw.clicked, tw) is None: tw.activity.results_label.set_text(_("deck is empty")) else: tw.activity.results_label.set_text(_("not a set")) -- cgit v0.9.1