mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
+ new mouse binding: middle click -> autodrop
* fixed `Octave' game git-svn-id: file:///home/shlomif/Backup/svn-dumps/PySolFC/svnsync-repos/pysolfc/PySolFC/trunk@192 efabe8c0-fbe8-4139-b769-b5e6d273206e
This commit is contained in:
parent
f6c646d1a5
commit
73fa562a97
4 changed files with 82 additions and 57 deletions
|
@ -253,9 +253,7 @@ class Game:
|
||||||
|
|
||||||
def initBindings(self):
|
def initBindings(self):
|
||||||
# note: a Game is only allowed to bind self.canvas and not to self.top
|
# note: a Game is only allowed to bind self.canvas and not to self.top
|
||||||
##bind(self.canvas, "<1>", self.clickHandler)
|
bind(self.canvas, "<2>", self.dropHandler)
|
||||||
bind(self.canvas, "<2>", self.clickHandler)
|
|
||||||
##bind(self.canvas, "<3>", self.clickHandler)
|
|
||||||
##bind(self.canvas, "<Double-1>", self.undoHandler)
|
##bind(self.canvas, "<Double-1>", self.undoHandler)
|
||||||
bind(self.canvas, "<1>", self.undoHandler)
|
bind(self.canvas, "<1>", self.undoHandler)
|
||||||
bind(self.canvas, "<3>", self.redoHandler)
|
bind(self.canvas, "<3>", self.redoHandler)
|
||||||
|
@ -853,44 +851,42 @@ class Game:
|
||||||
# UI & graphics support
|
# UI & graphics support
|
||||||
#
|
#
|
||||||
|
|
||||||
def _defaultHandler(self):
|
def _defaultHandler(self, event):
|
||||||
|
if not self.app:
|
||||||
|
return True # FIXME (GTK)
|
||||||
|
if not self.app.opt.mouse_undo:
|
||||||
|
return True
|
||||||
|
# stop animation
|
||||||
|
if not self.event_handled and self.stopWinAnimation():
|
||||||
|
return True
|
||||||
self.interruptSleep()
|
self.interruptSleep()
|
||||||
self.deleteStackDesc()
|
if self.deleteStackDesc():
|
||||||
|
# delete piles descriptions
|
||||||
|
return True
|
||||||
|
if self.demo:
|
||||||
|
# stop demo
|
||||||
|
self.stopDemo()
|
||||||
|
return True
|
||||||
|
if not self.event_handled and self.drag.stack:
|
||||||
|
# cancel drag
|
||||||
|
self.drag.stack.cancelDrag(event)
|
||||||
|
return True
|
||||||
|
return False # continue this event
|
||||||
|
|
||||||
def clickHandler(self, event):
|
def dropHandler(self, event):
|
||||||
if self.stopWinAnimation(): return EVENT_PROPAGATE
|
if not self._defaultHandler(event) and not self.event_handled:
|
||||||
self._defaultHandler()
|
self.app.menubar.mDrop()
|
||||||
self.event_handled = False
|
self.event_handled = False
|
||||||
return EVENT_PROPAGATE
|
return EVENT_PROPAGATE
|
||||||
|
|
||||||
def undoHandler(self, event):
|
def undoHandler(self, event):
|
||||||
if not self.app: return EVENT_PROPAGATE # FIXME (GTK)
|
if not self._defaultHandler(event) and not self.event_handled:
|
||||||
if not self.event_handled and self.stopWinAnimation():
|
|
||||||
return EVENT_PROPAGATE
|
|
||||||
self._defaultHandler()
|
|
||||||
if self.demo:
|
|
||||||
self.stopDemo()
|
|
||||||
return
|
|
||||||
if not self.event_handled:
|
|
||||||
if self.drag.stack:
|
|
||||||
self.drag.stack.cancelDrag(event)
|
|
||||||
elif self.app.opt.mouse_undo:
|
|
||||||
self.app.menubar.mUndo()
|
self.app.menubar.mUndo()
|
||||||
self.event_handled = False
|
self.event_handled = False
|
||||||
return EVENT_PROPAGATE
|
return EVENT_PROPAGATE
|
||||||
|
|
||||||
def redoHandler(self, event):
|
def redoHandler(self, event):
|
||||||
if not self.app: return EVENT_PROPAGATE # FIXME (GTK)
|
if not self._defaultHandler(event) and not self.event_handled:
|
||||||
if not self.event_handled and self.stopWinAnimation():
|
|
||||||
return EVENT_PROPAGATE
|
|
||||||
self._defaultHandler()
|
|
||||||
if self.demo:
|
|
||||||
self.stopDemo()
|
|
||||||
return
|
|
||||||
if not self.event_handled:
|
|
||||||
if self.drag.stack:
|
|
||||||
self.drag.stack.cancelDrag(event)
|
|
||||||
elif self.app.opt.mouse_undo:
|
|
||||||
self.app.menubar.mRedo()
|
self.app.menubar.mRedo()
|
||||||
self.event_handled = False
|
self.event_handled = False
|
||||||
return EVENT_PROPAGATE
|
return EVENT_PROPAGATE
|
||||||
|
@ -3124,6 +3120,8 @@ in the current implementation.''') % version)
|
||||||
for sd in self.stackdesc_list:
|
for sd in self.stackdesc_list:
|
||||||
sd.delete()
|
sd.delete()
|
||||||
self.stackdesc_list = []
|
self.stackdesc_list = []
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
## for find_card_dialog
|
## for find_card_dialog
|
||||||
def canFindCard(self):
|
def canFindCard(self):
|
||||||
|
|
|
@ -522,10 +522,13 @@ class Octave_Talon(WasteTalonStack):
|
||||||
|
|
||||||
def dealCards(self, sound=False):
|
def dealCards(self, sound=False):
|
||||||
if self.round == self.max_rounds:
|
if self.round == self.max_rounds:
|
||||||
|
return 0
|
||||||
|
if self.cards:
|
||||||
|
return WasteTalonStack.dealCards(self, sound)
|
||||||
# last round
|
# last round
|
||||||
old_state = self.game.enterState(self.game.S_DEAL)
|
num_cards = WasteTalonStack.dealCards(self, sound)
|
||||||
num_cards = 0
|
|
||||||
wastes = [self.waste]+list(self.game.s.reserves)
|
wastes = [self.waste]+list(self.game.s.reserves)
|
||||||
|
old_state = self.game.enterState(self.game.S_DEAL)
|
||||||
if self.cards:
|
if self.cards:
|
||||||
if sound and not self.game.demo:
|
if sound and not self.game.demo:
|
||||||
self.game.startDealSample()
|
self.game.startDealSample()
|
||||||
|
@ -538,7 +541,17 @@ class Octave_Talon(WasteTalonStack):
|
||||||
self.game.stopSamples()
|
self.game.stopSamples()
|
||||||
self.game.leaveState(old_state)
|
self.game.leaveState(old_state)
|
||||||
return num_cards
|
return num_cards
|
||||||
return WasteTalonStack.dealCards(self, sound)
|
|
||||||
|
|
||||||
|
class Octave_Waste(WasteStack):
|
||||||
|
def updateText(self):
|
||||||
|
if self.game.preview > 1 or self.texts.ncards is None:
|
||||||
|
return
|
||||||
|
if self.game.s.talon.round == self.game.s.talon.max_rounds:
|
||||||
|
t = ''
|
||||||
|
else:
|
||||||
|
t = str(len(self.cards))
|
||||||
|
self.texts.ncards.config(text=t)
|
||||||
|
|
||||||
|
|
||||||
class Octave(Game):
|
class Octave(Game):
|
||||||
|
@ -558,13 +571,13 @@ class Octave(Game):
|
||||||
self.setSize(w, h)
|
self.setSize(w, h)
|
||||||
|
|
||||||
# create stacks
|
# create stacks
|
||||||
x, y = l.XM, l.YM
|
x, y = l.XM+l.XS/2, l.YM
|
||||||
for i in range(8):
|
for i in range(8):
|
||||||
s.foundations.append(SS_FoundationStack(x, y, self,
|
s.foundations.append(SS_FoundationStack(x, y, self,
|
||||||
suit=int(i/2), max_cards=10))
|
suit=int(i/2), max_cards=10))
|
||||||
x += l.XS
|
x += l.XS
|
||||||
|
|
||||||
x, y = l.XM, l.YM+l.YS
|
x, y = l.XM+l.XS/2, l.YM+l.YS
|
||||||
for i in range(8):
|
for i in range(8):
|
||||||
s.rows.append(AC_RowStack(x, y, self,
|
s.rows.append(AC_RowStack(x, y, self,
|
||||||
base_rank=ANY_RANK, max_move=1))
|
base_rank=ANY_RANK, max_move=1))
|
||||||
|
@ -574,10 +587,12 @@ class Octave(Game):
|
||||||
s.talon = Octave_Talon(x, y, self, max_rounds=2)
|
s.talon = Octave_Talon(x, y, self, max_rounds=2)
|
||||||
l.createText(s.talon, "n")
|
l.createText(s.talon, "n")
|
||||||
x += l.XS
|
x += l.XS
|
||||||
s.waste = WasteStack(x, y, self)
|
s.waste = Octave_Waste(x, y, self)
|
||||||
|
l.createText(s.waste, 'n')
|
||||||
x += l.XS
|
x += l.XS
|
||||||
for i in range(7):
|
for i in range(7):
|
||||||
s.reserves.append(OpenStack(x, y, self, max_accept=0))
|
stack = WasteStack(x, y, self, max_accept=0)
|
||||||
|
s.reserves.append(stack)
|
||||||
x += l.XS
|
x += l.XS
|
||||||
|
|
||||||
# define stack-groups
|
# define stack-groups
|
||||||
|
@ -586,7 +601,7 @@ class Octave(Game):
|
||||||
def _shuffleHook(self, cards):
|
def _shuffleHook(self, cards):
|
||||||
# move Aces to top of the Talon (i.e. first cards to be dealt)
|
# move Aces to top of the Talon (i.e. first cards to be dealt)
|
||||||
return self._shuffleHookMoveToTop(cards,
|
return self._shuffleHookMoveToTop(cards,
|
||||||
lambda c: (c.rank == 0, c.suit))
|
lambda c: (c.rank == ACE, c.suit))
|
||||||
|
|
||||||
def startGame(self):
|
def startGame(self):
|
||||||
self.s.talon.dealRow(rows=self.s.foundations, frames=0)
|
self.s.talon.dealRow(rows=self.s.foundations, frames=0)
|
||||||
|
@ -613,6 +628,16 @@ class Octave(Game):
|
||||||
return self.dealCards(sound=sound)
|
return self.dealCards(sound=sound)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
def fillStack(self, stack):
|
||||||
|
if self.s.talon.round == self.s.talon.max_rounds:
|
||||||
|
# last round
|
||||||
|
if not stack.cards and self.s.talon.cards:
|
||||||
|
if stack is self.s.waste or stack in self.s.reserves:
|
||||||
|
old_state = self.enterState(self.S_FILL)
|
||||||
|
self.flipMove(self.s.talon)
|
||||||
|
self.moveMove(1, self.s.talon, stack, frames=4, shadow=0)
|
||||||
|
self.leaveState(old_state)
|
||||||
|
|
||||||
|
|
||||||
# /***********************************************************************
|
# /***********************************************************************
|
||||||
# // Fortune's Favor
|
# // Fortune's Favor
|
||||||
|
@ -1186,7 +1211,7 @@ registerGame(GameInfo(295, NapoleonsSquare, "Napoleon's Square",
|
||||||
registerGame(GameInfo(310, Emperor, "Emperor",
|
registerGame(GameInfo(310, Emperor, "Emperor",
|
||||||
GI.GT_FORTY_THIEVES, 2, 0, GI.SL_BALANCED))
|
GI.GT_FORTY_THIEVES, 2, 0, GI.SL_BALANCED))
|
||||||
registerGame(GameInfo(323, Octave, "Octave",
|
registerGame(GameInfo(323, Octave, "Octave",
|
||||||
GI.GT_FORTY_THIEVES, 2, 1, GI.SL_BALANCED))
|
GI.GT_FORTY_THIEVES, 2, 1, GI.SL_MOSTLY_SKILL))
|
||||||
registerGame(GameInfo(332, Mumbai, "Mumbai",
|
registerGame(GameInfo(332, Mumbai, "Mumbai",
|
||||||
GI.GT_FORTY_THIEVES, 3, 0, GI.SL_MOSTLY_SKILL))
|
GI.GT_FORTY_THIEVES, 3, 0, GI.SL_MOSTLY_SKILL))
|
||||||
registerGame(GameInfo(411, CarreNapoleon, "Carre Napoleon",
|
registerGame(GameInfo(411, CarreNapoleon, "Carre Napoleon",
|
||||||
|
|
|
@ -681,7 +681,8 @@ class StackDesc:
|
||||||
if text:
|
if text:
|
||||||
frame = Tkinter.Frame(self.canvas)
|
frame = Tkinter.Frame(self.canvas)
|
||||||
self.frame = frame
|
self.frame = frame
|
||||||
label = Tkinter.Message(frame, font=font, text=text, width=cardw-8,
|
label = Tkinter.Message(frame, font=font, text=text,
|
||||||
|
width=cardw-8, relief='solid',
|
||||||
fg='#000000', bg='#ffffe0', bd=1)
|
fg='#000000', bg='#ffffe0', bd=1)
|
||||||
label.pack()
|
label.pack()
|
||||||
self.label = label
|
self.label = label
|
||||||
|
|
|
@ -672,7 +672,8 @@ class StackDesc:
|
||||||
frame = Tkinter.Frame(self.canvas, highlightthickness=1,
|
frame = Tkinter.Frame(self.canvas, highlightthickness=1,
|
||||||
highlightbackground='black')
|
highlightbackground='black')
|
||||||
self.frame = frame
|
self.frame = frame
|
||||||
label = Tkinter.Message(frame, font=font, text=text, width=cardw-8,
|
label = Tkinter.Message(frame, font=font, text=text,
|
||||||
|
width=cardw-8, relief='solid',
|
||||||
fg='#000000', bg='#ffffe0', bd=1)
|
fg='#000000', bg='#ffffe0', bd=1)
|
||||||
label.pack()
|
label.pack()
|
||||||
self.label = label
|
self.label = label
|
||||||
|
|
Loading…
Add table
Reference in a new issue