summaryrefslogtreecommitdiff
authorar <ar>2004-06-03 21:13:20 (UTC)
committer ar <ar>2004-06-03 21:13:20 (UTC)
commit9f12abfa6b60232592aa15feea25bee28908f525 (patch) (unidiff)
treeaf16be15cd597cdf01d8476f478f3bbe7dc81509
parent52f849d3031f9d2fad2272ad069e7a1456c0ee54 (diff)
downloadopie-9f12abfa6b60232592aa15feea25bee28908f525.zip
opie-9f12abfa6b60232592aa15feea25bee28908f525.tar.gz
opie-9f12abfa6b60232592aa15feea25bee28908f525.tar.bz2
- turn on casino rules in solitare (make it eventually configurable)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/solitaire/patiencecardgame.cpp26
1 files changed, 15 insertions, 11 deletions
diff --git a/noncore/games/solitaire/patiencecardgame.cpp b/noncore/games/solitaire/patiencecardgame.cpp
index a1e4968..00448ad 100644
--- a/noncore/games/solitaire/patiencecardgame.cpp
+++ b/noncore/games/solitaire/patiencecardgame.cpp
@@ -1,288 +1,292 @@
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
20#include "patiencecardgame.h" 21#include "patiencecardgame.h"
21 22
22 23
23int highestZ = 0; 24int highestZ = 0;
24 25
25 26
26PatienceCardGame::PatienceCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent) 27PatienceCardGame::PatienceCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent)
27{ 28{
28 numberOfTimesThroughDeck = 0; 29 numberOfTimesThroughDeck = 0;
29 highestZ = 0; 30 highestZ = 0;
30 31
31 if ( qt_screen->deviceWidth() < 200 ) 32 if ( qt_screen->deviceWidth() < 200 )
32 { 33 {
33 circleCross = new CanvasCircleOrCross( 7, 16, canvas() ); 34 circleCross = new CanvasCircleOrCross( 7, 16, canvas() );
34 rectangle = new CanvasRoundRect( 30, 10, canvas() ); 35 rectangle = new CanvasRoundRect( 30, 10, canvas() );
35 36
36 for (int i = 0; i < 4; i++) 37 for (int i = 0; i < 4; i++)
37 { 38 {
38 discardPiles[i] = new PatienceDiscardPile( 78 + i * 23, 10, canvas() ); 39 discardPiles[i] = new PatienceDiscardPile( 78 + i * 23, 10, canvas() );
39 addCardPile(discardPiles[i]); 40 addCardPile(discardPiles[i]);
40 } 41 }
41 for (int i = 0; i < 7; i++) 42 for (int i = 0; i < 7; i++)
42 { 43 {
43 workingPiles[i] = new PatienceWorkingPile( 5 + i * 23, 50, canvas() ); 44 workingPiles[i] = new PatienceWorkingPile( 5 + i * 23, 50, canvas() );
44 addCardPile(workingPiles[i]); 45 addCardPile(workingPiles[i]);
45 } 46 }
46 faceDownDealingPile = new PatienceFaceDownDeck( 5, 10, canvas() ); 47 faceDownDealingPile = new PatienceFaceDownDeck( 5, 10, canvas() );
47 faceUpDealingPile = new PatienceFaceUpDeck( 30, 10, canvas() ); 48 faceUpDealingPile = new PatienceFaceUpDeck( 30, 10, canvas() );
48 } 49 }
49 else 50 else
50 { 51 {
51 circleCross = new CanvasCircleOrCross( 7, 18, canvas() ); 52 circleCross = new CanvasCircleOrCross( 7, 18, canvas() );
52 rectangle = new CanvasRoundRect( 35, 10, canvas() ); 53 rectangle = new CanvasRoundRect( 35, 10, canvas() );
53 54
54 for (int i = 0; i < 4; i++) 55 for (int i = 0; i < 4; i++)
55 { 56 {
56 discardPiles[i] = new PatienceDiscardPile( 110 + i * 30, 10, canvas() ); 57 discardPiles[i] = new PatienceDiscardPile( 110 + i * 30, 10, canvas() );
57 addCardPile(discardPiles[i]); 58 addCardPile(discardPiles[i]);
58 } 59 }
59 for (int i = 0; i < 7; i++) 60 for (int i = 0; i < 7; i++)
60 { 61 {
61 workingPiles[i] = new PatienceWorkingPile( 10 + i * 30, 50, canvas() ); 62 workingPiles[i] = new PatienceWorkingPile( 10 + i * 30, 50, canvas() );
62 addCardPile(workingPiles[i]); 63 addCardPile(workingPiles[i]);
63 } 64 }
64 faceDownDealingPile = new PatienceFaceDownDeck( 5, 10, canvas() ); 65 faceDownDealingPile = new PatienceFaceDownDeck( 5, 10, canvas() );
65 faceUpDealingPile = new PatienceFaceUpDeck( 35, 10, canvas() ); 66 faceUpDealingPile = new PatienceFaceUpDeck( 35, 10, canvas() );
66 } 67 }
67} 68}
68 69
69 70
70PatienceCardGame::~PatienceCardGame() 71PatienceCardGame::~PatienceCardGame()
71{ 72{
72 delete circleCross; 73 delete circleCross;
73 delete rectangle; 74 delete rectangle;
74 delete faceDownDealingPile; 75 delete faceDownDealingPile;
75 delete faceUpDealingPile; 76 delete faceUpDealingPile;
76} 77}
77 78
78 79
79void PatienceCardGame::deal(void) 80void PatienceCardGame::deal(void)
80{ 81{
81 highestZ = 1; 82 highestZ = 1;
82 int t = 0; 83 int t = 0;
83 84
84 beginDealing(); 85 beginDealing();
85 86
86 for (int i = 0; i < 7; i++) 87 for (int i = 0; i < 7; i++)
87 { 88 {
88 cards[t]->setFace(TRUE); 89 cards[t]->setFace(TRUE);
89 for (int k = i; k < 7; k++, t++) 90 for (int k = i; k < 7; k++, t++)
90 { 91 {
91 Card *card = cards[t]; 92 Card *card = cards[t];
92 workingPiles[k]->addCardToTop(card); 93 workingPiles[k]->addCardToTop(card);
93 card->setCardPile( workingPiles[k] ); 94 card->setCardPile( workingPiles[k] );
94 QPoint p = workingPiles[k]->getCardPos( card ); 95 QPoint p = workingPiles[k]->getCardPos( card );
95 card->setPos( p.x(), p.y(), highestZ ); 96 card->setPos( p.x(), p.y(), highestZ );
96 card->showCard(); 97 card->showCard();
97 highestZ++; 98 highestZ++;
98 } 99 }
99 } 100 }
100 101
101 for ( ; t < 52; t++) 102 for ( ; t < 52; t++)
102 { 103 {
103 Card *card = cards[t]; 104 Card *card = cards[t];
104 faceDownDealingPile->addCardToTop(card); 105 faceDownDealingPile->addCardToTop(card);
105 card->setCardPile( faceDownDealingPile ); 106 card->setCardPile( faceDownDealingPile );
106 QPoint p = faceDownDealingPile->getCardPos( card ); 107 QPoint p = faceDownDealingPile->getCardPos( card );
107 card->setPos( p.x(), p.y(), highestZ ); 108 card->setPos( p.x(), p.y(), highestZ );
108 card->showCard(); 109 card->showCard();
109 highestZ++; 110 highestZ++;
110 } 111 }
111 112
112 endDealing(); 113 endDealing();
113} 114}
114 115
115 116
116void PatienceCardGame::readConfig( Config& cfg ) 117void PatienceCardGame::readConfig( Config& cfg )
117{ 118{
118 cfg.setGroup("GameState"); 119 cfg.setGroup("GameState");
119 120
120 deckTurns = cfg.readNumEntry("DeckTurns", 2500); 121 // todo: make this eventually configurable
122 deckTurns = cfg.readNumEntry("DeckTurns", 2);
121 // Do we have a config file to read in? 123 // Do we have a config file to read in?
122 if ( !cfg.hasKey("numberOfTimesThroughDeck") ) { 124 if ( !cfg.hasKey("numberOfTimesThroughDeck") )
125 {
123 // if not, create a new game 126 // if not, create a new game
124 newGame(); 127 newGame();
125 return; 128 return;
126 } 129 }
127 // We have a config file, lets read it in and use it 130 // We have a config file, lets read it in and use it
128 131
129 // Create Cards, but don't shuffle or deal them yet 132 // Create Cards, but don't shuffle or deal them yet
130 createDeck(); 133 createDeck();
131 134
132 // How many times through the deck have we been 135 // How many times through the deck have we been
133 numberOfTimesThroughDeck = cfg.readNumEntry("numberOfTimesThroughDeck"); 136 numberOfTimesThroughDeck = cfg.readNumEntry("numberOfTimesThroughDeck");
134 137
135 // restore state to the circle/cross under the dealing pile 138 // restore state to the circle/cross under the dealing pile
136 if ( canTurnOverDeck() ) 139 if ( canTurnOverDeck() )
137 circleCross->setCircle(); 140 circleCross->setCircle();
138 else 141 else
139 circleCross->setCross(); 142 circleCross->setCross();
140 143
141 // Move the cards to their piles (deal them to their previous places) 144 // Move the cards to their piles (deal them to their previous places)
142 beginDealing(); 145 beginDealing();
143 146
144 highestZ = 1; 147 highestZ = 1;
145 148
146 for (int k = 0; k < 7; k++) 149 for (int k = 0; k < 7; k++)
147 { 150 {
148 QString pile; 151 QString pile;
149 pile.sprintf( "WorkingPile%i", k ); 152 pile.sprintf( "WorkingPile%i", k );
150 readPile( cfg, workingPiles[k], pile, highestZ ); 153 readPile( cfg, workingPiles[k], pile, highestZ );
151 } 154 }
152 155
153 for (int k = 0; k < 4; k++) 156 for (int k = 0; k < 4; k++)
154 { 157 {
155 QString pile; 158 QString pile;
156 pile.sprintf( "DiscardPile%i", k ); 159 pile.sprintf( "DiscardPile%i", k );
157 readPile( cfg, discardPiles[k], pile, highestZ ); 160 readPile( cfg, discardPiles[k], pile, highestZ );
158 } 161 }
159 162
160 readPile( cfg, faceDownDealingPile, "FaceDownDealingPile", highestZ ); 163 readPile( cfg, faceDownDealingPile, "FaceDownDealingPile", highestZ );
161 readPile( cfg, faceUpDealingPile, "FaceUpDealingPile", highestZ ); 164 readPile( cfg, faceUpDealingPile, "FaceUpDealingPile", highestZ );
162 165
163 highestZ++; 166 highestZ++;
164 167
165 endDealing(); 168 endDealing();
166} 169}
167 170
168 171
169void PatienceCardGame::writeConfig( Config& cfg ) 172void PatienceCardGame::writeConfig( Config& cfg )
170{ 173{
171 cfg.setGroup("GameState"); 174 cfg.setGroup("GameState");
172 cfg.writeEntry("numberOfTimesThroughDeck", numberOfTimesThroughDeck); 175 cfg.writeEntry("numberOfTimesThroughDeck", numberOfTimesThroughDeck);
173 176
174 for ( int i = 0; i < 7; i++ ) 177 for ( int i = 0; i < 7; i++ )
175 { 178 {
176 QString pile; 179 QString pile;
177 pile.sprintf( "WorkingPile%i", i ); 180 pile.sprintf( "WorkingPile%i", i );
178 workingPiles[i]->writeConfig( cfg, pile ); 181 workingPiles[i]->writeConfig( cfg, pile );
179 } 182 }
180 for ( int i = 0; i < 4; i++ ) 183 for ( int i = 0; i < 4; i++ )
181 { 184 {
182 QString pile; 185 QString pile;
183 pile.sprintf( "DiscardPile%i", i ); 186 pile.sprintf( "DiscardPile%i", i );
184 discardPiles[i]->writeConfig( cfg, pile ); 187 discardPiles[i]->writeConfig( cfg, pile );
185 } 188 }
186 faceDownDealingPile->writeConfig( cfg, "FaceDownDealingPile" ); 189 faceDownDealingPile->writeConfig( cfg, "FaceDownDealingPile" );
187 faceUpDealingPile->writeConfig( cfg, "FaceUpDealingPile" ); 190 faceUpDealingPile->writeConfig( cfg, "FaceUpDealingPile" );
188} 191}
189 192
190 193
191bool PatienceCardGame::mousePressCard( Card *card, QPoint p ) 194bool PatienceCardGame::mousePressCard( Card *card, QPoint p )
192{ 195{
193 Q_UNUSED(p); 196 Q_UNUSED(p);
194 197
195 CanvasCard *item = (CanvasCard *)card; 198 CanvasCard *item = (CanvasCard *)card;
196 if (item->isFacing() != TRUE) 199 if (item->isFacing() != TRUE)
197 { 200 {
198 // From facedown stack 201 // From facedown stack
199 if ((item->x() == 5) && ((int)item->y() == 10)) 202 if ((item->x() == 5) && ((int)item->y() == 10))
200 { 203 {
201 item->setZ(highestZ); 204 item->setZ(highestZ);
202 highestZ++; 205 highestZ++;
203 206
204 // Added Code 207 // Added Code
205 faceDownDealingPile->removeCard(item); 208 faceDownDealingPile->removeCard(item);
206 faceUpDealingPile->addCardToTop(item); 209 faceUpDealingPile->addCardToTop(item);
207 item->setCardPile( faceUpDealingPile ); 210 item->setCardPile( faceUpDealingPile );
208 211
209 if ( qt_screen->deviceWidth() < 200 ) 212 if ( qt_screen->deviceWidth() < 200 )
210 item->flipTo( 30, (int)item->y() ); 213 item->flipTo( 30, (int)item->y() );
211 else 214 else
212 item->flipTo( 35, (int)item->y() ); 215 item->flipTo( 35, (int)item->y() );
213 } 216 }
214 else return FALSE; // <- was missing, caused facedown card to react 217 else return FALSE; // <- was missing, caused facedown card to react
215 // to clicking, which is wrong 218 // to clicking, which is wrong
216 moving = NULL; 219 moving = NULL;
217 moved = FALSE; 220 moved = FALSE;
218 221
219 // move two other cards if we flip three at a time 222 // move two other cards if we flip three at a time
220 int flipped = 1; 223 int flipped = 1;
221 QCanvasItemList l = canvas()->collisions( p ); 224 QCanvasItemList l = canvas()->collisions( p );
222 for (QCanvasItemList::Iterator it = l.begin(); (it != l.end()) && (flipped != cardsDrawn()); ++it) 225 for (QCanvasItemList::Iterator it = l.begin(); (it != l.end()) && (flipped != cardsDrawn()); ++it)
223 { 226 {
224 if ( (*it)->rtti() == canvasCardId ) 227 if ( (*it)->rtti() == canvasCardId )
225 { 228 {
226 CanvasCard *item = (CanvasCard *)*it; 229 CanvasCard *item = (CanvasCard *)*it;
227 if (item->animated()) 230 if (item->animated())
228 continue; 231 continue;
229 item->setZ(highestZ); 232 item->setZ(highestZ);
230 highestZ++; 233 highestZ++;
231 flipped++; 234 flipped++;
232 235
233 // Added Code 236 // Added Code
234 faceDownDealingPile->removeCard(item); 237 faceDownDealingPile->removeCard(item);
235 faceUpDealingPile->addCardToTop(item); 238 faceUpDealingPile->addCardToTop(item);
236 item->setCardPile( faceUpDealingPile ); 239 item->setCardPile( faceUpDealingPile );
237 240
238 if ( qt_screen->deviceWidth() < 200 ) 241 if ( qt_screen->deviceWidth() < 200 )
239 item->flipTo( 30, (int)item->y(), 8 * flipped ); 242 item->flipTo( 30, (int)item->y(), 8 * flipped );
240 else 243 else
241 item->flipTo( 35, (int)item->y(), 8 * flipped ); 244 item->flipTo( 35, (int)item->y(), 8 * flipped );
242 } 245 }
243 } 246 }
244 247
245 return TRUE; 248 return TRUE;
246 } 249 }
247 250
248 return FALSE; 251 return FALSE;
249} 252}
250 253
251 254
252void PatienceCardGame::mousePress(QPoint p) 255void PatienceCardGame::mousePress(QPoint p)
253{ 256{
254 if ( canTurnOverDeck() && 257 if ( canTurnOverDeck() &&
255 (p.x() > 5) && (p.x() < 28) && 258 (p.x() > 5) && (p.x() < 28) &&
256 (p.y() > 10) && (p.y() < 46) ) 259 (p.y() > 10) && (p.y() < 46) )
257 { 260 {
258 261
259 beginDealing(); 262 beginDealing();
260 Card *card = faceUpDealingPile->cardOnTop(); 263 Card *card = faceUpDealingPile->cardOnTop();
261 while ( card ) 264 while ( card )
262 { 265 {
263 card->setPos( 5, 10, highestZ ); 266 card->setPos( 5, 10, highestZ );
264 card->setFace( FALSE ); 267 card->setFace( FALSE );
265 faceUpDealingPile->removeCard( card ); 268 faceUpDealingPile->removeCard( card );
266 faceDownDealingPile->addCardToTop( card ); 269 faceDownDealingPile->addCardToTop( card );
267 card->setCardPile( faceDownDealingPile ); 270 card->setCardPile( faceDownDealingPile );
268 card = faceUpDealingPile->cardOnTop(); 271 card = faceUpDealingPile->cardOnTop();
269 highestZ++; 272 highestZ++;
270 } 273 }
271 endDealing(); 274 endDealing();
272 275
273 throughDeck(); 276 throughDeck();
274 277
275 moved = TRUE; 278 moved = TRUE;
276 } 279 }
277} 280}
278 281
279 282bool PatienceCardGame::canTurnOverDeck()
280bool PatienceCardGame::canTurnOverDeck() { 283{
281 return (numberOfTimesThroughDeck != deckTurns); 284 return (numberOfTimesThroughDeck != deckTurns);
282} 285}
283 286
284void PatienceCardGame::throughDeck() { 287void PatienceCardGame::throughDeck()
285 numberOfTimesThroughDeck++; 288{
286 if (numberOfTimesThroughDeck == deckTurns) 289 numberOfTimesThroughDeck++;
287 circleCross->setCross(); 290 if (numberOfTimesThroughDeck == deckTurns)
288 } 291 circleCross->setCross();
292}