Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Bender <walter@walter-laptop.(none)>2009-11-29 15:07:37 (GMT)
committer Walter Bender <walter@walter-laptop.(none)>2009-11-29 15:07:37 (GMT)
commit541a3ae6908701c5b7d3acd5e43cb4e2152c10b5 (patch)
tree8e8aae71ee759141e408be5e271d9e18ea1c17d2
parent7ecbf2e8aa2df23dfe154f5f729c1cb38697b8cc (diff)
add three cards when you get stuckv4
-rw-r--r--NEWS4
-rw-r--r--VisualMatchActivity.py36
-rw-r--r--activity/activity.info2
-rw-r--r--grid.py88
-rw-r--r--icons/new-game-on.svg14
-rw-r--r--icons/new-game.svg14
-rw-r--r--icons/plus-3-on.svg (renamed from icons/button1off.svg)6
-rw-r--r--icons/plus-3.svg (renamed from icons/button1on.svg)8
-rw-r--r--window.py2
9 files changed, 127 insertions, 47 deletions
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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="55px" height="55px">
+ <rect
+ style="fill:#808080;fill-opacity:1;stroke:#808080;stroke-width:4;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
+ width="51"
+ height="51"
+ x="2"
+ y="2"
+ ry="7.0"
+ rx="8.1" />
+ <path
+ style="fill:none;stroke:#ffffff;stroke-width:3;stroke-linejoin:round;stroke-miterlimit:4"
+ d="M 17,44 l 4,-13 l -11,-8 l 13,0 l 5,-13 l 4,13 l 14,0 l -11,8 l 4,13 l -11,-8 z"/>
+</svg>
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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="55px" height="55px">
+ <rect
+ style="fill:#000000;fill-opacity:1;stroke:#808080;stroke-width:4;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
+ width="51"
+ height="51"
+ x="2"
+ y="2"
+ ry="7.0"
+ rx="8.1" />
+ <path
+ style="fill:none;stroke:#ffffff;stroke-width:3;stroke-linejoin:round;stroke-miterlimit:4"
+ d="M 17,44 l 4,-13 l -11,-8 l 13,0 l 5,-13 l 4,13 l 14,0 l -11,8 l 4,13 l -11,-8 z"/>
+</svg>
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 @@
<text
x="13.5"
y="42.0"
- style="font-size:40px;font-style:normal;font-weight:normal;fill:#ffffff;fill-opacity:1;font-family:Bitstream Vera Sans"><tspan
- x="13.5"
- y="42.0">1</tspan></text>
+ style="font-size:32px;font-style:normal;font-weight:normal;fill:#ffffff;fill-opacity:1;font-family:Bitstream Vera Sans"><tspan
+ x="3"
+ y="40.0">+3</tspan></text>
</svg>
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" />
<text
- style="font-size:40px;font-style:normal;font-weight:normal;fill:#ffffff;fill-opacity:1;font-family:Bitstream Vera Sans"><tspan
- x="13.5"
- y="42.0"
- id="tspan2396">1</tspan></text>
+ style="font-size:32px;font-style:normal;font-weight:normal;fill:#ffffff;fill-opacity:1;font-family:Bitstream Vera Sans"><tspan
+ x="3"
+ y="40.0"
+ id="tspan2396">+3</tspan></text>
</svg>
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"))