From 0080e116667bdf5a3e89a53197baa95f5cea46c6 Mon Sep 17 00:00:00 2001 From: skomoroh Date: Mon, 11 Dec 2006 22:14:41 +0000 Subject: [PATCH] + 2 new games * improved stack's shade git-svn-id: https://pysolfc.svn.sourceforge.net/svnroot/pysolfc/PySolFC/trunk@110 39dd0a4e-7c14-0410-91b3-c4f2d318f732 --- pysollib/gamedb.py | 4 +- pysollib/games/calculation.py | 64 ++++++++++++++++++++++++ pysollib/games/mahjongg/mahjongg.py | 5 +- pysollib/games/napoleon.py | 75 ++++++++++++++++++++++++++--- pysollib/images.py | 4 +- pysollib/stack.py | 56 ++++++++++----------- 6 files changed, 165 insertions(+), 43 deletions(-) diff --git a/pysollib/gamedb.py b/pysollib/gamedb.py index 6903c007..72a75d5d 100644 --- a/pysollib/gamedb.py +++ b/pysollib/gamedb.py @@ -331,8 +331,8 @@ class GI: 15420, 15421, 15422, 16000, 16001, 16002, 16003, 16004, 16666, 16667, 16668, 16669, 16670, 16671, 16672, 16673, 16674, 16675, 16676, 16677, 16678, 16679, 16680, 22216, - 22217, 22218, 22219, 22220, 22221, 22223, 22224, 22225, - 22226, 22227, 22228, 22229, 22230, 22231, 22232,)), + 22223, 22224, 22225, 22226, 22227, 22228, 22229, 22230, + 22231, 22232,)), ('fc-0.8.0', tuple(range(263, 323))), ('fc-0.9.0', tuple(range(323, 421))), ('fc-0.9.1', tuple(range(421, 441))), diff --git a/pysollib/games/calculation.py b/pysollib/games/calculation.py index f4a82c92..d656ea91 100644 --- a/pysollib/games/calculation.py +++ b/pysollib/games/calculation.py @@ -442,6 +442,68 @@ class SeniorWrangler(Game): self.s.talon.dealRow() +# /*********************************************************************** +# // S Patience +# ************************************************************************/ + +class SPatience(Game): + Hint_Class = Calculation_Hint + + def createGame(self): + l, s = Layout(self), self.s + self.setSize(l.XM+7.5*l.XS, l.YM+3.8*l.YS) + + x0, y0 = l.XM, l.YM + for xx, yy in ((4, 0.4), + (3, 0.2), + (2, 0.0), + (1, 0.2), + (0, 0.7), + (1, 1.2), + (2, 1.4), + (3, 1.6), + (4, 2.0), + (3, 2.6), + (2, 2.8), + (1, 2.6), + (0, 2.4), + ): + x, y = x0+xx*l.XS, y0+yy*l.YS + s.foundations.append(RK_FoundationStack(x, y, self, suit=ANY_SUIT, + max_cards=8, mod=13, max_move=0)) + + x, y = l.XM+5.5*l.XS, l.YM+2*l.YS + for i in (0,1): + stack = Calculation_RowStack(x, y, self, max_move=1, max_accept=1) + stack.CARD_YOFFSET = 0 + s.rows.append(stack) + l.createText(stack, 's') + x += l.XS + x, y = l.XM+5.5*l.XS, l.YM+l.YS + s.talon = WasteTalonStack(x, y, self, max_rounds=1) + l.createText(s.talon, 'nw') + x += l.XS + s.waste = WasteStack(x, y, self, max_cards=1) + + l.defaultStackGroups() + + def _shuffleHook(self, cards): + top = [] + ranks = [] + for c in cards[:]: + if c.rank not in ranks: + ranks.append(c.rank) + cards.remove(c) + top.append(c) + top.sort(lambda a, b: cmp(b.rank, a.rank)) + return cards+top[7:]+top[:7] + + def startGame(self): + self.startDealSample() + self.s.talon.dealRow(rows=self.s.foundations) + self.s.talon.dealCards() + + # register the game registerGame(GameInfo(256, Calculation, "Calculation", @@ -457,4 +519,6 @@ registerGame(GameInfo(550, One234, "One234", GI.GT_1DECK_TYPE | GI.GT_OPEN, 1, 0, GI.SL_MOSTLY_SKILL)) registerGame(GameInfo(653, SeniorWrangler, "Senior Wrangler", GI.GT_2DECK_TYPE, 2, 8, GI.SL_BALANCED)) +registerGame(GameInfo(704, SPatience, "S Patience", + GI.GT_2DECK_TYPE, 2, 0, GI.SL_BALANCED)) diff --git a/pysollib/games/mahjongg/mahjongg.py b/pysollib/games/mahjongg/mahjongg.py index 082b0cb5..bcf9f31e 100644 --- a/pysollib/games/mahjongg/mahjongg.py +++ b/pysollib/games/mahjongg/mahjongg.py @@ -268,7 +268,7 @@ class Mahjongg_RowStack(OpenStack): drag.shade_img.delete() #game.canvas.delete(drag.shade_img) drag.shade_img = None - img = game.app.images.getShadowCard(card.suit, card.rank) + img = game.app.images.getShadowCard(card.deck, card.suit, card.rank) if img is None: return 1 img = MfxCanvasImage(game.canvas, self.x, self.y, image=img, @@ -490,7 +490,8 @@ class AbstractMahjonggGame(Game): l.YM + dyy, anchor="nw", font=font) # the Talon is invisble - s.talon = InitialDealTalonStack(-l.XS, self.height - dyy, self) + s.talon = InitialDealTalonStack(-l.XS-self.canvas.xmargin, + self.height-dyy, self) # Define stack groups l.defaultStackGroups() diff --git a/pysollib/games/napoleon.py b/pysollib/games/napoleon.py index efcc59de..71d25807 100644 --- a/pysollib/games/napoleon.py +++ b/pysollib/games/napoleon.py @@ -89,6 +89,7 @@ class Napoleon_FreeCell(ReserveStack): class DerKleineNapoleon(Game): + Hint_Class = CautiousDefaultHint Foundation_Class = Braid_Foundation RowStack_Class = StackWrapper(Napoleon_RowStack, mod=13) @@ -221,17 +222,12 @@ class DerFreieNapoleon(DerKleineNapoleon): for j in range(reserves): x = x1 + j*l.XS s.rows.append(self.ReserveStack_Class(x, y, self)) - self.setRegion(s.rows, (-999, y - l.YM/2, 999999, 999999)) + self.setRegion(s.rows, (-999, y - l.CH/2, 999999, 999999)) y = l.YM x = x1+(max(cells, reserves)-cells)*l.XS/2 for i in range(cells): s.reserves.append(self.FreeCell_Class(x, y, self)) x += l.XS -## if cells == 1: -## s.reserves.append(Napoleon_SingleFreeCell(x1 + l.XS/2, y, self)) -## else: -## s.reserves.append(Napoleon_FreeCell(x1, y, self)) -## s.reserves.append(Napoleon_FreeCell(x1 + l.XS, y, self)) # foundations x = l.XM + 2*l.XS for i in range(4): @@ -346,12 +342,75 @@ class Bonaparte(TheLittleCorporal): def startGame(self): for i in range(5): - self.s.talon.dealRow(rows=self.s.rows, frames=0) + self.s.talon.dealRow(frames=0) self.startDealSample() self.s.talon.dealRow() self.s.talon.dealBaseCards(ncards=4) +# /*********************************************************************** +# // Busy Cards +# ************************************************************************/ + +class BusyCards_FreeCell(ReserveStack): + def canMoveCards(self, cards): + if not ReserveStack.canMoveCards(self, cards): + return False + rows = self.game.s.rows + index = list(self.game.s.reserves).index(self) + if rows[2*index].cards or rows[2*index+1].cards: + return False + return True + + +class BusyCards(Game): + Hint_Class = CautiousDefaultHint + + def createGame(self): + rows=12 + + l, s = Layout(self), self.s + self.setSize(l.XM+rows*l.XS, l.YM + 3*l.YS+16*l.YOFFSET) + + x, y = l.XM+(rows-8)*l.XS/2, l.YM + for i in range(4): + s.foundations.append(SS_FoundationStack(x, y, self, suit=i)) + x += l.XS + for i in range(4): + s.foundations.append(SS_FoundationStack(x, y, self, suit=i, + base_rank=KING, dir=-1)) + x += l.XS + + x, y = l.XM+l.XS/2, l.YM+l.YS + for i in range(rows/2): + s.reserves.append(BusyCards_FreeCell(x, y, self)) + x += 2*l.XS + + x, y = l.XM, l.YM+2*l.YS + for i in range(rows): + s.rows.append(UD_SS_RowStack(x, y, self)) + x += l.XS + + x, y = l.XM, self.height - l.YS + s.talon = InitialDealTalonStack(x, y, self) + + l.defaultStackGroups() + + def _shuffleHook(self, cards): + return self._shuffleHookMoveToTop(cards, + lambda c: ((c.rank in (ACE,KING) and c.deck == 0), (c.rank, c.suit))) + + def startGame(self): + self.s.talon.dealRow(rows=self.s.foundations, frames=0) + for i in range(7): + self.s.talon.dealRow(frames=0) + self.startDealSample() + self.s.talon.dealRow() + + shallHighlightMatch = Game._shallHighlightMatch_SS + + + # register the game registerGame(GameInfo(167, DerKleineNapoleon, "Der kleine Napoleon", GI.GT_NAPOLEON | GI.GT_OPEN, 1, 0, GI.SL_MOSTLY_SKILL)) @@ -367,4 +426,6 @@ registerGame(GameInfo(537, TheLittleCorporal, "The Little Corporal", GI.GT_NAPOLEON | GI.GT_OPEN, 1, 0, GI.SL_MOSTLY_SKILL)) registerGame(GameInfo(538, Bonaparte, "Bonaparte", GI.GT_NAPOLEON | GI.GT_OPEN | GI.GT_ORIGINAL, 1, 0, GI.SL_MOSTLY_SKILL)) +registerGame(GameInfo(705, BusyCards, "Busy Cards", + GI.GT_NAPOLEON | GI.GT_OPEN | GI.GT_ORIGINAL, 2, 0, GI.SL_MOSTLY_SKILL)) diff --git a/pysollib/images.py b/pysollib/images.py index a833052a..2dc352d2 100644 --- a/pysollib/images.py +++ b/pysollib/images.py @@ -294,11 +294,11 @@ class Images: def getShade(self): return self._shade[self._shade_index] - def getShadowCard(self, suit, rank): + def getShadowCard(self, deck, suit, rank): if self._shadow_cards.has_key((suit, rank)): shade = self._shadow_cards[(suit, rank)] else: - image = self.getFace(0, suit, rank) + image = self.getFace(deck, suit, rank) shade = shadowImage(image) self._shadow_cards[(suit, rank)] = shade if not shade: diff --git a/pysollib/stack.py b/pysollib/stack.py index afaab54d..ab964d4c 100644 --- a/pysollib/stack.py +++ b/pysollib/stack.py @@ -1193,13 +1193,6 @@ class Stack: # optimized for speed - we use lots of local variables game = self.game images = game.app.images - if not self.images.shade_img: - img = images.getShade() - self.images.shade_img = img - else: - img = self.images.shade_img - if img is None: - return CW, CH = images.CARDW, images.CARDH drag = game.drag ##stacks = game.allstacks @@ -1233,23 +1226,28 @@ class Stack: if sstack is None: self._deleteShade() return - # move or create the shade image - drag.shade_stack = sstack if drag.shade_img: - drag.shade_img.moveTo(sx, sy) + self._deleteShade() + # create the shade image + drag.shade_stack = sstack + if sstack.cards: + card = sstack.cards[-1] + img = images.getShadowCard(card.deck, card.suit, card.rank) else: - img = MfxCanvasImage(game.canvas, sx, sy, - image=img, anchor=ANCHOR_NW) - drag.shade_img = img - # raise/lower the shade image to the correct stacking order - if TOOLKIT == 'tk': - if drag.shadows: - img.lower(drag.shadows[0]) - else: - img.lower(drag.cards[0].item) - elif TOOLKIT == 'gtk': - img.tkraise() - drag.stack.group.tkraise() + img = images.getShade() + if not img: + return + img = MfxCanvasImage(game.canvas, sx, sy, image=img, anchor=ANCHOR_NW) + drag.shade_img = img + # raise/lower the shade image to the correct stacking order + if TOOLKIT == 'tk': + if drag.shadows: + img.lower(drag.shadows[0]) + else: + img.lower(drag.cards[0].item) + elif TOOLKIT == 'gtk': + img.tkraise() + drag.stack.group.tkraise() # for closeStack @@ -1260,16 +1258,14 @@ class Stack: ## self.CARD_YOFFSET != (0,)): ## return card = self.cards[-1] - img = self.game.app.images.getShadowCard(card.suit, card.rank) + img = self.game.app.images.getShadowCard(card.deck, card.suit, card.rank) if img is None: return - if 1: ##not self.items.shade_item: - #self.game.canvas.update_idletasks() - item = MfxCanvasImage(self.game.canvas, card.x, card.y, - image=img, anchor=ANCHOR_NW, - group=self.group) - #item.tkraise() - self.items.shade_item = item + #self.game.canvas.update_idletasks() + item = MfxCanvasImage(self.game.canvas, card.x, card.y, + image=img, anchor=ANCHOR_NW, group=self.group) + #item.tkraise() + self.items.shade_item = item def _unshadeStack(self): if self.items.shade_item: