forked from shlomif/PySolFC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
labyrinth.py
133 lines (108 loc) · 3.96 KB
/
labyrinth.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env python
# -*- mode: python; coding: utf-8; -*-
# ---------------------------------------------------------------------------##
#
# 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.game import Game
from pysollib.layout import Layout
from pysollib.stack import \
BasicRowStack, \
DealRowTalonStack, \
SS_FoundationStack
# ************************************************************************
# * Labyrinth
# ************************************************************************
class Labyrinth_Talon(DealRowTalonStack):
def dealCards(self, sound=False):
top_stacks = []
for i in range(8):
for r in self.game.s.rows[i::8]:
if not r.cards:
top_stacks.append(r)
break
return self.dealRowAvail(rows=top_stacks, sound=sound)
class Labyrinth_RowStack(BasicRowStack):
def clickHandler(self, event):
BasicRowStack.doubleclickHandler(self, event)
return True
def basicIsBlocked(self):
if self in self.game.s.rows[:8]:
return False
if self.id+8 >= len(self.game.allstacks):
return False
r = self.game.allstacks[self.id+8]
if r in self.game.s.rows and r.cards:
return True
return False
class Labyrinth(Game):
#
# game layout
#
def createGame(self):
# create layout
l, s = Layout(self), self.s
# set window
self.setSize(l.XM+8*l.XS, l.YM+l.YS+20*l.YOFFSET)
# create stacks
s.talon = Labyrinth_Talon(l.XM, l.YM, self)
x, y, = l.XM+2*l.XS, l.YM
for i in range(4):
s.foundations.append(SS_FoundationStack(x, y, self, suit=i))
x += l.XS
x, y = l.XM, l.YM+l.YS
for i in range(6):
x = l.XM
for j in range(8):
s.rows.append(Labyrinth_RowStack(x, y, self, max_move=1))
x += l.XS
y += l.YOFFSET
# default
l.defaultAll()
#
# game overrides
#
def startGame(self):
self.startDealSample()
self.s.talon.dealRow(rows=self.s.foundations)
self.s.talon.dealRow(rows=self.s.rows[:8])
def _shuffleHook(self, cards):
return self._shuffleHookMoveToTop(
cards, lambda c: (c.rank == 0, c.suit))
def fillStack(self, stack):
if stack in self.s.rows[:8] and not stack.cards:
rows = self.s.rows
to_stack = stack
# if not self.demo:
# self.startDealSample()
old_state = self.enterState(self.S_FILL)
for r in rows[list(rows).index(stack)+8::8]:
if r.cards:
self.moveMove(1, r, to_stack, frames=0)
to_stack = r
else:
break
if not stack.cards and self.s.talon.cards:
self.s.talon.dealRow(rows=[stack])
self.leaveState(old_state)
# if not self.demo:
# self.stopSamples()
# register the game
# registerGame(GameInfo(400, Labyrinth, "Labyrinth",
# GI.GT_1DECK_TYPE, 1, 0))