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-25 21:21:30 (GMT)
committer Walter Bender <walter@walter-laptop.(none)>2009-11-25 21:21:30 (GMT)
commitfdbd09ee5126bd49972cf4f3a65611494f15a0cc (patch)
treed7d68fd8c757f831bc62560b695adc4cf93fc01a
parentce88268277b90ed6363cbf0ed14d1b6f240ee787 (diff)
cleaning up logic
-rw-r--r--card.py20
-rw-r--r--grid.py30
-rw-r--r--images/card-28.svg64
-rw-r--r--window.py3
4 files changed, 91 insertions, 26 deletions
diff --git a/card.py b/card.py
index 120e424..7065252 100644
--- a/card.py
+++ b/card.py
@@ -33,20 +33,20 @@ from sprites import *
# pattern - game logic related
# card index is generated in the following loop:
"""
- for shape in range(1,4):
- for color in range(1,5):
- for num in range(1,4):
- for fill in range(1,4):
+ for shape in range(0,3):
+ for color in range(0,4):
+ for num in range(0,3):
+ for fill in range(0,3):
"""
#
class Card:
- def __init__(self,tw,pattern):
+ def __init__(self,tw,shape,color,num,fill):
# what do we need to know about each card?
- self.shape = pattern.shape
- self.color = pattern.color
- self.num = pattern.num
- self.fill = pattern.fill
- self.index = self.shape*4*3*3+self.color*3*3+self.num*3+self.fill
+ self.shape = shape
+ self.color = color
+ self.num = num
+ self.fill = fill
+ self.index = self.shape*4*3*3+self.color*3*3+self.num*3+self.fill+1
# create sprite from svg file
self.spr = sprNew(tw, 0, 0,\
self.load_image(tw.path+str(self.index),tw.card_w*tw.scale,
diff --git a/grid.py b/grid.py
index 95b4a99..059fcc1 100644
--- a/grid.py
+++ b/grid.py
@@ -42,19 +42,31 @@ class Grid:
# Initialize the deck of cards
# some loop through all the patterns
- for shape in range(1,4):
- for color in range(1,5):
- for num in range(1,4):
- for fill in range(1,4):
- pattern.shape = shape
- pattern.color = color
- pattern.num = num
- pattern.fill = fill
- self.deck[self.count] = Card(tw,pattern)
+ for shape in range(0,3):
+ for color in range(0,4):
+ for num in range(0,3):
+ for fill in range(0,3):
+ self.deck[self.count] = Card(tw,shape,color,num,fill)
self.count += 1
+ # shuffle the deck
self.shuffle()
+ # 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)
+ 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)
+
# shuffle the deck
def shuffle(self):
return
diff --git a/images/card-28.svg b/images/card-28.svg
index 863f4a3..02b13b0 100644
--- a/images/card-28.svg
+++ b/images/card-28.svg
@@ -1,14 +1,68 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Emacs -->
+
<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.0"
width="55"
- height="125">
- <g>
-<path d="m 33.3585,62.5035 10.102,10.1 c 0.752,0.75 1.217,1.783 1.217,2.932 0,2.287 -1.855,4.143 -4.146,4.143 -1.145,0 -2.178,-0.463 -2.932,-1.211 l -10.102,-10.103 -10.1,10.1 c -0.75,0.75 -1.787,1.211 -2.934,1.211 -2.284,0 -4.143,-1.854 -4.143,-4.141 0,-1.146 0.465,-2.184 1.212,-2.934 l 10.104,-10.102 -10.102,-10.1 c -0.747,-0.748 -1.212,-1.785 -1.212,-2.93 0,-2.289 1.854,-4.146 4.146,-4.146 1.143,0 2.18,0.465 2.93,1.214 l 10.099,10.102 10.102,-10.103 c 0.754,-0.749 1.787,-1.214 2.934,-1.214 2.289,0 4.146,1.856 4.146,4.145 0,1.146 -0.467,2.18 -1.217,2.932 l -10.104,10.105 z"
- transform="translate(0,1.5)"
- style="fill:#FFFFFF;stroke:#FF00FF;stroke-width:1.8;" />
+ height="125"
+ id="svg2"
+ inkscape:version="0.47pre4 r22446"
+ sodipodi:docname="card-28.svg">
+ <metadata
+ id="metadata12">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <defs
+ id="defs10">
+ <inkscape:perspective
+ sodipodi:type="inkscape:persp3d"
+ inkscape:vp_x="0 : 62.5 : 1"
+ inkscape:vp_y="0 : 1000 : 0"
+ inkscape:vp_z="55 : 62.5 : 1"
+ inkscape:persp3d-origin="27.5 : 41.666667 : 1"
+ id="perspective14" />
+ </defs>
+ <sodipodi:namedview
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1"
+ objecttolerance="10"
+ gridtolerance="10"
+ guidetolerance="10"
+ inkscape:pageopacity="0"
+ inkscape:pageshadow="2"
+ inkscape:window-width="640"
+ inkscape:window-height="483"
+ id="namedview8"
+ showgrid="false"
+ inkscape:zoom="1.888"
+ inkscape:cx="-37.383475"
+ inkscape:cy="62.5"
+ inkscape:window-x="0"
+ inkscape:window-y="27"
+ inkscape:window-maximized="0"
+ inkscape:current-layer="svg2" />
+ <g
+ id="g4"
+ transform="translate(25,-41.5)">
+ <path
+ d="m 33.3585,62.5035 10.102,10.1 c 0.752,0.75 1.217,1.783 1.217,2.932 0,2.287 -1.855,4.143 -4.146,4.143 -1.145,0 -2.178,-0.463 -2.932,-1.211 l -10.102,-10.103 -10.1,10.1 c -0.75,0.75 -1.787,1.211 -2.934,1.211 -2.284,0 -4.143,-1.854 -4.143,-4.141 0,-1.146 0.465,-2.184 1.212,-2.934 l 10.104,-10.102 -10.102,-10.1 c -0.747,-0.748 -1.212,-1.785 -1.212,-2.93 0,-2.289 1.854,-4.146 4.146,-4.146 1.143,0 2.18,0.465 2.93,1.214 l 10.099,10.102 10.102,-10.103 c 0.754,-0.749 1.787,-1.214 2.934,-1.214 2.289,0 4.146,1.856 4.146,4.145 0,1.146 -0.467,2.18 -1.217,2.932 l -10.104,10.105 z"
+ transform="translate(-25,41.5)"
+ style="fill:#ffffff;stroke:#ff00ff;stroke-width:1.79999995"
+ id="path6" />
</g>
</svg>
diff --git a/window.py b/window.py
index bf5f987..1e27ab1 100644
--- a/window.py
+++ b/window.py
@@ -71,7 +71,7 @@ def new_window(canvas, path, parent=None):
tw.height = gtk.gdk.screen_height()-GRID_CELL_SIZE
tw.card_w = CARD_W
tw.card_h = CARD_H
- tw.scale = 0.8 * tw.height/(tw.card_dim*3)
+ tw.scale = 0.8 * tw.height/(tw.card_h*3)
tw.area = tw.canvas.window
tw.gc = tw.area.new_gc()
tw.cm = tw.gc.get_colormap()
@@ -80,7 +80,6 @@ def new_window(canvas, path, parent=None):
# make the cards, the deck and start playing...
tw.deck = Grid(tw)
- tw.deck.shuffle(tw)
tw.deck.start(tw)
# Start doing something