1
0
Fork 0
mirror of https://github.com/shlomif/PySolFC.git synced 2025-04-05 00:02:29 -04:00

Added Accordion's Revenge game.

This commit is contained in:
Joe R 2021-07-17 09:39:57 -04:00
parent 1a446862bd
commit d9c98ae017
6 changed files with 113 additions and 10 deletions

View file

@ -0,0 +1,20 @@
<h1>Accordion's Revenge</h1>
<p>
One deck type. 1 deck. No redeal.
<h3>Object</h3>
<p>
Remove all the cards except the one card declared at the start.
<h3>Quick Description</h3>
<p>
Like <a href="accordion.html">Accordion</a>,
but at the start of the game, a single card is randomly declared.
This card must be the last remaining card in order to win the game.
<h3>Notes</h3>
<p>
Accordion's Revenge is unwinnable if the first or second card is
declared. As such, PySol will reselect the declared card if it
is chosen.

View file

@ -405,7 +405,8 @@ class GI:
('fc-2.1', tuple(range(767, 774))), ('fc-2.1', tuple(range(767, 774))),
('fc-2.8', (343001,)), ('fc-2.8', (343001,)),
('fc-2.12', tuple(range(774, 811)) + (16681,) + ('fc-2.12', tuple(range(774, 811)) + (16681,) +
tuple(range(22217, 22219))) tuple(range(22217, 22219))),
('fc-2.14', tuple(range(811, 812)))
) )
# deprecated - the correct way is to or a GI.GT_XXX flag # deprecated - the correct way is to or a GI.GT_XXX flag

View file

