summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/solitaire/canvascardgame.cpp3
-rw-r--r--noncore/games/solitaire/canvascardgame.h1
-rw-r--r--noncore/games/solitaire/freecellcardgame.cpp83
-rw-r--r--noncore/games/solitaire/freecellcardgame.h5
4 files changed, 90 insertions, 2 deletions
diff --git a/noncore/games/solitaire/canvascardgame.cpp b/noncore/games/solitaire/canvascardgame.cpp
index 8e07cc8..8250193 100644
--- a/noncore/games/solitaire/canvascardgame.cpp
+++ b/noncore/games/solitaire/canvascardgame.cpp
@@ -1,387 +1,388 @@
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
21#include "cardgame.h" 21#include "cardgame.h"
22#include "canvasshapes.h" 22#include "canvasshapes.h"
23#include "canvascard.h" 23#include "canvascard.h"
24#include "canvascardgame.h" 24#include "canvascardgame.h"
25 25
26#include <qpe/resource.h> 26#include <qpe/resource.h>
27#include <qpe/config.h> 27#include <qpe/config.h>
28 28
29#include <qmainwindow.h> 29#include <qmainwindow.h>
30#include <qpe/qpemenubar.h> 30#include <qpe/qpemenubar.h>
31#include <qpainter.h> 31#include <qpainter.h>
32#include <qgfx_qws.h> 32#include <qgfx_qws.h>
33 33
34#include <stdlib.h> 34#include <stdlib.h>
35#include <limits.h> 35#include <limits.h>
36#include <time.h> 36#include <time.h>
37#include <math.h> 37#include <math.h>
38 38
39 39
40extern int highestZ; 40extern int highestZ;
41 41
42 42
43class CanvasCardPile : public QCanvasRectangle 43class CanvasCardPile : public QCanvasRectangle
44{ 44{
45public: 45public:
46 CanvasCardPile( CanvasCardGame *ccg, QCanvas *canvas ) : QCanvasRectangle( canvas ), parent( ccg ) { 46 CanvasCardPile( CanvasCardGame *ccg, QCanvas *canvas ) : QCanvasRectangle( canvas ), parent( ccg ) {
47 pile = new QPixmap( 0, 0 ); 47 pile = new QPixmap( 0, 0 );
48 pileHeight = 0; 48 pileHeight = 0;
49 firstCard = NULL; 49 firstCard = NULL;
50 } 50 }
51 51
52 void addCard( CanvasCard *card ); 52 void addCard( CanvasCard *card );
53 void advance(int stage); 53 void advance(int stage);
54 void animatedMove() { animatedMove(savedX, savedY); } 54 void animatedMove() { animatedMove(savedX, savedY); }
55 void savePos(void) { savedX = (int)x(); savedY = (int)y(); } 55 void savePos(void) { savedX = (int)x(); savedY = (int)y(); }
56 void animatedMove(int x2, int y2, int steps = 7 ); 56 void animatedMove(int x2, int y2, int steps = 7 );
57 57
58protected: 58protected:
59 virtual void draw( QPainter& p ); 59 virtual void draw( QPainter& p );
60 60
61private: 61private:
62 CanvasCardGame *parent; 62 CanvasCardGame *parent;
63 QPixmap *pile; 63 QPixmap *pile;
64 QImage tempImage32; 64 QImage tempImage32;
65 CanvasCard *firstCard; 65 CanvasCard *firstCard;
66 int pileHeight; 66 int pileHeight;
67 int destX, destY; 67 int destX, destY;
68 int savedX, savedY; 68 int savedX, savedY;
69 int animSteps; 69 int animSteps;
70}; 70};
71 71
72 72
73void CanvasCardPile::addCard( CanvasCard *card ) 73void CanvasCardPile::addCard( CanvasCard *card )
74{ 74{
75 int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13; 75 int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13;
76 int cardHeight = ( qt_screen->deviceWidth() < 200 ) ? 27 : 36; 76 int cardHeight = ( qt_screen->deviceWidth() < 200 ) ? 27 : 36;
77 int cardWidth = ( qt_screen->deviceWidth() < 200 ) ? 20 : 23; 77 int cardWidth = ( qt_screen->deviceWidth() < 200 ) ? 20 : 23;
78 78
79 if ( !firstCard ) 79 if ( !firstCard )
80 firstCard = card; 80 firstCard = card;
81 81
82 int height = cardHeight + pileHeight * offsetDown; 82 int height = cardHeight + pileHeight * offsetDown;
83 setSize( cardWidth, height ); 83 setSize( cardWidth, height );
84 pile->resize( cardWidth, height ); 84 pile->resize( cardWidth, height );
85 QPainter p( pile ); 85 QPainter p( pile );
86 p.translate( -card->x(), -card->y() + pileHeight * offsetDown ); 86 p.translate( -card->x(), -card->y() + pileHeight * offsetDown );
87 card->draw( p ); 87 card->draw( p );
88 pileHeight++; 88 pileHeight++;
89 89
90 QImage tempImage; 90 QImage tempImage;
91 tempImage = *pile; 91 tempImage = *pile;
92 tempImage32 = tempImage.convertDepth( 32 ); 92 tempImage32 = tempImage.convertDepth( 32 );
93 tempImage32.setAlphaBuffer( TRUE ); 93 tempImage32.setAlphaBuffer( TRUE );
94 for ( int i = 0; i < tempImage32.width(); i++ ) 94 for ( int i = 0; i < tempImage32.width(); i++ )
95 for ( int j = 0; j < tempImage32.height(); j++ ) { 95 for ( int j = 0; j < tempImage32.height(); j++ ) {
96 QRgb col = tempImage32.pixel( i, j ); 96 QRgb col = tempImage32.pixel( i, j );
97 int a = 255-j*220/tempImage32.height(); 97 int a = 255-j*220/tempImage32.height();
98 QRgb alpha = qRgba( qRed( col ), qGreen( col ), qBlue( col ), a ); 98 QRgb alpha = qRgba( qRed( col ), qGreen( col ), qBlue( col ), a );
99 tempImage32.setPixel( i, j, alpha ); 99 tempImage32.setPixel( i, j, alpha );
100 } 100 }
101 101
102 QRgb alpha = qRgba( 0, 0, 0, 0 ); 102 QRgb alpha = qRgba( 0, 0, 0, 0 );
103 tempImage32.setPixel( 1, 0, alpha ); 103 tempImage32.setPixel( 1, 0, alpha );
104 tempImage32.setPixel( 0, 0, alpha ); 104 tempImage32.setPixel( 0, 0, alpha );
105 tempImage32.setPixel( 0, 1, alpha ); 105 tempImage32.setPixel( 0, 1, alpha );
106 106
107 tempImage32.setPixel( cardWidth - 2, 0, alpha ); 107 tempImage32.setPixel( cardWidth - 2, 0, alpha );
108 tempImage32.setPixel( cardWidth - 1, 0, alpha ); 108 tempImage32.setPixel( cardWidth - 1, 0, alpha );
109 tempImage32.setPixel( cardWidth - 1, 1, alpha ); 109 tempImage32.setPixel( cardWidth - 1, 1, alpha );
110 height--; 110 height--;
111 tempImage32.setPixel( 1, height, alpha ); 111 tempImage32.setPixel( 1, height, alpha );
112 tempImage32.setPixel( 0, height - 1, alpha ); 112 tempImage32.setPixel( 0, height - 1, alpha );
113 tempImage32.setPixel( 0, height, alpha ); 113 tempImage32.setPixel( 0, height, alpha );
114 114
115 tempImage32.setPixel( cardWidth - 2, height, alpha ); 115 tempImage32.setPixel( cardWidth - 2, height, alpha );
116 tempImage32.setPixel( cardWidth - 1, height, alpha ); 116 tempImage32.setPixel( cardWidth - 1, height, alpha );
117 tempImage32.setPixel( cardWidth - 1, height - 1, alpha ); 117 tempImage32.setPixel( cardWidth - 1, height - 1, alpha );
118} 118}
119 119
120 120
121void CanvasCardPile::advance(int stage) 121void CanvasCardPile::advance(int stage)
122{ 122{
123 if ( stage==1 ) { 123 if ( stage==1 ) {
124 if ( animSteps-- <= 0 ) { 124 if ( animSteps-- <= 0 ) {
125 CanvasCard *item = firstCard; 125 CanvasCard *item = firstCard;
126 while (item) { 126 while (item) {
127 item->show(); 127 item->show();
128 item = (CanvasCard *)item->getCardPile()->cardInfront(item); 128 item = (CanvasCard *)item->getCardPile()->cardInfront(item);
129 } 129 }
130 setVelocity(0,0); 130 setVelocity(0,0);
131 setAnimated(FALSE); 131 setAnimated(FALSE);
132 parent->cancelMoving(); 132 parent->cancelMoving();
133 hide(); 133 hide();
134 move(destX,destY); // exact 134 move(destX,destY); // exact
135 } 135 }
136 } 136 }
137 QCanvasRectangle::advance(stage); 137 QCanvasRectangle::advance(stage);
138} 138}
139 139
140 140
141void CanvasCardPile::animatedMove(int x2, int y2, int steps ) 141void CanvasCardPile::animatedMove(int x2, int y2, int steps )
142{ 142{
143 destX = x2; 143 destX = x2;
144 destY = y2; 144 destY = y2;
145 145
146 double x1 = x(), y1 = y(), dx = x2 - x1, dy = y2 - y1; 146 double x1 = x(), y1 = y(), dx = x2 - x1, dy = y2 - y1;
147 147
148 // Ensure a good speed 148 // Ensure a good speed
149 while ( fabs(dx/steps)+fabs(dy/steps) < 5.0 && steps > 4 ) 149 while ( fabs(dx/steps)+fabs(dy/steps) < 5.0 && steps > 4 )
150 steps--; 150 steps--;
151 151
152 setAnimated(TRUE); 152 setAnimated(TRUE);
153 setVelocity(dx/steps, dy/steps); 153 setVelocity(dx/steps, dy/steps);
154 154
155 animSteps = steps; 155 animSteps = steps;
156} 156}
157 157
158 158
159void CanvasCardPile::draw( QPainter& p ) 159void CanvasCardPile::draw( QPainter& p )
160{ 160{
161 int ix = (int)x(), iy = (int)y(); 161 int ix = (int)x(), iy = (int)y();
162 p.drawImage( ix, iy, tempImage32 ); 162 p.drawImage( ix, iy, tempImage32 );
163} 163}
164 164
165 165
166CanvasCardGame::~CanvasCardGame() { 166CanvasCardGame::~CanvasCardGame() {
167 // the deletion stuff should be fixed now and only deletes 167 // the deletion stuff should be fixed now and only deletes
168 // items created by this CardGame. I haven't verified there are zero 168 // items created by this CardGame. I haven't verified there are zero
169 // memory leaks yet 169 // memory leaks yet
170 if ( alphaCardPile ) 170 if ( alphaCardPile )
171 delete alphaCardPile; 171 delete alphaCardPile;
172} 172}
173 173
174 174
175void CanvasCardGame::gameWon() { 175void CanvasCardGame::gameWon() {
176 176
177 srand(time(NULL)); 177 srand(time(NULL));
178 178
179 QCanvasItemList list = canvas()->allItems(); 179 QCanvasItemList list = canvas()->allItems();
180 QCanvasItemList::Iterator it = list.begin(); 180 QCanvasItemList::Iterator it = list.begin();
181 181
182 for (; it != list.end(); ++it) { 182 for (; it != list.end(); ++it) {
183 if ( (*it)->rtti() == canvasCardId ) { 183 if ( (*it)->rtti() == canvasCardId ) {
184 // disperse the cards everywhere 184 // disperse the cards everywhere
185 int x = 300 - rand() % 1000; 185 int x = 300 - rand() % 1000;
186 int y = 300 + rand() % 200; 186 int y = 300 + rand() % 200;
187 ((CanvasCard *)*it)->animatedMove( x, y, 50 ); 187 ((CanvasCard *)*it)->animatedMove( x, y, 50 );
188 } 188 }
189 } 189 }
190} 190}
191 191
192 192
193void CanvasCardGame::contentsMousePressEvent(QMouseEvent *e) { 193void CanvasCardGame::contentsMousePressEvent(QMouseEvent *e) {
194 194
195 if ( moving ) 195 if ( moving )
196 return; 196 return;
197 197
198 QCanvasItemList l = canvas()->collisions( e->pos() ); 198 QCanvasItemList l = canvas()->collisions( e->pos() );
199 199
200 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) { 200 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
201 201
202 if ( (*it)->rtti() == canvasCardId ) { 202 if ( (*it)->rtti() == canvasCardId ) {
203 203
204 moving = (CanvasCard *)*it; 204 moving = (CanvasCard *)*it;
205 205
206 if ( moving->animated() ) 206 if ( moving->animated() )
207 return; 207 return;
208 208
209 cardXOff = (int)(e->pos().x() - moving->x()); 209 cardXOff = (int)(e->pos().x() - moving->x());
210 cardYOff = (int)(e->pos().y() - moving->y()); 210 cardYOff = (int)(e->pos().y() - moving->y());
211 211
212 if ( !mousePressCard( moving, e->pos() ) ) { 212 if ( !mousePressCard( moving, e->pos() ) ) {
213 CanvasCard *card = moving; 213 CanvasCard *card = moving;
214 214
215 if ( alphaCardPile ) 215 if ( alphaCardPile )
216 delete alphaCardPile; 216 delete alphaCardPile;
217 217
218 alphaCardPile = new CanvasCardPile( this, canvas() ); 218 alphaCardPile = new CanvasCardPile( this, canvas() );
219 alphaCardPile->move( card->x(), card->y() ); 219 alphaCardPile->move( card->x(), card->y() );
220 alphaCardPile->savePos(); 220 alphaCardPile->savePos();
221 alphaCardPile->show(); 221 alphaCardPile->show();
222 222
223 while (card) { 223 while (card) {
224 alphaCardPile->addCard( card ); 224 alphaCardPile->addCard( card );
225 card->hide(); 225 card->hide();
226 card = (CanvasCard *)card->getCardPile()->cardInfront(card); 226 card = (CanvasCard *)card->getCardPile()->cardInfront(card);
227 } 227 }
228 228
229 alphaCardPile->setZ( INT_MAX ); 229 alphaCardPile->setZ( INT_MAX );
230 230
231 moved = TRUE; 231 moved = TRUE;
232 } else { 232 } else {
233 if ( alphaCardPile ) 233 if ( alphaCardPile )
234 alphaCardPile->hide(); 234 alphaCardPile->hide();
235 } 235 }
236 return; 236 return;
237 } 237 }
238 } 238 }
239 239
240 mousePress( e->pos() ); 240 mousePress( e->pos() );
241} 241}
242 242
243/* 243/*
244// 244//
245// Should have some intelligent way to make double clicking on a 245// Should have some intelligent way to make double clicking on a
246// card send it to the most appropriate pile 246// card send it to the most appropriate pile
247// 247//
248void CanvasCardGame::contentsMouseDoubleClickEvent(QMouseEvent *e) { 248void CanvasCardGame::contentsMouseDoubleClickEvent(QMouseEvent *e) {
249 QCanvasItemList l = canvas()->collisions( e->pos() ); 249 QCanvasItemList l = canvas()->collisions( e->pos() );
250 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) { 250 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
251 if ( (*it)->rtti() == canvasCardId ) { 251 if ( (*it)->rtti() == canvasCardId ) {
252 CanvasCard *card = (CanvasCard *)*it; 252 CanvasCard *card = (CanvasCard *)*it;
253 253
254 if ( card->animated() ) 254 if ( card->animated() )
255 return; 255 return;
256 256
257 if ( card->getCardPile()->isAllowedToBeMoved(card) ) { 257 if ( card->getCardPile()->isAllowedToBeMoved(card) ) {
258 if (card->getCardPile()->cardInfront(card) == NULL) { 258 if (card->getCardPile()->cardInfront(card) == NULL) {
259 CardPile *pile = first(); 259 CardPile *pile = first();
260 if (pile && pile->isAllowedOnTop(card)) { 260 if (pile && pile->isAllowedOnTop(card)) {
261 // move card to this pile 261 // move card to this pile
262 return; 262 return;
263 } 263 }
264 } 264 }
265 } 265 }
266 } 266 }
267 } 267 }
268} 268}
269*/ 269*/
270 270
271void CanvasCardGame::contentsMouseMoveEvent(QMouseEvent *e) { 271void CanvasCardGame::contentsMouseMoveEvent(QMouseEvent *e) {
272 272
273 QPoint p = e->pos(); 273 QPoint p = e->pos();
274 274
275 if ( moving ) { 275 if ( moving ) {
276 276
277 moved = TRUE; 277 moved = TRUE;
278 278
279 if (moving->isFacing() != TRUE) 279 if (moving->isFacing() != TRUE)
280 return; 280 return;
281 281
282 int tx = (int)p.x() - cardXOff; 282 int tx = (int)p.x() - cardXOff;
283 int ty = (int)p.y() - cardYOff; 283 int ty = (int)p.y() - cardYOff;
284 284
285 if (snapOn == TRUE) { 285 if (snapOn == TRUE) {
286 CardPile *pile = closestPile( tx, ty, 50 ); 286 CardPile *pile = closestPile( tx, ty, 50 );
287 if ( pile && pile->isAllowedOnTop( moving ) ) { 287 if ( pile && pile->isAllowedOnTop( moving ) ) {
288 QPoint p = pile->getHypertheticalNextCardPos(); 288 QPoint p = pile->getHypertheticalNextCardPos();
289 if ( alphaCardPile ) 289 if ( alphaCardPile )
290 alphaCardPile->move( p.x(), p.y() ); 290 alphaCardPile->move( p.x(), p.y() );
291 return; 291 return;
292 } 292 }
293 } 293 }
294 294
295 if ( alphaCardPile ) 295 if ( alphaCardPile )
296 alphaCardPile->move( tx, ty ); 296 alphaCardPile->move( tx, ty );
297 } 297 }
298 298
299} 299}
300 300
301 301
302void CanvasCardGame::contentsMouseReleaseEvent(QMouseEvent *e) 302void CanvasCardGame::contentsMouseReleaseEvent(QMouseEvent *e)
303{ 303{
304 QPoint p = e->pos(); 304 QPoint p = e->pos();
305 305
306 Q_UNUSED(p); 306 Q_UNUSED(p);
307 307
308 if ( moving ) { 308 if ( moving ) {
309 309
310 CanvasCard *item = moving; 310 CanvasCard *item = moving;
311 311
312 if ( item->animated() ) 312 if ( item->animated() )
313 return; 313 return;
314 314
315 if ( alphaCardPile ) 315 if ( alphaCardPile )
316 if ( moved ) { 316 if ( moved ) {
317 317
318 CardPile *pile = closestPile((int)alphaCardPile->x(), (int)alphaCardPile->y(), 30); 318 CardPile *pile = closestPile((int)alphaCardPile->x(), (int)alphaCardPile->y(), 30);
319 319
320 if (pile && pile->isAllowedOnTop(item)) { 320 if (pile && pile->isAllowedOnTop(item)) {
321 CardPile *oldPile = item->getCardPile(); 321 CardPile *oldPile = item->getCardPile();
322 Card *c = NULL; 322 Card *c = NULL;
323 if ( oldPile != pile) { 323 if ( oldPile != pile) {
324 while ( item ) { 324 while ( item ) {
325 item->show(); 325 item->show();
326 if ( oldPile ) { 326 if ( oldPile ) {
327 c = oldPile->cardInfront(item); 327 c = oldPile->cardInfront(item);
328 oldPile->removeCard(item); 328 oldPile->removeCard(item);
329 } 329 }
330 pile->addCardToTop(item);
331 item->setCardPile(pile); 330 item->setCardPile(pile);
332 //item->move( pile->getCardPos(item) ); 331 //item->move( pile->getCardPos(item) );
332 pile->addCardToTop(item);
333 QPoint p = pile->getCardPos(item); 333 QPoint p = pile->getCardPos(item);
334 item->setPos( p.x(), p.y(), highestZ ); 334 item->setPos( p.x(), p.y(), highestZ );
335 highestZ++; 335 highestZ++;
336 checkUnusable(); // added for freecell to move card to discard pile
336 337
337 if (item->getValue() == king && haveWeWon()) { 338 if (item->getValue() == king && haveWeWon()) {
338 alphaCardPile->hide(); 339 alphaCardPile->hide();
339 gameWon(); 340 gameWon();
340 moving = NULL; 341 moving = NULL;
341 return; 342 return;
342 } 343 }
343 344
344 if (oldPile) { 345 if (oldPile) {
345 item = (CanvasCard *)c; 346 item = (CanvasCard *)c;
346 } else { 347 } else {
347 item = NULL; 348 item = NULL;
348 } 349 }
349 } 350 }
350 alphaCardPile->hide(); 351 alphaCardPile->hide();
351 moving = NULL; 352 moving = NULL;
352 return; 353 return;
353 } 354 }
354 } 355 }
355 356
356 alphaCardPile->animatedMove(); 357 alphaCardPile->animatedMove();
357 } 358 }
358 } 359 }
359 360
360 moved = FALSE; 361 moved = FALSE;
361} 362}
362 363
363 364
364void CanvasCardGame::readPile( Config& cfg, CardPile *pile, QString name, int& highestZ ) 365void CanvasCardGame::readPile( Config& cfg, CardPile *pile, QString name, int& highestZ )
365{ 366{
366 cfg.setGroup( name ); 367 cfg.setGroup( name );
367 int numberOfCards = cfg.readNumEntry("NumberOfCards", 0); 368 int numberOfCards = cfg.readNumEntry("NumberOfCards", 0);
368 Card *card = NULL; 369 Card *card = NULL;
369 370
370 for ( int i = 0; i < numberOfCards; i++ ) { 371 for ( int i = 0; i < numberOfCards; i++ ) {
371 QString cardStr; 372 QString cardStr;
372 cardStr.sprintf( "%i", i ); 373 cardStr.sprintf( "%i", i );
373 int val = cfg.readNumEntry( "Card" + cardStr ); 374 int val = cfg.readNumEntry( "Card" + cardStr );
374 bool facing = cfg.readBoolEntry( "CardFacing" + cardStr ); 375 bool facing = cfg.readBoolEntry( "CardFacing" + cardStr );
375 376
376 card = cards[ val ]; 377 card = cards[ val ];
377 card->setFace(facing); 378 card->setFace(facing);
378 card->setCardPile(pile); // cam: setCardPile has to happen bevor addCardToTop 379 card->setCardPile(pile); // cam: setCardPile has to happen bevor addCardToTop
379 pile->addCardToTop(card); // due to a empty pointer if you use cardAddedToTop 380 pile->addCardToTop(card); // due to a empty pointer if you use cardAddedToTop
380 QPoint p = pile->getCardPos( card ); 381 QPoint p = pile->getCardPos( card );
381 card->setPos( p.x(), p.y(), highestZ ); 382 card->setPos( p.x(), p.y(), highestZ );
382 card->showCard(); 383 card->showCard();
383 highestZ++; 384 highestZ++;
384 } 385 }
385} 386}
386 387
387 388
diff --git a/noncore/games/solitaire/canvascardgame.h b/noncore/games/solitaire/canvascardgame.h
index 0dfb85e..d159de6 100644
--- a/noncore/games/solitaire/canvascardgame.h
+++ b/noncore/games/solitaire/canvascardgame.h
@@ -1,96 +1,97 @@
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 CANVAS_CARD_GAME_H 20#ifndef CANVAS_CARD_GAME_H
21#define CANVAS_CARD_GAME_H 21#define CANVAS_CARD_GAME_H
22 22
23#include "cardgame.h" 23#include "cardgame.h"
24#include "canvasshapes.h" 24#include "canvasshapes.h"
25#include "canvascard.h" 25#include "canvascard.h"
26 26
27#include <qpe/resource.h> 27#include <qpe/resource.h>
28#include <qpe/config.h> 28#include <qpe/config.h>
29 29
30#include <qmainwindow.h> 30#include <qmainwindow.h>
31#include <qpe/qpemenubar.h> 31#include <qpe/qpemenubar.h>
32#include <qpainter.h> 32#include <qpainter.h>
33 33
34#include <stdlib.h> 34#include <stdlib.h>
35#include <time.h> 35#include <time.h>
36 36
37 37
38class CanvasCardPile; 38class CanvasCardPile;
39 39
40 40
41class CanvasCardGame : public QCanvasView, public CardGame 41class CanvasCardGame : public QCanvasView, public CardGame
42{ 42{
43public: 43public:
44 CanvasCardGame(QCanvas &c, bool snap, QWidget *parent = 0, int numOfDecks = 1, const char *name = 0, WFlags f = 0) : 44 CanvasCardGame(QCanvas &c, bool snap, QWidget *parent = 0, int numOfDecks = 1, const char *name = 0, WFlags f = 0) :
45 QCanvasView( &c, parent, name, f ), 45 QCanvasView( &c, parent, name, f ),
46 CardGame(0,numOfDecks), 46 CardGame(0,numOfDecks),
47 moved(FALSE), 47 moved(FALSE),
48 moving(NULL), 48 moving(NULL),
49 alphaCardPile( NULL ), 49 alphaCardPile( NULL ),
50 cardXOff(0), cardYOff(0), 50 cardXOff(0), cardYOff(0),
51 snapOn(snap), 51 snapOn(snap),
52 numberToDraw(1) { } 52 numberToDraw(1) { }
53 53
54 virtual ~CanvasCardGame(); 54 virtual ~CanvasCardGame();
55 55
56 virtual Card *newCard( eValue v, eSuit s, bool f ) { 56 virtual Card *newCard( eValue v, eSuit s, bool f ) {
57 return new CanvasCard( v, s, f, canvas() ); 57 return new CanvasCard( v, s, f, canvas() );
58 } 58 }
59 59
60 virtual void readConfig( Config& cfg ) { Q_UNUSED( cfg ); } 60 virtual void readConfig( Config& cfg ) { Q_UNUSED( cfg ); }
61 virtual void writeConfig( Config& cfg ) { Q_UNUSED( cfg ); } 61 virtual void writeConfig( Config& cfg ) { Q_UNUSED( cfg ); }
62 62
63 virtual void gameWon(); 63 virtual void gameWon();
64 virtual bool haveWeWon() { return FALSE; } 64 virtual bool haveWeWon() { return FALSE; }
65 65
66 virtual bool mousePressCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); return FALSE; } 66 virtual bool mousePressCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); return FALSE; }
67 virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); } 67 virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); }
68 68
69 void cancelMoving() { moving = NULL; } 69 void cancelMoving() { moving = NULL; }
70 void toggleSnap() { snapOn = (snapOn == TRUE) ? FALSE : TRUE; } 70 void toggleSnap() { snapOn = (snapOn == TRUE) ? FALSE : TRUE; }
71 void toggleCardsDrawn() { numberToDraw = (numberToDraw == 1) ? 3 : 1; } 71 void toggleCardsDrawn() { numberToDraw = (numberToDraw == 1) ? 3 : 1; }
72 int cardsDrawn() { return numberToDraw; } 72 int cardsDrawn() { return numberToDraw; }
73 void setNumberToDraw(int numToDraw) { this->numberToDraw = numToDraw; } 73 void setNumberToDraw(int numToDraw) { this->numberToDraw = numToDraw; }
74 74
75 void readPile( Config& cfg, CardPile *pile, QString name, int& highestZ ); 75 void readPile( Config& cfg, CardPile *pile, QString name, int& highestZ );
76 76
77protected: 77protected:
78 void contentsMousePressEvent(QMouseEvent *e); 78 void contentsMousePressEvent(QMouseEvent *e);
79 void contentsMouseReleaseEvent(QMouseEvent *e); 79 void contentsMouseReleaseEvent(QMouseEvent *e);
80 void contentsMouseMoveEvent(QMouseEvent *e); 80 void contentsMouseMoveEvent(QMouseEvent *e);
81 virtualvoid checkUnusable() { } //added for freecell
81 82
82protected: 83protected:
83 // Mouse event state variables 84 // Mouse event state variables
84 bool moved; 85 bool moved;
85 CanvasCard *moving; 86 CanvasCard *moving;
86 CanvasCardPile *alphaCardPile; 87 CanvasCardPile *alphaCardPile;
87 int cardXOff, cardYOff; 88 int cardXOff, cardYOff;
88 89
89private: 90private:
90 bool snapOn; 91 bool snapOn;
91 int numberToDraw; 92 int numberToDraw;
92}; 93};
93 94
94 95
95#endif 96#endif
96 97
diff --git a/noncore/games/solitaire/freecellcardgame.cpp b/noncore/games/solitaire/freecellcardgame.cpp
index 98415aa..aeb32fc 100644
--- a/noncore/games/solitaire/freecellcardgame.cpp
+++ b/noncore/games/solitaire/freecellcardgame.cpp
@@ -1,142 +1,225 @@
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 <qgfx_qws.h> 20#include <qgfx_qws.h>
21#include "freecellcardgame.h" 21#include "freecellcardgame.h"
22 22
23 23
24extern int highestZ; 24extern int highestZ;
25int numberOfFreeCells = 4; 25int numberOfFreeCells = 4;
26 26
27 27
28FreecellCardGame::FreecellCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent) 28FreecellCardGame::FreecellCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent)
29{ 29{
30 numberOfFreeCells = 4; 30 numberOfFreeCells = 4;
31 highestZ = 0; 31 highestZ = 0;
32 32
33 int spaceBetweenPiles = ( qt_screen->deviceWidth() < 200 ) ? 21 : 28; 33 int spaceBetweenPiles = ( qt_screen->deviceWidth() < 200 ) ? 21 : 28;
34 int xOrigin = ( qt_screen->deviceWidth() < 200 ) ? 0 : 5; 34 int xOrigin = ( qt_screen->deviceWidth() < 200 ) ? 0 : 5;
35 int spacing = ( qt_screen->deviceWidth() < 200 ) ? 0 : 0; 35 int spacing = ( qt_screen->deviceWidth() < 200 ) ? 0 : 0;
36 36
37 for (int i = 0; i < 4; i++) { 37 for (int i = 0; i < 4; i++) {
38 freecellPiles[i] = new FreecellFreecellPile( xOrigin + i * spaceBetweenPiles, 10, canvas() ); 38 freecellPiles[i] = new FreecellFreecellPile( xOrigin + i * spaceBetweenPiles, 10, canvas() );
39 addCardPile(freecellPiles[i]); 39 addCardPile(freecellPiles[i]);
40 } 40 }
41 for (int i = 0; i < 4; i++) { 41 for (int i = 0; i < 4; i++) {
42 discardPiles[i] = new FreecellDiscardPile( xOrigin + spacing + 6 + (i + 4) * spaceBetweenPiles, 10, canvas() ); 42 discardPiles[i] = new FreecellDiscardPile( xOrigin + spacing + 6 + (i + 4) * spaceBetweenPiles, 10, canvas() );
43 addCardPile(discardPiles[i]); 43 addCardPile(discardPiles[i]);
44 } 44 }
45 for (int i = 0; i < 8; i++) { 45 for (int i = 0; i < 8; i++) {
46 workingPiles[i] = new FreecellWorkingPile( xOrigin + spacing + 2 + i * spaceBetweenPiles, 50, canvas() ); 46 workingPiles[i] = new FreecellWorkingPile( xOrigin + spacing + 2 + i * spaceBetweenPiles, 50, canvas() );
47 addCardPile(workingPiles[i]); 47 addCardPile(workingPiles[i]);
48 } 48 }
49} 49}
50 50
51 51
52void FreecellCardGame::deal(void) 52void FreecellCardGame::deal(void)
53{ 53{
54 highestZ = 1; 54 highestZ = 1;
55 55
56 beginDealing(); 56 beginDealing();
57 57
58 for (int i = 0; i < 52; i++) { 58 for (int i = 0; i < 52; i++) {
59 Card *card = cards[i]; 59 Card *card = cards[i];
60 card->setFace( TRUE ); 60 card->setFace( TRUE );
61 card->setPos( 0, 0, highestZ ); 61 card->setPos( 0, 0, highestZ );
62 card->setCardPile( workingPiles[i%8] ); 62 card->setCardPile( workingPiles[i%8] );
63 workingPiles[i%8]->addCardToTop( card ); 63 workingPiles[i%8]->addCardToTop( card );
64 card->move( workingPiles[i%8]->getCardPos( card ) ); 64 card->move( workingPiles[i%8]->getCardPos( card ) );
65 card->showCard(); 65 card->showCard();
66 highestZ++; 66 highestZ++;
67 } 67 }
68 68
69 endDealing(); 69 endDealing();
70} 70}
71 71
72 // checks if smaller card with different color, that could be put on top on the
73 // card, is present in working or freecell pile
74bool FreecellCardGame::checkNeeded(Card *card)
75{
76 if (card->getValue() > 2){
77 int i;
78 Card *c;
79 for (i=0;i<4;i++){
80 c = freecellPiles[i]->cardOnBottom();
81 if (c != NULL){
82 if (card->isRed()!= c->isRed() && card->getValue()== c->getValue()+1){
83 return (false);
84 }
85 }
86 }
87 for (i=0;i<8;i++){
88 c=workingPiles[i]->cardOnBottom();
89 while (c!=NULL){
90 if (card->isRed() != c->isRed()&& card->getValue() == c->getValue()+1) {
91 return (false);
92 }
93 c=workingPiles[i]->cardInfront(c);
94 }
95 }
96 }
97 return(true);
98}
99
100// added to move cards, on which no card can be moved, to discard pile
101void FreecellCardGame::checkUnusable()
102{
103 int i,j;
104 //printf("void FreecellCardGame::checkUnusable()\n");
105 Card *top_one;
106 for (i=0;i < 8;i++)
107 {
108 top_one = workingPiles[i]->cardOnTop();
109 if (top_one != NULL)
110 {
111 j = 0;
112 while ((j < 4))
113 {
114 if (discardPiles[j]->isAllowedOnTop(top_one)){
115 if (checkNeeded(top_one)){
116 top_one->setCardPile(discardPiles[j]);
117 workingPiles[i]->removeCard(top_one);
118 // printf("k %d f work%d to disk%d on %d\n ",top_one->getValue(),i+1,j+1,highestZ);
119 discardPiles[j]->addCardToTop(top_one);
120 top_one->setPos(discardPiles[j]->getX(),discardPiles[j]->getY(),highestZ);
121 highestZ++;
122 j = 4;
123 checkUnusable();
124 }
125 }
126 j++;
127 }
128 }
129 }
130 for (i=0;i<4;i++){
131 top_one = freecellPiles[i]->cardOnTop();
132 if (top_one != NULL)
133 {
134 j = 0;
135 while ((j < 4))
136 {
137 if (discardPiles[j]->isAllowedOnTop(top_one)){
138 if (checkNeeded(top_one)){
139 top_one->setCardPile(discardPiles[j]);
140 freecellPiles[i]->removeCard(top_one);
141 // printf("k %d f work%d to disk%d on %d\n ",top_one->getValue(),i+1,j+1,highestZ);
142 discardPiles[j]->addCardToTop(top_one);
143 top_one->setPos(discardPiles[j]->getX(),discardPiles[j]->getY(),highestZ);
144 highestZ++;
145 j = 4;
146 checkUnusable();
147 }
148 }
149 j++;
150 }
151 }
152 }
153}
154
72 155
73bool FreecellCardGame::mousePressCard( Card *c, QPoint p ) 156bool FreecellCardGame::mousePressCard( Card *c, QPoint p )
74{ 157{
75 Q_UNUSED(p); 158 Q_UNUSED(p);
76 159
77 if ( !c->getCardPile()->isAllowedToBeMoved(c) ) { 160 if ( !c->getCardPile()->isAllowedToBeMoved(c) ) {
78 moving = NULL; 161 moving = NULL;
79 return TRUE; 162 return TRUE;
80 } 163 }
81 164
82 return FALSE; 165 return FALSE;
83} 166}
84 167
85 168
86void FreecellCardGame::readConfig( Config& cfg ) 169void FreecellCardGame::readConfig( Config& cfg )
87{ 170{
88 cfg.setGroup("GameState"); 171 cfg.setGroup("GameState");
89 172
90 // Create Cards, but don't shuffle or deal them yet 173 // Create Cards, but don't shuffle or deal them yet
91 createDeck(); 174 createDeck();
92 175
93 // Move the cards to their piles (deal them to their previous places) 176 // Move the cards to their piles (deal them to their previous places)
94 beginDealing(); 177 beginDealing();
95 178
96 highestZ = 1; 179 highestZ = 1;
97 180
98 for (int k = 0; k < 4; k++) { 181 for (int k = 0; k < 4; k++) {
99 QString pile; 182 QString pile;
100 pile.sprintf( "FreeCellPile%i", k ); 183 pile.sprintf( "FreeCellPile%i", k );
101 readPile( cfg, freecellPiles[k], pile, highestZ ); 184 readPile( cfg, freecellPiles[k], pile, highestZ );
102 } 185 }
103 186
104 for (int k = 0; k < 4; k++) { 187 for (int k = 0; k < 4; k++) {
105 QString pile; 188 QString pile;
106 pile.sprintf( "DiscardPile%i", k ); 189 pile.sprintf( "DiscardPile%i", k );
107 readPile( cfg, discardPiles[k], pile, highestZ ); 190 readPile( cfg, discardPiles[k], pile, highestZ );
108 } 191 }
109 192
110 for (int k = 0; k < 8; k++) { 193 for (int k = 0; k < 8; k++) {
111 QString pile; 194 QString pile;
112 pile.sprintf( "WorkingPile%i", k ); 195 pile.sprintf( "WorkingPile%i", k );
113 readPile( cfg, workingPiles[k], pile, highestZ ); 196 readPile( cfg, workingPiles[k], pile, highestZ );
114 } 197 }
115 198
116 highestZ++; 199 highestZ++;
117 200
118 endDealing(); 201 endDealing();
119} 202}
120 203
121 204
122void FreecellCardGame::writeConfig( Config& cfg ) 205void FreecellCardGame::writeConfig( Config& cfg )
123{ 206{
124 cfg.setGroup("GameState"); 207 cfg.setGroup("GameState");
125 for ( int i = 0; i < 4; i++ ) { 208 for ( int i = 0; i < 4; i++ ) {
126 QString pile; 209 QString pile;
127 pile.sprintf( "FreeCellPile%i", i ); 210 pile.sprintf( "FreeCellPile%i", i );
128 freecellPiles[i]->writeConfig( cfg, pile ); 211 freecellPiles[i]->writeConfig( cfg, pile );
129 } 212 }
130 for ( int i = 0; i < 4; i++ ) { 213 for ( int i = 0; i < 4; i++ ) {
131 QString pile; 214 QString pile;
132 pile.sprintf( "DiscardPile%i", i ); 215 pile.sprintf( "DiscardPile%i", i );
133 discardPiles[i]->writeConfig( cfg, pile ); 216 discardPiles[i]->writeConfig( cfg, pile );
134 } 217 }
135 for ( int i = 0; i < 8; i++ ) { 218 for ( int i = 0; i < 8; i++ ) {
136 QString pile; 219 QString pile;
137 pile.sprintf( "WorkingPile%i", i ); 220 pile.sprintf( "WorkingPile%i", i );
138 workingPiles[i]->writeConfig( cfg, pile ); 221 workingPiles[i]->writeConfig( cfg, pile );
139 } 222 }
140} 223}
141 224
142 225
diff --git a/noncore/games/solitaire/freecellcardgame.h b/noncore/games/solitaire/freecellcardgame.h
index f1b09ab..2df751b 100644
--- a/noncore/games/solitaire/freecellcardgame.h
+++ b/noncore/games/solitaire/freecellcardgame.h
@@ -1,152 +1,155 @@
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 FREECELL_CARD_GAME_H 20#ifndef FREECELL_CARD_GAME_H
21#define FREECELL_CARD_GAME_H 21#define FREECELL_CARD_GAME_H
22 22
23 23
24#include "patiencecardgame.h" 24#include "patiencecardgame.h"
25 25
26 26
27extern int numberOfFreeCells; 27extern int numberOfFreeCells;
28 28
29 29
30class FreecellDiscardPile : public PatienceDiscardPile 30class FreecellDiscardPile : public PatienceDiscardPile
31{ 31{
32public: 32public:
33 FreecellDiscardPile(int x, int y, QCanvas *canvas) : 33 FreecellDiscardPile(int x, int y, QCanvas *canvas) :
34 PatienceDiscardPile(x, y, canvas) { } 34 PatienceDiscardPile(x, y, canvas) { }
35 35
36}; 36};
37 37
38 38
39class FreecellWorkingPile : public PatienceWorkingPile 39class FreecellWorkingPile : public PatienceWorkingPile
40{ 40{
41public: 41public:
42 FreecellWorkingPile(int x, int y, QCanvas *canvas) : 42 FreecellWorkingPile(int x, int y, QCanvas *canvas) :
43 PatienceWorkingPile(x, y, canvas) { } 43 PatienceWorkingPile(x, y, canvas) { }
44 44
45 virtual bool isAllowedOnTop(Card *card) { 45 virtual bool isAllowedOnTop(Card *card) {
46 if ( cardOnBottom() == NULL ) { 46 if ( cardOnBottom() == NULL ) {
47 int numberOfCardsBeingMoved = 0; 47 int numberOfCardsBeingMoved = 0;
48 Card *tempCard = card; 48 Card *tempCard = card;
49 49
50 while ((tempCard != NULL)) { 50 while ((tempCard != NULL)) {
51 numberOfCardsBeingMoved++; 51 numberOfCardsBeingMoved++;
52 tempCard = cardInfront(tempCard); 52 tempCard = cardInfront(tempCard);
53 } 53 }
54 54
55 if (numberOfCardsBeingMoved > numberOfFreeCells) 55 if (numberOfCardsBeingMoved > numberOfFreeCells)
56 return FALSE; 56 return FALSE;
57 } 57 }
58 58
59 if ( card->isFacing() && 59 if ( card->isFacing() &&
60 cardOnTop() == NULL ) 60 cardOnTop() == NULL )
61 return TRUE; 61 return TRUE;
62 return PatienceWorkingPile::isAllowedOnTop( card ); 62 return PatienceWorkingPile::isAllowedOnTop( card );
63 } 63 }
64 64
65
65 virtual bool isAllowedToBeMoved(Card *card) { 66 virtual bool isAllowedToBeMoved(Card *card) {
66 int nextExpectedValue = (int)card->getValue(); 67 int nextExpectedValue = (int)card->getValue();
67 bool nextExpectedColor = card->isRed(); 68 bool nextExpectedColor = card->isRed();
68 int numberOfCardsBeingMoved = 0; 69 int numberOfCardsBeingMoved = 0;
69 70
70 while ((card != NULL)) { 71 while ((card != NULL)) {
71 numberOfCardsBeingMoved++; 72 numberOfCardsBeingMoved++;
72 if ( (int)card->getValue() != nextExpectedValue ) 73 if ( (int)card->getValue() != nextExpectedValue )
73 return FALSE; 74 return FALSE;
74 if ( card->isRed() != nextExpectedColor ) 75 if ( card->isRed() != nextExpectedColor )
75 return FALSE; 76 return FALSE;
76 nextExpectedValue--;; 77 nextExpectedValue--;;
77 nextExpectedColor = !nextExpectedColor; 78 nextExpectedColor = !nextExpectedColor;
78 card = cardInfront(card); 79 card = cardInfront(card);
79 } 80 }
80 81
81 if (numberOfCardsBeingMoved <= (numberOfFreeCells + 1)) 82 if (numberOfCardsBeingMoved <= (numberOfFreeCells + 1))
82 return TRUE; 83 return TRUE;
83 84
84 return FALSE; 85 return FALSE;
85 } 86 }
86 virtual void cardRemoved(Card *card) { 87 virtual void cardRemoved(Card *card) {
87 if ( !isDealing() && !cardOnTop() ) 88 if ( !isDealing() && !cardOnTop() )
88 numberOfFreeCells++; 89 numberOfFreeCells++;
89 PatienceWorkingPile::cardRemoved( card ); 90 PatienceWorkingPile::cardRemoved( card );
90 } 91 }
91 virtual void cardAddedToTop(Card *card) { 92 virtual void cardAddedToTop(Card *card) {
92 if ( !isDealing() && cardOnBottom() == card ) 93 if ( !isDealing() && cardOnBottom() == card )
93 numberOfFreeCells--; 94 numberOfFreeCells--;
94 PatienceWorkingPile::cardAddedToTop( card ); 95 PatienceWorkingPile::cardAddedToTop( card );
95 } 96 }
96}; 97};
97 98
98 99
99class FreecellFreecellPile : public CardPile, public CanvasRoundRect 100class FreecellFreecellPile : public CardPile, public CanvasRoundRect
100{ 101{
101public: 102public:
102 FreecellFreecellPile(int x, int y, QCanvas *canvas) 103 FreecellFreecellPile(int x, int y, QCanvas *canvas)
103 : CardPile(x, y), CanvasRoundRect(x, y, canvas) { } 104 : CardPile(x, y), CanvasRoundRect(x, y, canvas) { }
104 virtual bool isAllowedOnTop(Card *card) { 105 virtual bool isAllowedOnTop(Card *card) {
105 if ( ( cardOnTop() == NULL ) && ( card->getCardPile()->cardInfront(card) == NULL ) ) 106 if ( ( cardOnTop() == NULL ) && ( card->getCardPile()->cardInfront(card) == NULL ) )
106 return TRUE; 107 return TRUE;
107 return FALSE; 108 return FALSE;
108 } 109 }
109 virtual bool isAllowedToBeMoved(Card *card) { 110 virtual bool isAllowedToBeMoved(Card *card) {
110 Q_UNUSED(card); 111 Q_UNUSED(card);
111 return TRUE; 112 return TRUE;
112 } 113 }
113 virtual void cardAddedToTop(Card *card) { 114 virtual void cardAddedToTop(Card *card) {
114 Q_UNUSED(card); 115 Q_UNUSED(card);
115 numberOfFreeCells--; 116 numberOfFreeCells--;
116 } 117 }
117 virtual void cardRemoved(Card *card) { 118 virtual void cardRemoved(Card *card) {
118 Q_UNUSED(card); 119 Q_UNUSED(card);
119 numberOfFreeCells++; 120 numberOfFreeCells++;
120 } 121 }
121}; 122};
122 123
123 124
124class FreecellCardGame : public CanvasCardGame 125class FreecellCardGame : public CanvasCardGame
125{ 126{
126public: 127public:
127 FreecellCardGame(QCanvas *c, bool snap, QWidget *parent = 0); 128 FreecellCardGame(QCanvas *c, bool snap, QWidget *parent = 0);
128 virtual void deal(void); 129 virtual void deal(void);
129 virtual bool haveWeWon() { 130 virtual bool haveWeWon() {
130 return ( discardPiles[0]->kingOnTop() && 131 return ( discardPiles[0]->kingOnTop() &&
131 discardPiles[1]->kingOnTop() && 132 discardPiles[1]->kingOnTop() &&
132 discardPiles[2]->kingOnTop() && 133 discardPiles[2]->kingOnTop() &&
133 discardPiles[3]->kingOnTop() ); 134 discardPiles[3]->kingOnTop() );
134 } 135 }
135 virtual void mousePress(QPoint p) { Q_UNUSED(p); } 136 virtual void mousePress(QPoint p) { Q_UNUSED(p); }
136 virtual void mouseRelease(QPoint p) { Q_UNUSED(p); } 137 virtual void mouseRelease(QPoint p) { Q_UNUSED(p); }
137// virtual void mouseMove(QPoint p); 138// virtual void mouseMove(QPoint p);
138 virtual bool mousePressCard(Card *card, QPoint p); 139 virtual bool mousePressCard(Card *card, QPoint p);
139 virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); } 140 virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); }
140// virtual void mouseMoveCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); } 141// virtual void mouseMoveCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); }
142 virtual void checkUnusable();
141 void readConfig( Config& cfg ); 143 void readConfig( Config& cfg );
142 void writeConfig( Config& cfg ); 144 void writeConfig( Config& cfg );
143 bool snapOn; 145 bool snapOn;
144private: 146private:
147 bool checkNeeded(Card *card);
145 FreecellFreecellPile *freecellPiles[8]; 148 FreecellFreecellPile *freecellPiles[8];
146 FreecellWorkingPile *workingPiles[8]; 149 FreecellWorkingPile *workingPiles[8];
147 FreecellDiscardPile *discardPiles[4]; 150 FreecellDiscardPile *discardPiles[4];
148}; 151};
149 152
150 153
151#endif 154#endif
152 155