From 02ea6c8454ece61c84a3235112015f6c66b7dd0a Mon Sep 17 00:00:00 2001 From: skomoroh Date: Sat, 22 Jul 2006 21:28:30 +0000 Subject: [PATCH] + 2 new games * bug fixes git-svn-id: https://pysolfc.svn.sourceforge.net/svnroot/pysolfc/PySolFC/trunk@24 39dd0a4e-7c14-0410-91b3-c4f2d318f732 --- pysollib/game.py | 9 ++- pysollib/games/canfield.py | 24 +++++-- pysollib/games/glenwood.py | 3 +- pysollib/games/harp.py | 3 +- pysollib/games/picturegallery.py | 111 +++++++++++++++++++++++++++++++ 5 files changed, 140 insertions(+), 10 deletions(-) diff --git a/pysollib/game.py b/pysollib/game.py index e17e3660..52d47bd8 100644 --- a/pysollib/game.py +++ b/pysollib/game.py @@ -1436,8 +1436,9 @@ for %d moves. # color = self.app.opt.highlight_not_matching_color width = 6 - r = MfxCanvasRectangle(self.canvas, x+width/2, y+width/2, - x+w-width/2, y+h-width/2, + x0, y0 = x+width/2-self.canvas.xmargin, y+width/2-self.canvas.ymargin + x1, y1 = x+w-width/2-self.canvas.xmargin, y+h-width/2-self.canvas.ymargin + r = MfxCanvasRectangle(self.canvas, x0, y0, x1, y1, width=width, fill=None, outline=color) self.canvas.update_idletasks() self.sleep(self.app.opt.highlight_cards_sleep) @@ -1660,16 +1661,18 @@ for %d moves. image=self.app.gimages.logos[4], strings=(s,), separatorwidth=2, timeout=timeout) status = d.status + self.finished = True else: ##s = self.app.miscrandom.choice((_("&OK"), _("&OK"))) s = _("&OK") text = _("\nGame finished\n") if self.app.debug: - text = text + "\n%d %d\n" % (self.stats.player_moves, self.stats.demo_moves) + text += "\nplayer_moves: %d\ndemo_moves: %d\n" % (self.stats.player_moves, self.stats.demo_moves) d = MfxMessageDialog(self.top, title=PACKAGE+_(" Autopilot"), text=text, bitmap=bitmap, strings=(s,), padx=30, timeout=timeout) status = d.status + self.finished = True elif finished: ##self.stopPlayTimer() if not self.top.winfo_ismapped(): diff --git a/pysollib/games/canfield.py b/pysollib/games/canfield.py index 0f4673bb..f1f4b1f9 100644 --- a/pysollib/games/canfield.py +++ b/pysollib/games/canfield.py @@ -650,33 +650,47 @@ class Acme(Canfield): # ************************************************************************/ class Duke(Game): + Foundation_Class = SS_FoundationStack + ReserveStack_Class = OpenStack + RowStack_Class = AC_RowStack - def createGame(self): + def createGame(self, max_rounds=3, texts=False): l, s = Layout(self), self.s w, h = l.XM+6*l.XS+4*l.XOFFSET, l.YM+2*l.YS+12*l.YOFFSET + if texts: + h += l.TEXT_HEIGHT self.setSize(w, h) + self.base_card = None + x, y = l.XM, l.YM - s.talon = WasteTalonStack(x, y, self, max_rounds=3) + s.talon = WasteTalonStack(x, y, self, max_rounds=max_rounds) l.createText(s.talon, 's') x += l.XS s.waste = WasteStack(x, y, self) l.createText(s.waste, 's') x += l.XS+4*l.XOFFSET for i in range(4): - s.foundations.append(SS_FoundationStack(x, y, self, suit=i)) + s.foundations.append(self.Foundation_Class(x, y, self, suit=i)) x += l.XS x0, y0, w = l.XM, l.YM+l.YS+l.TEXT_HEIGHT, l.XS+2*l.XOFFSET for i, j in ((0,0), (0,1), (1,0), (1,1)): x, y = x0+i*w, y0+j*l.YS - stack = OpenStack(x, y, self, max_accept=0) + stack = self.ReserveStack_Class(x, y, self, max_accept=0) stack.CARD_XOFFSET, stack.CARD_YOFFSET = l.XOFFSET, 0 s.reserves.append(stack) x, y = l.XM+2*l.XS+4*l.XOFFSET, l.YM+l.YS + if texts: + y += l.TEXT_HEIGHT for i in range(4): - s.rows.append(AC_RowStack(x, y, self)) + s.rows.append(self.RowStack_Class(x, y, self)) x += l.XS + if texts: + tx, ty, ta, tf = l.getTextAttr(s.foundations[-1], "ss") + font = self.app.getFont("canvas_default") + self.texts.info = MfxCanvasText(self.canvas, tx, ty, + anchor=ta, font=font) l.defaultStackGroups() diff --git a/pysollib/games/glenwood.py b/pysollib/games/glenwood.py index f86b0a04..9fad3717 100644 --- a/pysollib/games/glenwood.py +++ b/pysollib/games/glenwood.py @@ -183,5 +183,6 @@ class Glenwood(Game): # register the game registerGame(GameInfo(282, Glenwood, "Glenwood", - GI.GT_CANFIELD, 1, 1, GI.SL_BALANCED)) + GI.GT_CANFIELD, 1, 1, GI.SL_BALANCED, + altnames=("Duchess",) )) diff --git a/pysollib/games/harp.py b/pysollib/games/harp.py index cc4f6018..7562ba56 100644 --- a/pysollib/games/harp.py +++ b/pysollib/games/harp.py @@ -244,7 +244,8 @@ class BigDeal(DoubleKlondike): s.waste = WasteStack(x, y, self) l.createText(s.waste, 'n') if max_rounds > 1: - tx, ty, ta, tf = l.getTextAttr(s.waste, 'se') + tx, ty, ta, tf = l.getTextAttr(s.talon, 'nn') + ty -= 2*l.TEXT_MARGIN font = self.app.getFont('canvas_default') s.talon.texts.rounds = MfxCanvasText(self.canvas, tx, ty, anchor=ta, font=font) self.setRegion(s.rows, (-999, -999, l.XM+rows*l.XS-l.CW/2, 999999), priority=1) diff --git a/pysollib/games/picturegallery.py b/pysollib/games/picturegallery.py index a4e0b07d..f2bf98c6 100644 --- a/pysollib/games/picturegallery.py +++ b/pysollib/games/picturegallery.py @@ -108,6 +108,8 @@ class PictureGallery_Hint(AbstractHint): if not self.hints: for r in game.s.rows: pile = r.getPile() + if not pile: + continue lp = len(pile) lr = len(r.cards) assert 1 <= lp <= lr @@ -452,6 +454,110 @@ class Zeus(MountOlympus): self.s.talon.dealRow() +# /*********************************************************************** +# // Royal Parade +# ************************************************************************/ + + +class RoyalParade_TableauStack(PictureGallery_TableauStack): + + def _canSwapPair(self, from_stack): + if from_stack not in self.game.s.tableaux: + return False + if len(self.cards) != 1 or len(from_stack.cards) != 1: + return False + c0, c1 = from_stack.cards[0], self.cards[0] + return (c0.rank == self.cap.base_rank and + c1.rank == from_stack.cap.base_rank) + + def acceptsCards(self, from_stack, cards): + if self._canSwapPair(from_stack): + return True + return PictureGallery_TableauStack.acceptsCards(self, from_stack, cards) + + def moveMove(self, ncards, to_stack, frames=-1, shadow=-1): + if self._canSwapPair(to_stack): + self._swapPairMove(ncards, to_stack, frames=-1, shadow=0) + else: + PictureGallery_TableauStack.moveMove(self, ncards, to_stack, + frames=frames, shadow=shadow) + + def _swapPairMove(self, n, other_stack, frames=-1, shadow=-1): + game = self.game + old_state = game.enterState(game.S_FILL) + swap = game.s.internals[0] + game.moveMove(n, self, swap, frames=0) + game.moveMove(n, other_stack, self, frames=frames, shadow=shadow) + game.moveMove(n, swap, other_stack, frames=0) + game.leaveState(old_state) + + +class RoyalParade(PictureGallery): + Talon_Class = DealRowTalonStack + TableauStack_Classes = [ + StackWrapper(RoyalParade_TableauStack, + base_rank=1, max_cards=4, dir=3), + StackWrapper(RoyalParade_TableauStack, + base_rank=2, max_cards=4, dir=3), + StackWrapper(RoyalParade_TableauStack, + base_rank=3, max_cards=4, dir=3), + ] + RowStack_Class = StackWrapper(BasicRowStack, max_accept=0) + + def createGame(self): + PictureGallery.createGame(self) + self.s.internals.append(InvisibleStack(self)) + + def startGame(self): + self.startDealSample() + self.s.talon.dealRow(rows=self.s.tableaux) + self.s.talon.dealRow() + + +# /*********************************************************************** +# // Virginia Reel +# ************************************************************************/ + +class VirginiaReel_Talon(DealRowTalonStack): + + def canDealCards(self): + if not DealRowTalonStack.canDealCards(self): + return False + for s in self.game.s.tableaux: + if not s.cards: + return False + return True + + +class VirginiaReel(RoyalParade): + Talon_Class = VirginiaReel_Talon + + def _shuffleHook(self, cards): + bottom_cards = [] + ranks = [] + for c in cards[:]: + if c.rank in (1,2,3) and c.rank not in ranks: + ranks.append(c.rank) + cards.remove(c) + bottom_cards.append(c) + if len(ranks) == 3: + break + bottom_cards.sort(lambda a, b: cmp(b.rank, a.rank)) + return cards+bottom_cards + + def startGame(self): + self.s.talon.dealRow(rows=self.s.tableaux[0::8], frames=0) + self.startDealSample() + for i in range(3): + rows = self.s.tableaux[i*8+1:i*8+8] + self.s.talon.dealRow(rows=rows) + self.s.talon.dealRow() + + def fillStack(self, stack): + pass + + + # register the game registerGame(GameInfo(7, PictureGallery, "Picture Gallery", GI.GT_2DECK_TYPE, 2, 0, GI.SL_BALANCED, @@ -464,4 +570,9 @@ registerGame(GameInfo(398, MountOlympus, "Mount Olympus", GI.GT_2DECK_TYPE, 2, 0, GI.SL_BALANCED)) registerGame(GameInfo(399, Zeus, "Zeus", GI.GT_2DECK_TYPE, 2, 0, GI.SL_BALANCED)) +registerGame(GameInfo(546, RoyalParade, "Royal Parade", + GI.GT_2DECK_TYPE, 2, 0, GI.SL_MOSTLY_SKILL)) +registerGame(GameInfo(547, VirginiaReel, "Virginia Reel", + GI.GT_2DECK_TYPE, 2, 0, GI.SL_MOSTLY_SKILL)) +