summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2004-04-26 10:24:35 (UTC)
committer llornkcor <llornkcor>2004-04-26 10:24:35 (UTC)
commitf6a98984fcb0dfc7e176636560b7cc1adacf38f2 (patch) (unidiff)
treef358b16531551035a54c1dac95e16a36f86f8dc9
parent57d7f3faf053786925d2315e43ab6ba8d892f51a (diff)
downloadopie-f6a98984fcb0dfc7e176636560b7cc1adacf38f2.zip
opie-f6a98984fcb0dfc7e176636560b7cc1adacf38f2.tar.gz
opie-f6a98984fcb0dfc7e176636560b7cc1adacf38f2.tar.bz2
turn off silly casino rules solitare
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/solitaire/patiencecardgame.cpp13
-rw-r--r--noncore/games/solitaire/patiencecardgame.h31
2 files changed, 25 insertions, 19 deletions
diff --git a/noncore/games/solitaire/patiencecardgame.cpp b/noncore/games/solitaire/patiencecardgame.cpp
index 756577a..a1e4968 100644
--- a/noncore/games/solitaire/patiencecardgame.cpp
+++ b/noncore/games/solitaire/patiencecardgame.cpp
@@ -1,279 +1,288 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include "patiencecardgame.h" 20#include "patiencecardgame.h"
21 21
22 22
23int highestZ = 0; 23int highestZ = 0;
24 24
25 25
26PatienceCardGame::PatienceCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent) 26PatienceCardGame::PatienceCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent)
27{ 27{
28 numberOfTimesThroughDeck = 0; 28 numberOfTimesThroughDeck = 0;
29 highestZ = 0; 29 highestZ = 0;
30 30
31 if ( qt_screen->deviceWidth() < 200 ) 31 if ( qt_screen->deviceWidth() < 200 )
32 { 32 {
33 circleCross = new CanvasCircleOrCross( 7, 16, canvas() ); 33 circleCross = new CanvasCircleOrCross( 7, 16, canvas() );
34 rectangle = new CanvasRoundRect( 30, 10, canvas() ); 34 rectangle = new CanvasRoundRect( 30, 10, canvas() );
35 35
36 for (int i = 0; i < 4; i++) 36 for (int i = 0; i < 4; i++)
37 { 37 {
38 discardPiles[i] = new PatienceDiscardPile( 78 + i * 23, 10, canvas() ); 38 discardPiles[i] = new PatienceDiscardPile( 78 + i * 23, 10, canvas() );
39 addCardPile(discardPiles[i]); 39 addCardPile(discardPiles[i]);
40 } 40 }
41 for (int i = 0; i < 7; i++) 41 for (int i = 0; i < 7; i++)
42 { 42 {
43 workingPiles[i] = new PatienceWorkingPile( 5 + i * 23, 50, canvas() ); 43 workingPiles[i] = new PatienceWorkingPile( 5 + i * 23, 50, canvas() );
44 addCardPile(workingPiles[i]); 44 addCardPile(workingPiles[i]);
45 } 45 }
46 faceDownDealingPile = new PatienceFaceDownDeck( 5, 10, canvas() ); 46 faceDownDealingPile = new PatienceFaceDownDeck( 5, 10, canvas() );
47 faceUpDealingPile = new PatienceFaceUpDeck( 30, 10, canvas() ); 47 faceUpDealingPile = new PatienceFaceUpDeck( 30, 10, canvas() );
48 } 48 }
49 else 49 else
50 { 50 {
51 circleCross = new CanvasCircleOrCross( 7, 18, canvas() ); 51 circleCross = new CanvasCircleOrCross( 7, 18, canvas() );
52 rectangle = new CanvasRoundRect( 35, 10, canvas() ); 52 rectangle = new CanvasRoundRect( 35, 10, canvas() );
53 53
54 for (int i = 0; i < 4; i++) 54 for (int i = 0; i < 4; i++)
55 { 55 {
56 discardPiles[i] = new PatienceDiscardPile( 110 + i * 30, 10, canvas() ); 56 discardPiles[i] = new PatienceDiscardPile( 110 + i * 30, 10, canvas() );
57 addCardPile(discardPiles[i]); 57 addCardPile(discardPiles[i]);
58 } 58 }
59 for (int i = 0; i < 7; i++) 59 for (int i = 0; i < 7; i++)
60 { 60 {
61 workingPiles[i] = new PatienceWorkingPile( 10 + i * 30, 50, canvas() ); 61 workingPiles[i] = new PatienceWorkingPile( 10 + i * 30, 50, canvas() );
62 addCardPile(workingPiles[i]); 62 addCardPile(workingPiles[i]);
63 } 63 }
64 faceDownDealingPile = new PatienceFaceDownDeck( 5, 10, canvas() ); 64 faceDownDealingPile = new PatienceFaceDownDeck( 5, 10, canvas() );
65 faceUpDealingPile = new PatienceFaceUpDeck( 35, 10, canvas() ); 65 faceUpDealingPile = new PatienceFaceUpDeck( 35, 10, canvas() );
66 } 66 }
67} 67}
68 68
69 69
70PatienceCardGame::~PatienceCardGame() 70PatienceCardGame::~PatienceCardGame()
71{ 71{
72 delete circleCross; 72 delete circleCross;
73 delete rectangle; 73 delete rectangle;
74 delete faceDownDealingPile; 74 delete faceDownDealingPile;
75 delete faceUpDealingPile; 75 delete faceUpDealingPile;
76} 76}
77 77
78 78
79void PatienceCardGame::deal(void) 79void PatienceCardGame::deal(void)
80{ 80{
81 highestZ = 1; 81 highestZ = 1;
82 int t = 0; 82 int t = 0;
83 83
84 beginDealing(); 84 beginDealing();
85 85
86 for (int i = 0; i < 7; i++) 86 for (int i = 0; i < 7; i++)
87 { 87 {
88 cards[t]->setFace(TRUE); 88 cards[t]->setFace(TRUE);
89 for (int k = i; k < 7; k++, t++) 89 for (int k = i; k < 7; k++, t++)
90 { 90 {
91 Card *card = cards[t]; 91 Card *card = cards[t];
92 workingPiles[k]->addCardToTop(card); 92 workingPiles[k]->addCardToTop(card);
93 card->setCardPile( workingPiles[k] ); 93 card->setCardPile( workingPiles[k] );
94 QPoint p = workingPiles[k]->getCardPos( card ); 94 QPoint p = workingPiles[k]->getCardPos( card );
95 card->setPos( p.x(), p.y(), highestZ ); 95 card->setPos( p.x(), p.y(), highestZ );
96 card->showCard(); 96 card->showCard();
97 highestZ++; 97 highestZ++;
98 } 98 }
99 } 99 }
100 100
101 for ( ; t < 52; t++) 101 for ( ; t < 52; t++)
102 { 102 {
103 Card *card = cards[t]; 103 Card *card = cards[t];
104 faceDownDealingPile->addCardToTop(card); 104 faceDownDealingPile->addCardToTop(card);
105 card->setCardPile( faceDownDealingPile ); 105 card->setCardPile( faceDownDealingPile );
106 QPoint p = faceDownDealingPile->getCardPos( card ); 106 QPoint p = faceDownDealingPile->getCardPos( card );
107 card->setPos( p.x(), p.y(), highestZ ); 107 card->setPos( p.x(), p.y(), highestZ );
108 card->showCard(); 108 card->showCard();
109 highestZ++; 109 highestZ++;
110 } 110 }
111 111
112 endDealing(); 112 endDealing();
113} 113}
114 114
115 115
116void PatienceCardGame::readConfig( Config& cfg ) 116void PatienceCardGame::readConfig( Config& cfg )
117{ 117{
118 cfg.setGroup("GameState"); 118 cfg.setGroup("GameState");
119 119
120 deckTurns = cfg.readNumEntry("DeckTurns", 2500);
120 // Do we have a config file to read in? 121 // Do we have a config file to read in?
121 if ( !cfg.hasKey("numberOfTimesThroughDeck") ) 122 if ( !cfg.hasKey("numberOfTimesThroughDeck") ) {
122 {
123 // if not, create a new game 123 // if not, create a new game
124 newGame(); 124 newGame();
125 return; 125 return;
126 } 126 }
127 // We have a config file, lets read it in and use it 127 // We have a config file, lets read it in and use it
128 128
129 // Create Cards, but don't shuffle or deal them yet 129 // Create Cards, but don't shuffle or deal them yet
130 createDeck(); 130 createDeck();
131 131
132 // How many times through the deck have we been 132 // How many times through the deck have we been
133 numberOfTimesThroughDeck = cfg.readNumEntry("numberOfTimesThroughDeck"); 133 numberOfTimesThroughDeck = cfg.readNumEntry("numberOfTimesThroughDeck");
134 134
135 // restore state to the circle/cross under the dealing pile 135 // restore state to the circle/cross under the dealing pile
136 if ( canTurnOverDeck() ) 136 if ( canTurnOverDeck() )
137 circleCross->setCircle(); 137 circleCross->setCircle();
138 else 138 else
139 circleCross->setCross(); 139 circleCross->setCross();
140 140
141 // Move the cards to their piles (deal them to their previous places) 141 // Move the cards to their piles (deal them to their previous places)
142 beginDealing(); 142 beginDealing();
143 143
144 highestZ = 1; 144 highestZ = 1;
145 145
146 for (int k = 0; k < 7; k++) 146 for (int k = 0; k < 7; k++)
147 { 147 {
148 QString pile; 148 QString pile;
149 pile.sprintf( "WorkingPile%i", k ); 149 pile.sprintf( "WorkingPile%i", k );
150 readPile( cfg, workingPiles[k], pile, highestZ ); 150 readPile( cfg, workingPiles[k], pile, highestZ );
151 } 151 }
152 152
153 for (int k = 0; k < 4; k++) 153 for (int k = 0; k < 4; k++)
154 { 154 {
155 QString pile; 155 QString pile;
156 pile.sprintf( "DiscardPile%i", k ); 156 pile.sprintf( "DiscardPile%i", k );
157 readPile( cfg, discardPiles[k], pile, highestZ ); 157 readPile( cfg, discardPiles[k], pile, highestZ );
158 } 158 }
159 159
160 readPile( cfg, faceDownDealingPile, "FaceDownDealingPile", highestZ ); 160 readPile( cfg, faceDownDealingPile, "FaceDownDealingPile", highestZ );
161 readPile( cfg, faceUpDealingPile, "FaceUpDealingPile", highestZ ); 161 readPile( cfg, faceUpDealingPile, "FaceUpDealingPile", highestZ );
162 162
163 highestZ++; 163 highestZ++;
164 164
165 endDealing(); 165 endDealing();
166} 166}
167 167
168 168
169void PatienceCardGame::writeConfig( Config& cfg ) 169void PatienceCardGame::writeConfig( Config& cfg )
170{ 170{
171 cfg.setGroup("GameState"); 171 cfg.setGroup("GameState");
172 cfg.writeEntry("numberOfTimesThroughDeck", numberOfTimesThroughDeck); 172 cfg.writeEntry("numberOfTimesThroughDeck", numberOfTimesThroughDeck);
173 173
174 for ( int i = 0; i < 7; i++ ) 174 for ( int i = 0; i < 7; i++ )
175 { 175 {
176 QString pile; 176 QString pile;
177 pile.sprintf( "WorkingPile%i", i ); 177 pile.sprintf( "WorkingPile%i", i );
178 workingPiles[i]->writeConfig( cfg, pile ); 178 workingPiles[i]->writeConfig( cfg, pile );
179 } 179 }
180 for ( int i = 0; i < 4; i++ ) 180 for ( int i = 0; i < 4; i++ )
181 { 181 {
182 QString pile; 182 QString pile;
183 pile.sprintf( "DiscardPile%i", i ); 183 pile.sprintf( "DiscardPile%i", i );
184 discardPiles[i]->writeConfig( cfg, pile ); 184 discardPiles[i]->writeConfig( cfg, pile );
185 } 185 }
186 faceDownDealingPile->writeConfig( cfg, "FaceDownDealingPile" ); 186 faceDownDealingPile->writeConfig( cfg, "FaceDownDealingPile" );
187 faceUpDealingPile->writeConfig( cfg, "FaceUpDealingPile" ); 187 faceUpDealingPile->writeConfig( cfg, "FaceUpDealingPile" );
188} 188}
189 189
190 190
191bool PatienceCardGame::mousePressCard( Card *card, QPoint p ) 191bool PatienceCardGame::mousePressCard( Card *card, QPoint p )
192{ 192{
193 Q_UNUSED(p); 193 Q_UNUSED(p);
194 194
195 CanvasCard *item = (CanvasCard *)card; 195 CanvasCard *item = (CanvasCard *)card;
196 if (item->isFacing() != TRUE) 196 if (item->isFacing() != TRUE)
197 { 197 {
198 // From facedown stack 198 // From facedown stack
199 if ((item->x() == 5) && ((int)item->y() == 10)) 199 if ((item->x() == 5) && ((int)item->y() == 10))
200 { 200 {
201 item->setZ(highestZ); 201 item->setZ(highestZ);
202 highestZ++; 202 highestZ++;
203 203
204 // Added Code 204 // Added Code
205 faceDownDealingPile->removeCard(item); 205 faceDownDealingPile->removeCard(item);
206 faceUpDealingPile->addCardToTop(item); 206 faceUpDealingPile->addCardToTop(item);
207 item->setCardPile( faceUpDealingPile ); 207 item->setCardPile( faceUpDealingPile );
208 208
209 if ( qt_screen->deviceWidth() < 200 ) 209 if ( qt_screen->deviceWidth() < 200 )
210 item->flipTo( 30, (int)item->y() ); 210 item->flipTo( 30, (int)item->y() );
211 else 211 else
212 item->flipTo( 35, (int)item->y() ); 212 item->flipTo( 35, (int)item->y() );
213 } 213 }
214 else return FALSE; // <- was missing, caused facedown card to react 214 else return FALSE; // <- was missing, caused facedown card to react
215 // to clicking, which is wrong 215 // to clicking, which is wrong
216 moving = NULL; 216 moving = NULL;
217 moved = FALSE; 217 moved = FALSE;
218 218
219 // move two other cards if we flip three at a time 219 // move two other cards if we flip three at a time
220 int flipped = 1; 220 int flipped = 1;
221 QCanvasItemList l = canvas()->collisions( p ); 221 QCanvasItemList l = canvas()->collisions( p );
222 for (QCanvasItemList::Iterator it = l.begin(); (it != l.end()) && (flipped != cardsDrawn()); ++it) 222 for (QCanvasItemList::Iterator it = l.begin(); (it != l.end()) && (flipped != cardsDrawn()); ++it)
223 { 223 {
224 if ( (*it)->rtti() == canvasCardId ) 224 if ( (*it)->rtti() == canvasCardId )
225 { 225 {
226 CanvasCard *item = (CanvasCard *)*it; 226 CanvasCard *item = (CanvasCard *)*it;
227 if (item->animated()) 227 if (item->animated())
228 continue; 228 continue;
229 item->setZ(highestZ); 229 item->setZ(highestZ);
230 highestZ++; 230 highestZ++;
231 flipped++; 231 flipped++;
232 232
233 // Added Code 233 // Added Code
234 faceDownDealingPile->removeCard(item); 234 faceDownDealingPile->removeCard(item);
235 faceUpDealingPile->addCardToTop(item); 235 faceUpDealingPile->addCardToTop(item);
236 item->setCardPile( faceUpDealingPile ); 236 item->setCardPile( faceUpDealingPile );
237 237
238 if ( qt_screen->deviceWidth() < 200 ) 238 if ( qt_screen->deviceWidth() < 200 )
239 item->flipTo( 30, (int)item->y(), 8 * flipped ); 239 item->flipTo( 30, (int)item->y(), 8 * flipped );
240 else 240 else
241 item->flipTo( 35, (int)item->y(), 8 * flipped ); 241 item->flipTo( 35, (int)item->y(), 8 * flipped );
242 } 242 }
243 } 243 }
244 244
245 return TRUE; 245 return TRUE;
246 } 246 }
247 247
248 return FALSE; 248 return FALSE;
249} 249}
250 250
251 251
252void PatienceCardGame::mousePress(QPoint p) 252void PatienceCardGame::mousePress(QPoint p)
253{ 253{
254 if ( canTurnOverDeck() && 254 if ( canTurnOverDeck() &&
255 (p.x() > 5) && (p.x() < 28) && 255 (p.x() > 5) && (p.x() < 28) &&
256 (p.y() > 10) && (p.y() < 46) ) 256 (p.y() > 10) && (p.y() < 46) )
257 { 257 {
258 258
259 beginDealing(); 259 beginDealing();
260 Card *card = faceUpDealingPile->cardOnTop(); 260 Card *card = faceUpDealingPile->cardOnTop();
261 while ( card ) 261 while ( card )
262 { 262 {
263 card->setPos( 5, 10, highestZ ); 263 card->setPos( 5, 10, highestZ );
264 card->setFace( FALSE ); 264 card->setFace( FALSE );
265 faceUpDealingPile->removeCard( card ); 265 faceUpDealingPile->removeCard( card );
266 faceDownDealingPile->addCardToTop( card ); 266 faceDownDealingPile->addCardToTop( card );
267 card->setCardPile( faceDownDealingPile ); 267 card->setCardPile( faceDownDealingPile );
268 card = faceUpDealingPile->cardOnTop(); 268 card = faceUpDealingPile->cardOnTop();
269 highestZ++; 269 highestZ++;
270 } 270 }
271 endDealing(); 271 endDealing();
272 272
273 throughDeck(); 273 throughDeck();
274 274
275 moved = TRUE; 275 moved = TRUE;
276 } 276 }
277} 277}
278 278
279 279
280bool PatienceCardGame::canTurnOverDeck() {
281 return (numberOfTimesThroughDeck != deckTurns);
282}
283
284void PatienceCardGame::throughDeck() {
285 numberOfTimesThroughDeck++;
286 if (numberOfTimesThroughDeck == deckTurns)
287 circleCross->setCross();
288 }
diff --git a/noncore/games/solitaire/patiencecardgame.h b/noncore/games/solitaire/patiencecardgame.h
index 0d0e3d5..b76251a 100644
--- a/noncore/games/solitaire/patiencecardgame.h
+++ b/noncore/games/solitaire/patiencecardgame.h
@@ -1,209 +1,206 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef PATIENCE_CARD_GAME_H 20#ifndef PATIENCE_CARD_GAME_H
21#define PATIENCE_CARD_GAME_H 21#define PATIENCE_CARD_GAME_H
22 22
23 23
24#include <qpopupmenu.h> 24#include <qpopupmenu.h>
25#include <qmainwindow.h> 25#include <qmainwindow.h>
26#include <qintdict.h> 26#include <qintdict.h>
27#include <qcanvas.h> 27#include <qcanvas.h>
28#include <qgfx_qws.h> 28#include <qgfx_qws.h>
29// #include "canvascardshapes.h" 29// #include "canvascardshapes.h"
30// #include "canvascard.h" 30// #include "canvascard.h"
31#include "canvascardgame.h" 31#include "canvascardgame.h"
32 32
33 33
34class PatienceFaceDownDeck : public CardPile, public CanvasRoundRect 34class PatienceFaceDownDeck : public CardPile, public CanvasRoundRect
35{ 35{
36public: 36public:
37 PatienceFaceDownDeck(int x, int y, QCanvas *canvas) 37 PatienceFaceDownDeck(int x, int y, QCanvas *canvas)
38 : CardPile(x, y), CanvasRoundRect(x, y, canvas) { } 38 : CardPile(x, y), CanvasRoundRect(x, y, canvas) { }
39 virtual bool isAllowedOnTop(Card *card) { 39 virtual bool isAllowedOnTop(Card *card) {
40 Q_UNUSED(card); 40 Q_UNUSED(card);
41 // Need to check it is from the faceUpDealingPile 41 // Need to check it is from the faceUpDealingPile
42 return TRUE; 42 return TRUE;
43 } 43 }
44 virtual bool isAllowedToBeMoved(Card *card) { 44 virtual bool isAllowedToBeMoved(Card *card) {
45 Q_UNUSED(card); 45 Q_UNUSED(card);
46 //if ( ( !card->isFacing() ) && ( card == cardOnTop() ) ) 46 //if ( ( !card->isFacing() ) && ( card == cardOnTop() ) )
47 if ( card == cardOnTop() ) 47 if ( card == cardOnTop() )
48 return TRUE; 48 return TRUE;
49 return FALSE; 49 return FALSE;
50 } 50 }
51}; 51};
52 52
53 53
54class PatienceFaceUpDeck : public CardPile, public CanvasRoundRect 54class PatienceFaceUpDeck : public CardPile, public CanvasRoundRect
55{ 55{
56public: 56public:
57 PatienceFaceUpDeck(int x, int y, QCanvas *canvas) 57 PatienceFaceUpDeck(int x, int y, QCanvas *canvas)
58 : CardPile(x, y), CanvasRoundRect(x, y, canvas) { } 58 : CardPile(x, y), CanvasRoundRect(x, y, canvas) { }
59 virtual bool isAllowedOnTop(Card *card) { 59 virtual bool isAllowedOnTop(Card *card) {
60 Q_UNUSED(card); 60 Q_UNUSED(card);
61 // Need to check it is from the faceDownDealingPile 61 // Need to check it is from the faceDownDealingPile
62 return TRUE; 62 return TRUE;
63 } 63 }
64 virtual bool isAllowedToBeMoved(Card *card) { 64 virtual bool isAllowedToBeMoved(Card *card) {
65 Q_UNUSED(card); 65 Q_UNUSED(card);
66 //if ( ( card->isFacing() ) && ( card == cardOnTop() ) ) 66 //if ( ( card->isFacing() ) && ( card == cardOnTop() ) )
67 if ( card == cardOnTop() ) 67 if ( card == cardOnTop() )
68 return TRUE; 68 return TRUE;
69 return FALSE; 69 return FALSE;
70 } 70 }
71}; 71};
72 72
73 73
74class PatienceDiscardPile : public CardPile, public CanvasRoundRect 74class PatienceDiscardPile : public CardPile, public CanvasRoundRect
75{ 75{
76public: 76public:
77 PatienceDiscardPile(int x, int y, QCanvas *canvas) 77 PatienceDiscardPile(int x, int y, QCanvas *canvas)
78 : CardPile(x, y), CanvasRoundRect(x, y, canvas) { } 78 : CardPile(x, y), CanvasRoundRect(x, y, canvas) { }
79 virtual bool isAllowedOnTop(Card *card) { 79 virtual bool isAllowedOnTop(Card *card) {
80 if ( card->isFacing() && ( card->getCardPile()->cardInfront(card) == NULL ) && 80 if ( card->isFacing() && ( card->getCardPile()->cardInfront(card) == NULL ) &&
81 ( ( ( cardOnTop() == NULL ) && ( card->getValue() == ace ) ) || 81 ( ( ( cardOnTop() == NULL ) && ( card->getValue() == ace ) ) ||
82 ( ( cardOnTop() != NULL ) && 82 ( ( cardOnTop() != NULL ) &&
83 ( (int)card->getValue() == (int)cardOnTop()->getValue() + 1 ) && 83 ( (int)card->getValue() == (int)cardOnTop()->getValue() + 1 ) &&
84 ( card->getSuit() == cardOnTop()->getSuit() ) ) ) ) 84 ( card->getSuit() == cardOnTop()->getSuit() ) ) ) )
85 return TRUE; 85 return TRUE;
86 return FALSE; 86 return FALSE;
87 } 87 }
88 virtual bool isAllowedToBeMoved(Card *card) { 88 virtual bool isAllowedToBeMoved(Card *card) {
89 if ( card->isFacing() && ( card == cardOnTop() ) ) 89 if ( card->isFacing() && ( card == cardOnTop() ) )
90 return TRUE; 90 return TRUE;
91 return FALSE; 91 return FALSE;
92 } 92 }
93}; 93};
94 94
95 95
96class PatienceWorkingPile : public CardPile, public CanvasRoundRect 96class PatienceWorkingPile : public CardPile, public CanvasRoundRect
97{ 97{
98public: 98public:
99 PatienceWorkingPile(int x, int y, QCanvas *canvas) 99 PatienceWorkingPile(int x, int y, QCanvas *canvas)
100 : CardPile(x, y), CanvasRoundRect(x, y, canvas), top(x, y) { } 100 : CardPile(x, y), CanvasRoundRect(x, y, canvas), top(x, y) { }
101 virtual bool isAllowedOnTop(Card *card) { 101 virtual bool isAllowedOnTop(Card *card) {
102 if ( card->isFacing() && 102 if ( card->isFacing() &&
103 ( ( ( cardOnTop() == NULL ) && (card->getValue() == king) ) || 103 ( ( ( cardOnTop() == NULL ) && (card->getValue() == king) ) ||
104 ( ( cardOnTop() != NULL ) && 104 ( ( cardOnTop() != NULL ) &&
105 ( (int)card->getValue() + 1 == (int)cardOnTop()->getValue() ) && 105 ( (int)card->getValue() + 1 == (int)cardOnTop()->getValue() ) &&
106 ( card->isRed() != cardOnTop()->isRed() ) ) ) ) 106 ( card->isRed() != cardOnTop()->isRed() ) ) ) )
107 return TRUE; 107 return TRUE;
108 return FALSE; 108 return FALSE;
109 } 109 }
110 virtual bool isAllowedToBeMoved(Card *card) { 110 virtual bool isAllowedToBeMoved(Card *card) {
111 if ( card->isFacing() ) 111 if ( card->isFacing() )
112 return TRUE; 112 return TRUE;
113 return FALSE; 113 return FALSE;
114 } 114 }
115 virtual void cardAddedToTop(Card *card) { 115 virtual void cardAddedToTop(Card *card) {
116 Q_UNUSED(card); 116 Q_UNUSED(card);
117 top = getCardPos(NULL); 117 top = getCardPos(NULL);
118 setNextX( top.x() ); 118 setNextX( top.x() );
119 setNextY( top.y() ); 119 setNextY( top.y() );
120 } 120 }
121 virtual void cardRemoved(Card *card) { 121 virtual void cardRemoved(Card *card) {
122 Q_UNUSED(card); 122 Q_UNUSED(card);
123 123
124 Card *newTopCard = cardOnTop(); 124 Card *newTopCard = cardOnTop();
125 125
126 if ( !newTopCard ) { 126 if ( !newTopCard ) {
127 top = QPoint( pileX, pileY ); 127 top = QPoint( pileX, pileY );
128 setNextX( pileX ); 128 setNextX( pileX );
129 setNextY( pileY ); 129 setNextY( pileY );
130 return; 130 return;
131 } else { 131 } else {
132 top = getCardPos(NULL); 132 top = getCardPos(NULL);
133 if ( newTopCard->isFacing() == FALSE ) { 133 if ( newTopCard->isFacing() == FALSE ) {
134 int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13; 134 int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13;
135 // correct the position taking in to account the card is not 135 // correct the position taking in to account the card is not
136 // yet flipped, but will become flipped 136 // yet flipped, but will become flipped
137 top = QPoint( top.x() - 1, top.y() - 3 ); 137 top = QPoint( top.x() - 1, top.y() - 3 );
138 newTopCard->flipTo( top.x(), top.y() ); 138 newTopCard->flipTo( top.x(), top.y() );
139 top = QPoint( top.x(), top.y() + offsetDown ); 139 top = QPoint( top.x(), top.y() + offsetDown );
140 } 140 }
141 setNextX( top.x() ); 141 setNextX( top.x() );
142 setNextY( top.y() ); 142 setNextY( top.y() );
143 } 143 }
144 } 144 }
145 virtual QPoint getCardPos(Card *c) { 145 virtual QPoint getCardPos(Card *c) {
146 int x = pileX, y = pileY; 146 int x = pileX, y = pileY;
147 Card *card = cardOnBottom(); 147 Card *card = cardOnBottom();
148 while ((card != c) && (card != NULL)) { 148 while ((card != c) && (card != NULL)) {
149 if (card->isFacing()) { 149 if (card->isFacing()) {
150 int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13; 150 int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13;
151 y += offsetDown; 151 y += offsetDown;
152 } else { 152 } else {
153 x += 1; 153 x += 1;
154 y += 3; 154 y += 3;
155 } 155 }
156 card = cardInfront(card); 156 card = cardInfront(card);
157 } 157 }
158 return QPoint( x, y ); 158 return QPoint( x, y );
159 } 159 }
160 virtual QPoint getHypertheticalNextCardPos(void) { 160 virtual QPoint getHypertheticalNextCardPos(void) {
161 return top; 161 return top;
162 // return QPoint( getNextX(), getNextY() ); 162 // return QPoint( getNextX(), getNextY() );
163 } 163 }
164private: 164private:
165 QPoint top; 165 QPoint top;
166 166
167}; 167};
168 168
169 169
170class PatienceCardGame : public CanvasCardGame 170class PatienceCardGame : public CanvasCardGame
171{ 171{
172public: 172public:
173 PatienceCardGame(QCanvas *c, bool snap, QWidget *parent = 0); 173 PatienceCardGame(QCanvas *c, bool snap, QWidget *parent = 0);
174 virtual ~PatienceCardGame(); 174 virtual ~PatienceCardGame();
175 virtual void deal(void); 175 virtual void deal(void);
176 virtual bool haveWeWon() { 176 int deckTurns;
177 virtual bool haveWeWon() {
177 return ( discardPiles[0]->kingOnTop() && 178 return ( discardPiles[0]->kingOnTop() &&
178 discardPiles[1]->kingOnTop() && 179 discardPiles[1]->kingOnTop() &&
179 discardPiles[2]->kingOnTop() && 180 discardPiles[2]->kingOnTop() &&
180 discardPiles[3]->kingOnTop() );; 181 discardPiles[3]->kingOnTop() );;
181 } 182 }
182 virtual void mousePress(QPoint p); 183 virtual void mousePress(QPoint p);
183 virtual void mouseRelease(QPoint p) { Q_UNUSED(p); } 184 virtual void mouseRelease(QPoint p) { Q_UNUSED(p); }
184// virtual void mouseMove(QPoint p); 185// virtual void mouseMove(QPoint p);
185 virtual bool mousePressCard(Card *card, QPoint p); 186 virtual bool mousePressCard(Card *card, QPoint p);
186 virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); } 187 virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); }
187// virtual void mouseMoveCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); } 188// virtual void mouseMoveCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); }
188 bool canTurnOverDeck(void) { return (numberOfTimesThroughDeck != 3); } 189 bool canTurnOverDeck();
189 void throughDeck(void) { 190 void throughDeck();
190 numberOfTimesThroughDeck++;
191 if (numberOfTimesThroughDeck == 3)
192 circleCross->setCross();
193 }
194 bool snapOn; 191 bool snapOn;
195 virtual void writeConfig( Config& cfg ); 192 virtual void writeConfig( Config& cfg );
196 virtual void readConfig( Config& cfg ); 193 virtual void readConfig( Config& cfg );
197private: 194private:
198 CanvasCircleOrCross *circleCross; 195 CanvasCircleOrCross *circleCross;
199 CanvasRoundRect *rectangle; 196 CanvasRoundRect *rectangle;
200 PatienceWorkingPile *workingPiles[7]; 197 PatienceWorkingPile *workingPiles[7];
201 PatienceDiscardPile *discardPiles[4]; 198 PatienceDiscardPile *discardPiles[4];
202 PatienceFaceDownDeck *faceDownDealingPile; 199 PatienceFaceDownDeck *faceDownDealingPile;
203 PatienceFaceUpDeck *faceUpDealingPile; 200 PatienceFaceUpDeck *faceUpDealingPile;
204 int numberOfTimesThroughDeck; 201 int numberOfTimesThroughDeck;
205}; 202};
206 203
207 204
208#endif 205#endif
209 206