Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/grid.py
diff options
context:
space:
mode:
authorWalter Bender <walter@walter-laptop.(none)>2009-12-25 16:13:40 (GMT)
committer Walter Bender <walter@walter-laptop.(none)>2009-12-25 16:13:40 (GMT)
commitac36c9f307ad0b518c72df756ca30bee1a198db9 (patch)
treeafecd949ea3da7e6f02af9dc56a30faba890ed0d /grid.py
parent8587c746c6add025584cbf5fb2eca874b9525860 (diff)
consolidate grid after extra cards are dealt
Diffstat (limited to 'grid.py')
-rw-r--r--grid.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/grid.py b/grid.py
index f6eafe8..7b4e096 100644
--- a/grid.py
+++ b/grid.py
@@ -104,6 +104,18 @@ class Grid:
a.y = self.top + clicked_set.index(a)*self.yinc
deck.spr_to_card(a).show_card()
+ # if we have removed cards from a grid of 15, we may need to consolidate
+ def consolidate(self):
+ for j in range(12,15):
+ i = 0
+ while(self.grid[j] is not None):
+ if self.grid[i] is None:
+ self.grid[i] = self.grid[j]
+ self.grid[i].spr.move(self.grid_to_xy(i))
+ self.grid[j] = None
+ else:
+ i+=1
+
# place a card at position x,y and display it
def place_a_card(self, c, x, y):
if c is not None:
@@ -115,6 +127,9 @@ class Grid:
def xy_to_grid(self, x, y):
return int(COL*(y-self.top)/self.yinc) + int((x-self.left)/self.xinc)
+ # convert from grid index to sprite x,y
+ def grid_to_xy(self, i):
+ return ((self.left+i%COL*self.xinc),(self.top+(i/COL)*self.yinc))
# return sprite in grid element i
def grid_to_spr(self, i):