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-12-10 01:43:49 (GMT)
committer Walter Bender <walter@walter-laptop.(none)>2009-12-10 01:43:49 (GMT)
commit3b4367ec2437e73ae808d2511486682fb776d323 (patch)
tree495e997560c61606ba9247e47bea458025cfc988
parent7fc47a8055ba641f581084f455499b4c7ce08e59 (diff)
cleaned up match logic for word games
-rw-r--r--NEWS1
-rw-r--r--card.py6
-rw-r--r--deck.py5
-rw-r--r--grid.py24
-rw-r--r--window.py34
5 files changed, 41 insertions, 29 deletions
diff --git a/NEWS b/NEWS
index 6d501f1..031d9d3 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,7 @@
10
* es, fr translation
+* rotated cards to enable larger/longer text strings
9
diff --git a/card.py b/card.py
index 22ff602..d5d0b13 100644
--- a/card.py
+++ b/card.py
@@ -58,11 +58,7 @@ class Card:
vmw.card_h*vmw.scale))
self.index = MATCHMASK
else:
- # include card shape only for pattern cards
- if vmw.cardtype == 'pattern':
- self.shape = shape
- else:
- self.shape = 0
+ self.shape = shape
self.color = color
self.num = num
self.fill = fill
diff --git a/deck.py b/deck.py
index 995a756..b643c4f 100644
--- a/deck.py
+++ b/deck.py
@@ -77,10 +77,11 @@ class Deck:
# deal the next card from the deck
def deal_next_card(self):
- self.index += 1
if self.empty():
return None
- return self.deck[self.index]
+ c = self.deck[self.index]
+ self.index += 1
+ return c
# is the deck empty?
def empty(self):
diff --git a/grid.py b/grid.py
index 68dca60..7676195 100644
--- a/grid.py
+++ b/grid.py
@@ -30,6 +30,9 @@ from deck import *
from constants import *
+ROW = 5
+COL = 3
+
#
# class for managing 3x5 matrix of cards
#
@@ -46,16 +49,15 @@ class Grid:
self.top = 10
self.yinc = int(vmw.card_h*1.33*vmw.scale)
- # deal the initial 12 cards
+ # deal the initial set of cards
def deal(self, vmw):
- # layout the initial 12 cards from the deck
# find upper left corner of grid
self.cards = 0
self.grid = []
x = self.left
y = self.top
- for r in range(0,4):
- for c in range(0,3):
+ for r in range(0,ROW-1):
+ for c in range(0,COL):
a = vmw.deck.deal_next_card()
self.grid.append(a)
self.place_a_card(a,x,y)
@@ -63,8 +65,8 @@ class Grid:
self.cards += 1
x = self.left
y += self.yinc
- for c in range(0,3):
- # leave a space for the extra cards
+ for c in range(0,COL):
+ # leave a blank row for extra cards
self.grid.append(None)
# add cards when there is no match
@@ -72,11 +74,11 @@ class Grid:
# if there are still cards in the deck and only 12 cards in the grid
if vmw.deck.empty() is False and self.cards == DEAL:
# add 3 extra cards to the playing field
- for r in range(0,3):
+ for c in range(0,COL):
i = self.grid.index(None)
self.grid[i] = vmw.deck.deal_next_card()
- x = self.left+self.xinc*(i%3)
- y = self.top+self.yinc*int(i/3)
+ x = self.left+self.xinc*(i%COL)
+ y = self.top+self.yinc*int(i/ROW)
self.place_a_card(self.grid[i],x,y)
self.cards += 1
@@ -91,6 +93,8 @@ class Grid:
if vmw.deck.empty():
self.grid[i] = None
else:
+ # print "new card (%d) to grid position %d" % \
+ # (vmw.deck.index,i)
# save card in grid position of card we are replacing
self.grid[i] = vmw.deck.deal_next_card()
self.place_a_card(self.grid[i],a.x,a.y)
@@ -114,4 +118,4 @@ class Grid:
# convert from sprite x,y to grid index
def xy_to_grid(self,x,y):
- return int(3*(y-self.top)/self.yinc) + int((x-self.left)/self.xinc)
+ return int(COL*(y-self.top)/self.yinc) + int((x-self.left)/self.xinc)
diff --git a/window.py b/window.py
index acc5ed3..db7e8b7 100644
--- a/window.py
+++ b/window.py
@@ -174,7 +174,8 @@ def _button_release_cb(win, event, vmw):
else:
if match_check([vmw.deck.spr_to_card(vmw.clicked[0]),
vmw.deck.spr_to_card(vmw.clicked[1]),
- vmw.deck.spr_to_card(vmw.clicked[2])]):
+ vmw.deck.spr_to_card(vmw.clicked[2])],
+ vmw.cardtype):
# stop the timer
if vmw.timeout_id is not None:
gobject.source_remove(vmw.timeout_id)
@@ -231,7 +232,6 @@ def unselect(vmw):
for a in vmw.selected:
a.hide_card()
-
#
# Keypress
#
@@ -285,7 +285,7 @@ def find_a_match(vmw):
cardarray = [vmw.grid.grid[i[0]],\
vmw.grid.grid[i[1]],\
vmw.grid.grid[i[2]]]
- if match_check(cardarray) is True:
+ if match_check(cardarray, vmw.cardtype) is True:
vmw.msg = str(i)
return True
return False
@@ -295,31 +295,41 @@ def find_a_match(vmw):
# in all characteristics:
# either all cards are the same of all cards are different
#
-def match_check(cardarray):
+def match_check(cardarray, cardtype):
for a in cardarray:
if a is None:
return False
if (cardarray[0].num + cardarray[1].num + cardarray[2].num)%3 != 0:
- return False
- if (cardarray[0].fill + cardarray[1].fill + cardarray[2].fill)%3 != 0:
- return False
- if (cardarray[0].shape + cardarray[1].shape + cardarray[2].shape)%3 != 0:
- return False
+ return False
if cardarray[0].color == cardarray[1].color and \
cardarray[1].color != cardarray[2].color:
- return False
+ return False
if cardarray[0].color != cardarray[1].color and \
cardarray[1].color != cardarray[2].color and \
cardarray[0].color == cardarray[2].color:
- return False
+ return False
if cardarray[0].color != cardarray[1].color and \
cardarray[1].color == cardarray[2].color and \
cardarray[0].color != cardarray[2].color:
- return False
+ return False
if cardarray[0].color == cardarray[1].color and \
cardarray[1].color == cardarray[2].color and \
cardarray[0].color != cardarray[2].color:
+ return False
+ # special case for the word game
+ # only check fill when numbers are the same
+ if cardtype == 'word':
+ if cardarray[0].num == cardarray[1].num and \
+ cardarray[0].num == cardarray[2].num and \
+ (cardarray[0].fill + cardarray[1].fill + cardarray[2].fill)%3 != 0:
+ return False
+ else:
+ if (cardarray[0].fill + cardarray[1].fill + cardarray[2].fill)%3 != 0:
+ return False
+ # don't check shape except in pattern game
+ if cardtype == 'pattern' and \
+ (cardarray[0].shape + cardarray[1].shape + cardarray[2].shape)%3 != 0:
return False
return True