mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
Compare commits
3 commits
fd797ffbf5
...
41b4e75f15
Author | SHA1 | Date | |
---|---|---|---|
|
41b4e75f15 | ||
|
69a2036f94 | ||
|
7cb6d9c8b5 |
3 changed files with 61 additions and 153 deletions
|
@ -10,6 +10,7 @@ include NEWS.asciidoc
|
||||||
include pysollib/*.py pysollib/macosx/*.py pysollib/configobj/*.py
|
include pysollib/*.py pysollib/macosx/*.py pysollib/configobj/*.py
|
||||||
include pysollib/winsystems/*.py
|
include pysollib/winsystems/*.py
|
||||||
include pysollib/tk/*.py pysollib/tile/*.py pysollib/pysolgtk/*.py
|
include pysollib/tk/*.py pysollib/tile/*.py pysollib/pysolgtk/*.py
|
||||||
|
include pysollib/game/*.py
|
||||||
include pysollib/games/*.py pysollib/games/special/*.py
|
include pysollib/games/*.py pysollib/games/special/*.py
|
||||||
include pysollib/games/ultra/*.py pysollib/games/mahjongg/*.py
|
include pysollib/games/ultra/*.py pysollib/games/mahjongg/*.py
|
||||||
include data/tcl/*.tcl
|
include data/tcl/*.tcl
|
||||||
|
|
|
@ -29,6 +29,7 @@ from pickle import Pickler, Unpickler, UnpicklingError
|
||||||
|
|
||||||
from pysol_cards.cards import ms_rearrange
|
from pysol_cards.cards import ms_rearrange
|
||||||
|
|
||||||
|
from pysollib.game.dump import pysolDumpGame
|
||||||
from pysollib.gamedb import GI
|
from pysollib.gamedb import GI
|
||||||
from pysollib.help import help_about
|
from pysollib.help import help_about
|
||||||
from pysollib.hint import DefaultHint
|
from pysollib.hint import DefaultHint
|
||||||
|
@ -51,7 +52,7 @@ from pysollib.move import AUpdateStackMove
|
||||||
from pysollib.mygettext import _
|
from pysollib.mygettext import _
|
||||||
from pysollib.mygettext import ungettext
|
from pysollib.mygettext import ungettext
|
||||||
from pysollib.pysolrandom import LCRandom31, PysolRandom, constructRandom, \
|
from pysollib.pysolrandom import LCRandom31, PysolRandom, constructRandom, \
|
||||||
random__long2str, random__str2long
|
random__long2str
|
||||||
from pysollib.pysoltk import CURSOR_WATCH
|
from pysollib.pysoltk import CURSOR_WATCH
|
||||||
from pysollib.pysoltk import Card
|
from pysollib.pysoltk import Card
|
||||||
from pysollib.pysoltk import EVENT_HANDLED, EVENT_PROPAGATE
|
from pysollib.pysoltk import EVENT_HANDLED, EVENT_PROPAGATE
|
||||||
|
@ -275,10 +276,6 @@ class Game(object):
|
||||||
# the format for a saved game changed (see also canLoadGame())
|
# the format for a saved game changed (see also canLoadGame())
|
||||||
GAME_VERSION = 1
|
GAME_VERSION = 1
|
||||||
|
|
||||||
#
|
|
||||||
# game construction
|
|
||||||
#
|
|
||||||
|
|
||||||
# only basic initialization here
|
# only basic initialization here
|
||||||
def __init__(self, gameinfo):
|
def __init__(self, gameinfo):
|
||||||
self.preview = 0
|
self.preview = 0
|
||||||
|
@ -657,14 +654,8 @@ class Game(object):
|
||||||
# if self.app and self.app.toolbar:
|
# if self.app and self.app.toolbar:
|
||||||
# self.app.toolbar.setCursor(cursor=cursor)
|
# self.app.toolbar.setCursor(cursor=cursor)
|
||||||
|
|
||||||
#
|
|
||||||
# game creation
|
|
||||||
#
|
|
||||||
|
|
||||||
# start a new name
|
|
||||||
def newGame(self, random=None, restart=0, autoplay=1, shuffle=True,
|
def newGame(self, random=None, restart=0, autoplay=1, shuffle=True,
|
||||||
dealer=None):
|
dealer=None):
|
||||||
# print 'Game.newGame'
|
|
||||||
self.finished = False
|
self.finished = False
|
||||||
old_busy, self.busy = self.busy, 1
|
old_busy, self.busy = self.busy, 1
|
||||||
self.setCursor(cursor=CURSOR_WATCH)
|
self.setCursor(cursor=CURSOR_WATCH)
|
||||||
|
@ -675,7 +666,6 @@ class Game(object):
|
||||||
self.reset(restart=restart)
|
self.reset(restart=restart)
|
||||||
self.resetGame()
|
self.resetGame()
|
||||||
self.createRandom(random)
|
self.createRandom(random)
|
||||||
# print self.random, self.random.__dict__
|
|
||||||
if shuffle:
|
if shuffle:
|
||||||
self.shuffle()
|
self.shuffle()
|
||||||
assert len(self.s.talon.cards) == self.gameinfo.ncards
|
assert len(self.s.talon.cards) == self.gameinfo.ncards
|
||||||
|
@ -700,9 +690,7 @@ class Game(object):
|
||||||
if self.top:
|
if self.top:
|
||||||
self.top.update_idletasks()
|
self.top.update_idletasks()
|
||||||
self.top.show_now()
|
self.top.show_now()
|
||||||
#
|
|
||||||
self.stopSamples()
|
self.stopSamples()
|
||||||
# let's go
|
|
||||||
self.moves.state = self.S_INIT
|
self.moves.state = self.S_INIT
|
||||||
if dealer:
|
if dealer:
|
||||||
dealer()
|
dealer()
|
||||||
|
@ -725,7 +713,6 @@ class Game(object):
|
||||||
self.startPlayTimer()
|
self.startPlayTimer()
|
||||||
self.busy = old_busy
|
self.busy = old_busy
|
||||||
|
|
||||||
# restore a loaded game (see load/save below)
|
|
||||||
def restoreGame(self, game, reset=1):
|
def restoreGame(self, game, reset=1):
|
||||||
old_busy, self.busy = self.busy, 1
|
old_busy, self.busy = self.busy, 1
|
||||||
if reset:
|
if reset:
|
||||||
|
@ -780,20 +767,15 @@ class Game(object):
|
||||||
self.setCursor(cursor=self.app.top_cursor)
|
self.setCursor(cursor=self.app.top_cursor)
|
||||||
self.stats.update_time = time.time()
|
self.stats.update_time = time.time()
|
||||||
self.busy = old_busy
|
self.busy = old_busy
|
||||||
#
|
|
||||||
# self._configureHandler() # reallocateCards
|
|
||||||
# wait for canvas is mapped
|
# wait for canvas is mapped
|
||||||
after(self.top, 200, self._configureHandler)
|
after(self.top, 200, self._configureHandler)
|
||||||
#
|
|
||||||
if TOOLKIT == 'gtk':
|
if TOOLKIT == 'gtk':
|
||||||
# FIXME
|
# FIXME
|
||||||
if self.top:
|
if self.top:
|
||||||
self.top.update_idletasks()
|
self.top.update_idletasks()
|
||||||
self.top.show_now()
|
self.top.show_now()
|
||||||
#
|
|
||||||
self.startPlayTimer()
|
self.startPlayTimer()
|
||||||
|
|
||||||
# restore a bookmarked game (e.g. after changing the cardset)
|
|
||||||
def restoreGameFromBookmark(self, bookmark):
|
def restoreGameFromBookmark(self, bookmark):
|
||||||
old_busy, self.busy = self.busy, 1
|
old_busy, self.busy = self.busy, 1
|
||||||
file = BytesIO(bookmark)
|
file = BytesIO(bookmark)
|
||||||
|
@ -805,11 +787,9 @@ class Game(object):
|
||||||
self.busy = old_busy
|
self.busy = old_busy
|
||||||
|
|
||||||
def resetGame(self):
|
def resetGame(self):
|
||||||
# print 'Game.resetGame'
|
|
||||||
self.hints.list = None
|
self.hints.list = None
|
||||||
self.s.talon.removeAllCards()
|
self.s.talon.removeAllCards()
|
||||||
for stack in self.allstacks:
|
for stack in self.allstacks:
|
||||||
# print stack
|
|
||||||
stack.resetGame()
|
stack.resetGame()
|
||||||
if TOOLKIT == 'gtk':
|
if TOOLKIT == 'gtk':
|
||||||
# FIXME (pyramid like games)
|
# FIXME (pyramid like games)
|
||||||
|
@ -878,7 +858,6 @@ class Game(object):
|
||||||
stats.session_balance.get(self.id, 0) + b
|
stats.session_balance.get(self.id, 0) + b
|
||||||
stats.gameid_balance = stats.gameid_balance + b
|
stats.gameid_balance = stats.gameid_balance + b
|
||||||
|
|
||||||
# restart the current game
|
|
||||||
def restartGame(self):
|
def restartGame(self):
|
||||||
self.endGame(restart=1)
|
self.endGame(restart=1)
|
||||||
self.newGame(restart=1, random=self.random)
|
self.newGame(restart=1, random=self.random)
|
||||||
|
@ -921,16 +900,11 @@ class Game(object):
|
||||||
return
|
return
|
||||||
self.deleteStackDesc()
|
self.deleteStackDesc()
|
||||||
xf, yf = self.resizeImages()
|
xf, yf = self.resizeImages()
|
||||||
# print 'resizeGame', xf, yf
|
|
||||||
# stacks
|
|
||||||
for stack in self.allstacks:
|
for stack in self.allstacks:
|
||||||
x0, y0 = stack.init_coord
|
x0, y0 = stack.init_coord
|
||||||
x, y = int(round(x0*xf)), int(round(y0*yf))
|
x, y = int(round(x0*xf)), int(round(y0*yf))
|
||||||
# if x == stack.x and y == stack.y:
|
|
||||||
# continue
|
|
||||||
stack.resize(xf, yf)
|
stack.resize(xf, yf)
|
||||||
stack.updatePositions()
|
stack.updatePositions()
|
||||||
# regions
|
|
||||||
info = []
|
info = []
|
||||||
for stacks, rect in self.regions.init_info:
|
for stacks, rect in self.regions.init_info:
|
||||||
rect = (int(round(rect[0]*xf)), int(round(rect[1]*yf)),
|
rect = (int(round(rect[0]*xf)), int(round(rect[1]*yf)),
|
||||||
|
@ -950,9 +924,6 @@ class Game(object):
|
||||||
item = self.texts.list[i]
|
item = self.texts.list[i]
|
||||||
x, y = int(round(init_coord[0]*xf)), int(round(init_coord[1]*yf))
|
x, y = int(round(init_coord[0]*xf)), int(round(init_coord[1]*yf))
|
||||||
self.canvas.coords(item, x, y)
|
self.canvas.coords(item, x, y)
|
||||||
#
|
|
||||||
# self.canvas.update()
|
|
||||||
# self.canvas.update_idletasks()
|
|
||||||
|
|
||||||
def createRandom(self, random):
|
def createRandom(self, random):
|
||||||
if random is None:
|
if random is None:
|
||||||
|
@ -969,8 +940,6 @@ class Game(object):
|
||||||
else:
|
else:
|
||||||
self.random = random
|
self.random = random
|
||||||
self.random.reset()
|
self.random.reset()
|
||||||
# print 'createRandom:', self.random
|
|
||||||
# print "createRandom: origin =", self.random.origin
|
|
||||||
|
|
||||||
def enterState(self, state):
|
def enterState(self, state):
|
||||||
old_state = self.moves.state
|
old_state = self.moves.state
|
||||||
|
@ -1009,7 +978,6 @@ class Game(object):
|
||||||
sg[s] = [s.id]
|
sg[s] = [s.id]
|
||||||
sg = list(sg.values())
|
sg = list(sg.values())
|
||||||
self.sn_groups = sg
|
self.sn_groups = sg
|
||||||
# print sg
|
|
||||||
|
|
||||||
def updateSnapshots(self):
|
def updateSnapshots(self):
|
||||||
sn = self.getSnapshot()
|
sn = self.getSnapshot()
|
||||||
|
@ -1020,10 +988,6 @@ class Game(object):
|
||||||
self.snapshots.append(sn)
|
self.snapshots.append(sn)
|
||||||
# self.updateStatus(snapshot=False)
|
# self.updateStatus(snapshot=False)
|
||||||
|
|
||||||
#
|
|
||||||
# card creation & shuffling
|
|
||||||
#
|
|
||||||
|
|
||||||
# Create all cards for the game.
|
# Create all cards for the game.
|
||||||
def createCards(self, progress=None):
|
def createCards(self, progress=None):
|
||||||
gi = self.gameinfo
|
gi = self.gameinfo
|
||||||
|
@ -1115,10 +1079,6 @@ class Game(object):
|
||||||
i -= 1
|
i -= 1
|
||||||
return new, [x[2] for x in reversed(sorted(extracted))]
|
return new, [x[2] for x in reversed(sorted(extracted))]
|
||||||
|
|
||||||
#
|
|
||||||
# menu support
|
|
||||||
#
|
|
||||||
|
|
||||||
def _finishDrag(self):
|
def _finishDrag(self):
|
||||||
if self.demo:
|
if self.demo:
|
||||||
self.stopDemo()
|
self.stopDemo()
|
||||||
|
@ -1150,10 +1110,6 @@ class Game(object):
|
||||||
if not self.preview:
|
if not self.preview:
|
||||||
self.app.menubar.disableMenus()
|
self.app.menubar.disableMenus()
|
||||||
|
|
||||||
#
|
|
||||||
# UI & graphics support
|
|
||||||
#
|
|
||||||
|
|
||||||
def _defaultHandler(self, event):
|
def _defaultHandler(self, event):
|
||||||
if not self.app:
|
if not self.app:
|
||||||
return True # FIXME (GTK)
|
return True # FIXME (GTK)
|
||||||
|
@ -1162,7 +1118,6 @@ class Game(object):
|
||||||
if self.pause:
|
if self.pause:
|
||||||
self.app.menubar.mPause()
|
self.app.menubar.mPause()
|
||||||
return True
|
return True
|
||||||
# stop animation
|
|
||||||
if not self.event_handled and self.stopWinAnimation():
|
if not self.event_handled and self.stopWinAnimation():
|
||||||
return True
|
return True
|
||||||
self.interruptSleep()
|
self.interruptSleep()
|
||||||
|
@ -1170,11 +1125,9 @@ class Game(object):
|
||||||
# delete piles descriptions
|
# delete piles descriptions
|
||||||
return True
|
return True
|
||||||
if self.demo:
|
if self.demo:
|
||||||
# stop demo
|
|
||||||
self.stopDemo()
|
self.stopDemo()
|
||||||
return True
|
return True
|
||||||
if not self.event_handled and self.drag.stack:
|
if not self.event_handled and self.drag.stack:
|
||||||
# cancel drag
|
|
||||||
self.drag.stack.cancelDrag(event)
|
self.drag.stack.cancelDrag(event)
|
||||||
return True
|
return True
|
||||||
return False # continue this event
|
return False # continue this event
|
||||||
|
@ -1212,12 +1165,10 @@ class Game(object):
|
||||||
_resizeHandlerID = None
|
_resizeHandlerID = None
|
||||||
|
|
||||||
def _resizeHandler(self):
|
def _resizeHandler(self):
|
||||||
# print '_resizeHandler'
|
|
||||||
self._resizeHandlerID = None
|
self._resizeHandlerID = None
|
||||||
self.resizeGame()
|
self.resizeGame()
|
||||||
|
|
||||||
def _configureHandler(self, event=None):
|
def _configureHandler(self, event=None):
|
||||||
# print 'configureHandler'
|
|
||||||
if False: # if not USE_PIL:
|
if False: # if not USE_PIL:
|
||||||
return
|
return
|
||||||
if not self.app:
|
if not self.app:
|
||||||
|
@ -1232,12 +1183,7 @@ class Game(object):
|
||||||
self.canvas.after_cancel(self._resizeHandlerID)
|
self.canvas.after_cancel(self._resizeHandlerID)
|
||||||
self._resizeHandlerID = self.canvas.after(250, self._resizeHandler)
|
self._resizeHandlerID = self.canvas.after(250, self._resizeHandler)
|
||||||
|
|
||||||
#
|
|
||||||
# sound support
|
|
||||||
#
|
|
||||||
|
|
||||||
def playSample(self, name, priority=0, loop=0):
|
def playSample(self, name, priority=0, loop=0):
|
||||||
# print "Game.playSample:", name, priority, loop
|
|
||||||
if name in self.app.opt.sound_samples and \
|
if name in self.app.opt.sound_samples and \
|
||||||
not self.app.opt.sound_samples[name]:
|
not self.app.opt.sound_samples[name]:
|
||||||
return 0
|
return 0
|
||||||
|
@ -1269,15 +1215,9 @@ class Game(object):
|
||||||
elif a == 5:
|
elif a == 5:
|
||||||
self.playSample("deal08", priority=100, loop=loop)
|
self.playSample("deal08", priority=100, loop=loop)
|
||||||
|
|
||||||
#
|
|
||||||
# misc. methods
|
|
||||||
#
|
|
||||||
|
|
||||||
def areYouSure(self, title=None, text=None, confirm=-1, default=0):
|
def areYouSure(self, title=None, text=None, confirm=-1, default=0):
|
||||||
|
|
||||||
if TOOLKIT == 'kivy':
|
if TOOLKIT == 'kivy':
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if self.preview:
|
if self.preview:
|
||||||
return True
|
return True
|
||||||
if confirm < 0:
|
if confirm < 0:
|
||||||
|
@ -1296,7 +1236,6 @@ class Game(object):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def notYetImplemented(self):
|
def notYetImplemented(self):
|
||||||
# don't used
|
|
||||||
MfxMessageDialog(self.top, title="Not yet implemented",
|
MfxMessageDialog(self.top, title="Not yet implemented",
|
||||||
text="This function is\nnot yet implemented.",
|
text="This function is\nnot yet implemented.",
|
||||||
bitmap="error")
|
bitmap="error")
|
||||||
|
@ -1414,7 +1353,7 @@ class Game(object):
|
||||||
im2 = card._face_image._pil_image
|
im2 = card._face_image._pil_image
|
||||||
w, h = im1.size
|
w, h = im1.size
|
||||||
id = card.item.id
|
id = card.item.id
|
||||||
#
|
|
||||||
SPF = 0.1/8 # animation speed - seconds per frame
|
SPF = 0.1/8 # animation speed - seconds per frame
|
||||||
frames = 4.0 # num frames for each step
|
frames = 4.0 # num frames for each step
|
||||||
if self.app.opt.animations == 3: # medium
|
if self.app.opt.animations == 3: # medium
|
||||||
|
@ -1634,8 +1573,6 @@ class Game(object):
|
||||||
def winAnimation(self, perfect=0):
|
def winAnimation(self, perfect=0):
|
||||||
if self.preview:
|
if self.preview:
|
||||||
return
|
return
|
||||||
# if not self.app.opt.animations:
|
|
||||||
# return
|
|
||||||
if not self.app.opt.win_animation:
|
if not self.app.opt.win_animation:
|
||||||
return
|
return
|
||||||
if TOOLKIT == 'gtk':
|
if TOOLKIT == 'gtk':
|
||||||
|
@ -1725,10 +1662,6 @@ class Game(object):
|
||||||
if self.top:
|
if self.top:
|
||||||
self.top.interruptSleep()
|
self.top.interruptSleep()
|
||||||
|
|
||||||
#
|
|
||||||
# card image support
|
|
||||||
#
|
|
||||||
|
|
||||||
def getCardFaceImage(self, deck, suit, rank):
|
def getCardFaceImage(self, deck, suit, rank):
|
||||||
return self.app.images.getFace(deck, suit, rank)
|
return self.app.images.getFace(deck, suit, rank)
|
||||||
|
|
||||||
|
@ -1738,10 +1671,6 @@ class Game(object):
|
||||||
def getCardShadeImage(self):
|
def getCardShadeImage(self):
|
||||||
return self.app.images.getShade()
|
return self.app.images.getShade()
|
||||||
|
|
||||||
#
|
|
||||||
# layout support
|
|
||||||
#
|
|
||||||
|
|
||||||
def _getClosestStack(self, cx, cy, stacks, dragstack):
|
def _getClosestStack(self, cx, cy, stacks, dragstack):
|
||||||
closest, cdist = None, 999999999
|
closest, cdist = None, 999999999
|
||||||
# Since we only compare distances,
|
# Since we only compare distances,
|
||||||
|
@ -1775,10 +1704,8 @@ class Game(object):
|
||||||
r = rect
|
r = rect
|
||||||
if USE_PIL:
|
if USE_PIL:
|
||||||
x, y = s.init_coord
|
x, y = s.init_coord
|
||||||
# print 'setRegion:', x, y, r
|
|
||||||
else:
|
else:
|
||||||
x, y = s.x, s.y
|
x, y = s.x, s.y
|
||||||
# print 'setRegion:', x, y, r
|
|
||||||
assert r[0] <= x <= r[2] and r[1] <= y <= r[3]
|
assert r[0] <= x <= r[2] and r[1] <= y <= r[3]
|
||||||
# verify that the stack is not already in another region
|
# verify that the stack is not already in another region
|
||||||
# with the same priority
|
# with the same priority
|
||||||
|
@ -1866,21 +1793,15 @@ class Game(object):
|
||||||
def getStrictness(self):
|
def getStrictness(self):
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
# can we save outself ?
|
|
||||||
def canSaveGame(self):
|
def canSaveGame(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# can we load this game ?
|
|
||||||
|
|
||||||
def canLoadGame(self, version_tuple, game_version):
|
def canLoadGame(self, version_tuple, game_version):
|
||||||
return self.GAME_VERSION == game_version
|
return self.GAME_VERSION == game_version
|
||||||
|
|
||||||
# can we set a bookmark ?
|
|
||||||
|
|
||||||
def canSetBookmark(self):
|
def canSetBookmark(self):
|
||||||
return self.canSaveGame()
|
return self.canSaveGame()
|
||||||
|
|
||||||
# can we undo/redo ?
|
|
||||||
def canUndo(self):
|
def canUndo(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -1891,10 +1812,6 @@ class Game(object):
|
||||||
def canShuffle(self):
|
def canShuffle(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
#
|
|
||||||
# Game - stats handlers
|
|
||||||
#
|
|
||||||
|
|
||||||
# game changed - i.e. should we ask the player to discard the game
|
# game changed - i.e. should we ask the player to discard the game
|
||||||
def changed(self, restart=False):
|
def changed(self, restart=False):
|
||||||
if self.gstats.updated < 0:
|
if self.gstats.updated < 0:
|
||||||
|
@ -2217,7 +2134,7 @@ Congratulations, you did it !
|
||||||
x = int(int(self.canvas.cget('width'))*(self.canvas.xview()[0]))
|
x = int(int(self.canvas.cget('width'))*(self.canvas.xview()[0]))
|
||||||
y = int(int(self.canvas.cget('height'))*(self.canvas.yview()[0]))
|
y = int(int(self.canvas.cget('height'))*(self.canvas.yview()[0]))
|
||||||
w, h = self.canvas.winfo_width(), self.canvas.winfo_height()
|
w, h = self.canvas.winfo_width(), self.canvas.winfo_height()
|
||||||
#
|
|
||||||
color = self.app.opt.colors['not_matching']
|
color = self.app.opt.colors['not_matching']
|
||||||
width = 6
|
width = 6
|
||||||
xmargin, ymargin = self.canvas.xmargin, self.canvas.ymargin
|
xmargin, ymargin = self.canvas.xmargin, self.canvas.ymargin
|
||||||
|
@ -2312,10 +2229,6 @@ Congratulations, you did it !
|
||||||
((card1.rank + 1) % 13 == card2.rank or
|
((card1.rank + 1) % 13 == card2.rank or
|
||||||
(card2.rank + 1) % 13 == card1.rank))
|
(card2.rank + 1) % 13 == card1.rank))
|
||||||
|
|
||||||
#
|
|
||||||
# quick-play
|
|
||||||
#
|
|
||||||
|
|
||||||
def getQuickPlayScore(self, ncards, from_stack, to_stack):
|
def getQuickPlayScore(self, ncards, from_stack, to_stack):
|
||||||
if to_stack in self.s.reserves:
|
if to_stack in self.s.reserves:
|
||||||
# if to_stack in reserves prefer empty stack
|
# if to_stack in reserves prefer empty stack
|
||||||
|
@ -2366,10 +2279,6 @@ Congratulations, you did it !
|
||||||
def getGameBalance(self):
|
def getGameBalance(self):
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
#
|
|
||||||
# Hint - uses self.getHintClass()
|
|
||||||
#
|
|
||||||
|
|
||||||
# compute all hints for the current position
|
# compute all hints for the current position
|
||||||
# this is the only method that actually uses class Hint
|
# this is the only method that actually uses class Hint
|
||||||
def getHints(self, level, taken_hint=None):
|
def getHints(self, level, taken_hint=None):
|
||||||
|
@ -2485,7 +2394,6 @@ Congratulations, you did it !
|
||||||
# Demo - uses showHint()
|
# Demo - uses showHint()
|
||||||
#
|
#
|
||||||
|
|
||||||
# start a demo
|
|
||||||
def startDemo(self, mixed=1, level=2):
|
def startDemo(self, mixed=1, level=2):
|
||||||
assert level >= 2 # needed for flip/deal hints
|
assert level >= 2 # needed for flip/deal hints
|
||||||
if not self.top:
|
if not self.top:
|
||||||
|
@ -2506,7 +2414,6 @@ Congratulations, you did it !
|
||||||
self.createDemoLogo()
|
self.createDemoLogo()
|
||||||
after_idle(self.top, self.demoEvent) # schedule first move
|
after_idle(self.top, self.demoEvent) # schedule first move
|
||||||
|
|
||||||
# stop the demo
|
|
||||||
def stopDemo(self, event=None):
|
def stopDemo(self, event=None):
|
||||||
if not self.demo:
|
if not self.demo:
|
||||||
return
|
return
|
||||||
|
@ -2757,10 +2664,6 @@ Congratulations, you did it !
|
||||||
self.demo_logo = self.app.gimages.demo[int(n)]
|
self.demo_logo = self.app.gimages.demo[int(n)]
|
||||||
self.canvas.setTopImage(self.demo_logo)
|
self.canvas.setTopImage(self.demo_logo)
|
||||||
|
|
||||||
#
|
|
||||||
# stuck
|
|
||||||
#
|
|
||||||
|
|
||||||
def getStuck(self):
|
def getStuck(self):
|
||||||
h = self.Stuck_Class.getHints(None)
|
h = self.Stuck_Class.getHints(None)
|
||||||
if h:
|
if h:
|
||||||
|
@ -2973,10 +2876,6 @@ Congratulations, you did it !
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
#
|
|
||||||
# undo/redo layer
|
|
||||||
#
|
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
assert self.canUndo()
|
assert self.canUndo()
|
||||||
assert self.moves.state == self.S_PLAY and len(self.moves.current) == 0
|
assert self.moves.state == self.S_PLAY and len(self.moves.current) == 0
|
||||||
|
@ -3092,10 +2991,6 @@ Congratulations, you did it !
|
||||||
def undoGotoBookmark(self):
|
def undoGotoBookmark(self):
|
||||||
self.gotoBookmark(-1, update_stats=0)
|
self.gotoBookmark(-1, update_stats=0)
|
||||||
|
|
||||||
#
|
|
||||||
# load/save
|
|
||||||
#
|
|
||||||
|
|
||||||
def loadGame(self, filename):
|
def loadGame(self, filename):
|
||||||
if self.changed():
|
if self.changed():
|
||||||
if not self.areYouSure(_("Open game")):
|
if not self.areYouSure(_("Open game")):
|
||||||
|
@ -3271,42 +3166,7 @@ in the current implementation.''') % version)
|
||||||
self._dumpGame(Pickler(f, protocol))
|
self._dumpGame(Pickler(f, protocol))
|
||||||
|
|
||||||
def _dumpGame(self, p, bookmark=0):
|
def _dumpGame(self, p, bookmark=0):
|
||||||
self.updateTime()
|
return pysolDumpGame(self, p, bookmark)
|
||||||
assert 0 <= bookmark <= 2
|
|
||||||
p.dump(PACKAGE)
|
|
||||||
p.dump(VERSION)
|
|
||||||
p.dump(VERSION_TUPLE)
|
|
||||||
p.dump(bookmark)
|
|
||||||
p.dump(self.GAME_VERSION)
|
|
||||||
p.dump(self.id)
|
|
||||||
#
|
|
||||||
p.dump(random__str2long(self.random.getSeedStr()))
|
|
||||||
p.dump(self.random.getstate())
|
|
||||||
#
|
|
||||||
p.dump(len(self.allstacks))
|
|
||||||
for stack in self.allstacks:
|
|
||||||
p.dump(len(stack.cards))
|
|
||||||
for card in stack.cards:
|
|
||||||
p.dump(card.id)
|
|
||||||
p.dump(card.face_up)
|
|
||||||
p.dump(self.s.talon.round)
|
|
||||||
p.dump(self.finished)
|
|
||||||
if 0 <= bookmark <= 1:
|
|
||||||
p.dump(self.saveinfo)
|
|
||||||
p.dump(self.gsaveinfo)
|
|
||||||
p.dump(self.moves)
|
|
||||||
p.dump(self.snapshots)
|
|
||||||
if 0 <= bookmark <= 1:
|
|
||||||
if bookmark == 0:
|
|
||||||
self.gstats.saved = self.gstats.saved + 1
|
|
||||||
p.dump(self.gstats)
|
|
||||||
p.dump(self.stats)
|
|
||||||
self._saveGameHook(p)
|
|
||||||
p.dump("EOF")
|
|
||||||
|
|
||||||
#
|
|
||||||
# Playing time
|
|
||||||
#
|
|
||||||
|
|
||||||
def startPlayTimer(self):
|
def startPlayTimer(self):
|
||||||
self.updateStatus(time=None)
|
self.updateStatus(time=None)
|
||||||
|
@ -3331,10 +3191,6 @@ in the current implementation.''') % version)
|
||||||
d = time.time() - self.stats.update_time + self.stats.elapsed_time
|
d = time.time() - self.stats.update_time + self.stats.elapsed_time
|
||||||
self.updateStatus(time=format_time(d))
|
self.updateStatus(time=format_time(d))
|
||||||
|
|
||||||
#
|
|
||||||
# Pause
|
|
||||||
#
|
|
||||||
|
|
||||||
def doPause(self):
|
def doPause(self):
|
||||||
if self.finished:
|
if self.finished:
|
||||||
return
|
return
|
||||||
|
@ -3356,10 +3212,6 @@ in the current implementation.''') % version)
|
||||||
self.pause_logo = None
|
self.pause_logo = None
|
||||||
self.canvas.showAllItems()
|
self.canvas.showAllItems()
|
||||||
|
|
||||||
#
|
|
||||||
# Help
|
|
||||||
#
|
|
||||||
|
|
||||||
def showHelp(self, *args):
|
def showHelp(self, *args):
|
||||||
if self.preview:
|
if self.preview:
|
||||||
return
|
return
|
55
pysollib/game/dump.py
Normal file
55
pysollib/game/dump.py
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
# Copyright (C) 1998-2003 Markus Franz Xaver Johannes Oberhumer
|
||||||
|
# Copyright (C) 2003 Mt. Hood Playing Card Co.
|
||||||
|
# Copyright (C) 2005-2009 Skomoroh
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
from pysollib.pysolrandom import random__str2long
|
||||||
|
from pysollib.settings import PACKAGE
|
||||||
|
from pysollib.settings import VERSION, VERSION_TUPLE
|
||||||
|
|
||||||
|
|
||||||
|
def pysolDumpGame(game_, p, bookmark=0):
|
||||||
|
game_.updateTime()
|
||||||
|
assert 0 <= bookmark <= 2
|
||||||
|
p.dump(PACKAGE)
|
||||||
|
p.dump(VERSION)
|
||||||
|
p.dump(VERSION_TUPLE)
|
||||||
|
p.dump(bookmark)
|
||||||
|
p.dump(game_.GAME_VERSION)
|
||||||
|
p.dump(game_.id)
|
||||||
|
#
|
||||||
|
p.dump(random__str2long(game_.random.getSeedStr()))
|
||||||
|
p.dump(game_.random.getstate())
|
||||||
|
#
|
||||||
|
p.dump(len(game_.allstacks))
|
||||||
|
for stack in game_.allstacks:
|
||||||
|
p.dump(len(stack.cards))
|
||||||
|
for card in stack.cards:
|
||||||
|
p.dump(card.id)
|
||||||
|
p.dump(card.face_up)
|
||||||
|
p.dump(game_.s.talon.round)
|
||||||
|
p.dump(game_.finished)
|
||||||
|
if 0 <= bookmark <= 1:
|
||||||
|
p.dump(game_.saveinfo)
|
||||||
|
p.dump(game_.gsaveinfo)
|
||||||
|
p.dump(game_.moves)
|
||||||
|
p.dump(game_.snapshots)
|
||||||
|
if 0 <= bookmark <= 1:
|
||||||
|
if bookmark == 0:
|
||||||
|
game_.gstats.saved += 1
|
||||||
|
p.dump(game_.gstats)
|
||||||
|
p.dump(game_.stats)
|
||||||
|
game_._saveGameHook(p)
|
||||||
|
p.dump("EOF")
|
Loading…
Add table
Reference in a new issue