@ -25,12 +25,13 @@ from pysollib.game import Game
from pysollib.gamedb import GI, GameInfo, registerGame from pysollib.gamedb import GI, GameInfo, registerGame
from pysollib.hint import AbstractHint from pysollib.hint import AbstractHint
from pysollib.layout import Layout from pysollib.layout import Layout
from pysollib.pysoltk import MfxCanvasText
from pysollib.stack import \ from pysollib.stack import \
AbstractFoundationStack, \ AbstractFoundationStack, \
DealRowTalonStack, \ DealRowTalonStack, \
ReserveStack, \ ReserveStack, \
Stack Stack
from pysollib.util import ANY_RANK, ANY_SUIT from pysollib.util import ANY_RANK, ANY_SUIT, RANKS, SUITS_PL
class PushPin_Hint(AbstractHint): class PushPin_Hint(AbstractHint):
@ -125,6 +126,8 @@ class PushPin(Game):
Hint_Class = PushPin_Hint Hint_Class = PushPin_Hint
RowStack_Class = PushPin_RowStack RowStack_Class = PushPin_RowStack
Comment = False
# #
# game layout # game layout
# #
@ -133,9 +136,13 @@ class PushPin(Game):
# create layout # create layout
l, s = Layout(self), self.s l, s = Layout(self), self.s
pad = 1
if self.Comment:
pad = 5
# set window # set window
xx, yy = 9, 6 xx, yy = 9, 6
w, h = l.XM+xx*l.XS, l.YM+yy*l.YS w, h = l.XM + xx * l.XS, (l.YM * pad) + yy * l.YS
self.setSize(w, h) self.setSize(w, h)
# create stacks # create stacks
@ -149,9 +156,13 @@ class PushPin(Game):
k = j k = j
if i % 2: if i % 2:
k = xx-j-1 k = xx-j-1
x, y = l.XM + k*l.XS, l.YM + i*l.YS x, y = l.XM + k*l.XS, (l.YM * pad) + i * l.YS
s.rows.append(self.RowStack_Class(x, y, self)) s.rows.append(self.RowStack_Class(x, y, self))
s.talon = PushPin_Talon(l.XM, l.YM, self) s.talon = PushPin_Talon(l.XM, l.YM * pad, self)
if self.Comment:
self.texts.base_rank = \
MfxCanvasText(self.canvas, l.XM, l.YM, anchor="nw",
font=self.app.getFont("canvas_default"))
s.foundations.append(PushPin_Foundation(l.XM, h-l.YS, self, s.foundations.append(PushPin_Foundation(l.XM, h-l.YS, self,
suit=ANY_SUIT, dir=0, base_rank=ANY_RANK, suit=ANY_SUIT, dir=0, base_rank=ANY_RANK,
max_accept=0, max_move=0, max_cards=52)) max_accept=0, max_move=0, max_cards=52))
@ -162,7 +173,11 @@ class PushPin(Game):
def startGame(self): def startGame(self):
self.startDealSample() self.startDealSample()
self.s.talon.dealRow(rows=self.s.rows[:3]) if self.app.opt.accordion_deal_all:
self.s.talon.dealRow(rows=self.s.rows[:47], frames=0)
self.s.talon.dealRow(rows=self.s.rows[47:52])
else:
self.s.talon.dealRow(rows=self.s.rows[:3])
def isGameWon(self): def isGameWon(self):
return len(self.s.foundations[0].cards) == 50 return len(self.s.foundations[0].cards) == 50
@ -270,10 +285,6 @@ class Accordion(PushPin):
Hint_Class = Accordion_Hint Hint_Class = Accordion_Hint
RowStack_Class = Accordion_RowStack RowStack_Class = Accordion_RowStack
def startGame(self):
self.startDealSample()
self.s.talon.dealRow(rows=self.s.rows[:2])
def isGameWon(self): def isGameWon(self):
return len(self.s.foundations[0].cards) == 52 return len(self.s.foundations[0].cards) == 52
@ -321,6 +332,60 @@ class RelaxedAccordion_RowStack(Accordion2_RowStack):
class RelaxedAccordion(Accordion2): class RelaxedAccordion(Accordion2):
RowStack_Class = RelaxedAccordion_RowStack RowStack_Class = RelaxedAccordion_RowStack
# ************************************************************************
# * Accordion's Revenge
# ************************************************************************
class AccordionsRevenge(Accordion2):
Comment = True
def createGame(self):
self.finalrank = -1
self.finalsuit = -1
Accordion2.createGame(self)
def startGame(self):
self.finalrank = -1
self.finalsuit = -1
self.updateText()
Accordion2.startGame(self)
while (self.finalrank == -1 or self.finalsuit == -1 or
(self.finalrank == self.s.rows[0].cards[0].rank and
self.finalsuit == self.s.rows[0].cards[0].suit) or
(self.finalrank == self.s.rows[1].cards[0].rank and
self.finalsuit == self.s.rows[1].cards[0].suit)):
self.finalsuit = self.random.choice(self.gameinfo.suits)
self.finalrank = self.random.choice(self.gameinfo.ranks)
def isGameWon(self):
return (len(self.s.foundations[0].cards) == 51 and
self.s.rows[0].cards[0].rank == self.finalrank and
self.s.rows[0].cards[0].suit == self.finalsuit)
def _restoreGameHook(self, game):
self.finalrank = game.loadinfo.dval.get('Rank')
self.finalsuit = game.loadinfo.dval.get('Suit')
def _loadGameHook(self, p):
self.loadinfo.addattr(dval=p.load())
def _saveGameHook(self, p):
dval = {'Rank': self.finalrank, 'Suit': self.finalsuit}
p.dump(dval)
def updateText(self):
if self.preview > 1:
return
if self.finalrank == -1 and self.finalsuit == -1:
self.texts.base_rank.config('')
else:
self.texts.base_rank.config(text=RANKS[self.finalrank]
+ ' - ' + SUITS_PL[self.finalsuit])
registerGame(GameInfo(287, PushPin, "Push Pin", registerGame(GameInfo(287, PushPin, "Push Pin",
GI.GT_1DECK_TYPE, 1, 0, GI.SL_MOSTLY_LUCK)) GI.GT_1DECK_TYPE, 1, 0, GI.SL_MOSTLY_LUCK))
@ -335,3 +400,5 @@ registerGame(GameInfo(772, Accordion2, "Accordion",
altnames=('Idle Year', 'Methuselah', 'Tower of Babel'))) altnames=('Idle Year', 'Methuselah', 'Tower of Babel')))
registerGame(GameInfo(773, RelaxedAccordion, "Relaxed Accordion", registerGame(GameInfo(773, RelaxedAccordion, "Relaxed Accordion",
GI.GT_1DECK_TYPE | GI.GT_RELAXED, 1, 0, GI.SL_BALANCED)) GI.GT_1DECK_TYPE | GI.GT_RELAXED, 1, 0, GI.SL_BALANCED))
registerGame(GameInfo(811, AccordionsRevenge, "Accordion's Revenge",
GI.GT_1DECK_TYPE | GI.GT_RELAXED, 1, 0, GI.SL_BALANCED))

View file

