Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/grid.py
diff options
context:
space:
mode:
Diffstat (limited to 'grid.py')
-rw-r--r--grid.py88
1 files changed, 55 insertions, 33 deletions
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