summaryrefslogtreecommitdiff
authorharlekin <harlekin>2003-04-25 09:02:41 (UTC)
committer harlekin <harlekin>2003-04-25 09:02:41 (UTC)
commitbddc2d168776bf7674f9b938f8889051fb9fa7a8 (patch) (unidiff)
tree5b03d071f18e30e1b023c7bbd07c49346e1ef428
parent25ab69ab9964a8de1c05f9ff659a4b8a820eb201 (diff)
downloadopie-bddc2d168776bf7674f9b938f8889051fb9fa7a8.zip
opie-bddc2d168776bf7674f9b938f8889051fb9fa7a8.tar.gz
opie-bddc2d168776bf7674f9b938f8889051fb9fa7a8.tar.bz2
added patch for freecell mode by radofan, closes bug 736, i hope it helps
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
@@ -234,154 +234,155 @@ void CanvasCardGame::contentsMousePressEvent(QMouseEvent *e) {
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