@ -226,6 +226,7 @@ class Options:
('mahjongg_create_solvable', 'int'), ('mahjongg_create_solvable', 'int'),
('shisen_show_hint', 'bool'), ('shisen_show_hint', 'bool'),
('shisen_show_matching', 'bool'), ('shisen_show_matching', 'bool'),
('accordion_deal_all', 'bool'),
('animations', 'int'), ('animations', 'int'),
('redeal_animation', 'bool'), ('redeal_animation', 'bool'),
('win_animation', 'bool'), ('win_animation', 'bool'),
@ -308,6 +309,7 @@ class Options:
self.highlight_not_matching = True self.highlight_not_matching = True
self.mahjongg_show_removed = False self.mahjongg_show_removed = False
self.mahjongg_create_solvable = 2 # 0 - none, 1 - easy, 2 - hard self.mahjongg_create_solvable = 2 # 0 - none, 1 - easy, 2 - hard
self.accordion_deal_all = True
if TOOLKIT == 'kivy': if TOOLKIT == 'kivy':
self.mahjongg_create_solvable = 1 # 0 - none, 1 - easy, 2 - hard self.mahjongg_create_solvable = 1 # 0 - none, 1 - easy, 2 - hard
self.shisen_show_hint = True self.shisen_show_hint = True

View file

@ -169,6 +169,7 @@ class PysolMenubarTkCommon:
highlight_not_matching=tkinter.BooleanVar(), highlight_not_matching=tkinter.BooleanVar(),
mahjongg_show_removed=tkinter.BooleanVar(), mahjongg_show_removed=tkinter.BooleanVar(),
shisen_show_hint=tkinter.BooleanVar(), shisen_show_hint=tkinter.BooleanVar(),
accordion_deal_all=tkinter.BooleanVar(),
sound=tkinter.BooleanVar(), sound=tkinter.BooleanVar(),
auto_scale=tkinter.BooleanVar(), auto_scale=tkinter.BooleanVar(),
spread_stacks=tkinter.BooleanVar(), spread_stacks=tkinter.BooleanVar(),
@ -222,6 +223,7 @@ class PysolMenubarTkCommon:
tkopt.shade_filled_stacks.set(opt.shade_filled_stacks) tkopt.shade_filled_stacks.set(opt.shade_filled_stacks)
tkopt.mahjongg_show_removed.set(opt.mahjongg_show_removed) tkopt.mahjongg_show_removed.set(opt.mahjongg_show_removed)
tkopt.shisen_show_hint.set(opt.shisen_show_hint) tkopt.shisen_show_hint.set(opt.shisen_show_hint)
tkopt.accordion_deal_all.set(opt.accordion_deal_all)
tkopt.sound.set(opt.sound) tkopt.sound.set(opt.sound)
tkopt.auto_scale.set(opt.auto_scale) tkopt.auto_scale.set(opt.auto_scale)
tkopt.spread_stacks.set(opt.spread_stacks) tkopt.spread_stacks.set(opt.spread_stacks)
@ -516,6 +518,10 @@ class PysolMenubarTkCommon:
label=n_("Show hint &arrow (in Shisen-Sho games)"), label=n_("Show hint &arrow (in Shisen-Sho games)"),
variable=self.tkopt.shisen_show_hint, variable=self.tkopt.shisen_show_hint,
command=self.mOptShisenShowHint) command=self.mOptShisenShowHint)
submenu.add_checkbutton(
label=n_("Deal all cards (in Accordion type games)"),
variable=self.tkopt.accordion_deal_all,
command=self.mOptAccordionDealAll)
menu.add_separator() menu.add_separator()
label = n_("&Sound...") label = n_("&Sound...")
menu.add_command( menu.add_command(
@ -1429,6 +1435,12 @@ Unsupported game for import.
self.app.opt.shisen_show_hint = self.tkopt.shisen_show_hint.get() self.app.opt.shisen_show_hint = self.tkopt.shisen_show_hint.get()
# self.game.updateMenus() # self.game.updateMenus()
def mOptAccordionDealAll(self, *args):
if self._cancelDrag(break_pause=False):
return
self.app.opt.accordion_deal_all = self.tkopt.accordion_deal_all.get()
# self.game.updateMenus()
def _updateCardSize(self): def _updateCardSize(self):
geom = (self.app.canvas.winfo_width(), geom = (self.app.canvas.winfo_width(),
self.app.canvas.winfo_height()) self.app.canvas.winfo_height())

View file

@ -43,6 +43,7 @@ from pysollib.settings import DATA_DIRS, TOOLKIT
# Suits values are 0-3. This maps to colors 0-1. # Suits values are 0-3. This maps to colors 0-1.
SUITS = (_("Club"), _("Spade"), _("Heart"), _("Diamond")) SUITS = (_("Club"), _("Spade"), _("Heart"), _("Diamond"))
SUITS_PL = (_("Clubs"), _("Spades"), _("Hearts"), _("Diamonds"))
COLORS = (_("black"), _("red")) COLORS = (_("black"), _("red"))
# Card ranks are 0-12. We also define symbolic names for the picture cards. # Card ranks are 0-12. We also define symbolic names for the picture cards.