summaryrefslogtreecommitdiff
authortille <tille>2002-06-28 14:56:10 (UTC)
committer tille <tille>2002-06-28 14:56:10 (UTC)
commitab413257c3a23f535e99f8f61468382c73bc4adb (patch) (unidiff)
tree63834da1738157e52b67550d4e71058c6710f1ff
parentd4626cc76127b7022c8555ea11afbb289714c851 (diff)
downloadopie-ab413257c3a23f535e99f8f61468382c73bc4adb.zip
opie-ab413257c3a23f535e99f8f61468382c73bc4adb.tar.gz
opie-ab413257c3a23f535e99f8f61468382c73bc4adb.tar.bz2
cmader <chris@mediakreativwerk.de> impl. 2 new games
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/solitaire/canvascardgame.cpp4
-rw-r--r--noncore/games/solitaire/canvascardgame.h3
-rw-r--r--noncore/games/solitaire/canvascardwindow.cpp53
-rw-r--r--noncore/games/solitaire/canvascardwindow.h2
-rw-r--r--noncore/games/solitaire/card.h4
-rw-r--r--noncore/games/solitaire/carddeck.cpp22
-rw-r--r--noncore/games/solitaire/carddeck.h4
-rw-r--r--noncore/games/solitaire/cardgame.h2
-rw-r--r--noncore/games/solitaire/cardpile.cpp2
-rw-r--r--noncore/games/solitaire/chicanecardgame.cpp171
-rw-r--r--noncore/games/solitaire/chicanecardgame.h165
-rw-r--r--noncore/games/solitaire/harpcardgame.cpp171
-rw-r--r--noncore/games/solitaire/harpcardgame.h165
-rw-r--r--noncore/games/solitaire/patiencecardgame.cpp6
-rwxr-xr-xnoncore/games/solitaire/solitaire.pro7
15 files changed, 764 insertions, 17 deletions
diff --git a/noncore/games/solitaire/canvascardgame.cpp b/noncore/games/solitaire/canvascardgame.cpp
index ef35287..357e798 100644
--- a/noncore/games/solitaire/canvascardgame.cpp
+++ b/noncore/games/solitaire/canvascardgame.cpp
@@ -353,33 +353,35 @@ void CanvasCardGame::contentsMouseReleaseEvent(QMouseEvent *e)
353 } 353 }
354 } 354 }
355 355
356 alphaCardPile->animatedMove(); 356 alphaCardPile->animatedMove();
357 } 357 }
358 } 358 }
359 359
360 moved = FALSE; 360 moved = FALSE;
361} 361}
362 362
363 363
364void CanvasCardGame::readPile( Config& cfg, CardPile *pile, QString name, int& highestZ ) 364void CanvasCardGame::readPile( Config& cfg, CardPile *pile, QString name, int& highestZ )
365{ 365{
366 cfg.setGroup( name ); 366 cfg.setGroup( name );
367 int numberOfCards = cfg.readNumEntry("NumberOfCards", 0); 367 int numberOfCards = cfg.readNumEntry("NumberOfCards", 0);
368 Card *card = NULL; 368 Card *card = NULL;
369
369 for ( int i = 0; i < numberOfCards; i++ ) { 370 for ( int i = 0; i < numberOfCards; i++ ) {
370 QString cardStr; 371 QString cardStr;
371 cardStr.sprintf( "%i", i ); 372 cardStr.sprintf( "%i", i );
372 int val = cfg.readNumEntry( "Card" + cardStr ); 373 int val = cfg.readNumEntry( "Card" + cardStr );
373 bool facing = cfg.readBoolEntry( "CardFacing" + cardStr ); 374 bool facing = cfg.readBoolEntry( "CardFacing" + cardStr );
374 card = cards[ val ]; 375
376 card = cards[ val ];
375 card->setFace(facing); 377 card->setFace(facing);
376 pile->addCardToTop(card); 378 pile->addCardToTop(card);
377 card->setCardPile(pile); 379 card->setCardPile(pile);
378 QPoint p = pile->getCardPos( card ); 380 QPoint p = pile->getCardPos( card );
379 card->setPos( p.x(), p.y(), highestZ ); 381 card->setPos( p.x(), p.y(), highestZ );
380 card->showCard(); 382 card->showCard();
381 highestZ++; 383 highestZ++;
382 } 384 }
383} 385}
384 386
385 387
diff --git a/noncore/games/solitaire/canvascardgame.h b/noncore/games/solitaire/canvascardgame.h
index 4d32014..0dfb85e 100644
--- a/noncore/games/solitaire/canvascardgame.h
+++ b/noncore/games/solitaire/canvascardgame.h
@@ -28,34 +28,35 @@
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, 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 moved(FALSE), 47 moved(FALSE),
47 moving(NULL), 48 moving(NULL),
48 alphaCardPile( NULL ), 49 alphaCardPile( NULL ),
49 cardXOff(0), cardYOff(0), 50 cardXOff(0), cardYOff(0),
50 snapOn(snap), 51 snapOn(snap),
51 numberToDraw(1) { } 52 numberToDraw(1) { }
52 53
53 virtual ~CanvasCardGame(); 54 virtual ~CanvasCardGame();
54 55
55 virtual Card *newCard( eValue v, eSuit s, bool f ) { 56 virtual Card *newCard( eValue v, eSuit s, bool f ) {
56 return new CanvasCard( v, s, f, canvas() ); 57 return new CanvasCard( v, s, f, canvas() );
57 } 58 }
58 59
59 virtual void readConfig( Config& cfg ) { Q_UNUSED( cfg ); } 60 virtual void readConfig( Config& cfg ) { Q_UNUSED( cfg ); }
60 virtual void writeConfig( Config& cfg ) { Q_UNUSED( cfg ); } 61 virtual void writeConfig( Config& cfg ) { Q_UNUSED( cfg ); }
61 62
diff --git a/noncore/games/solitaire/canvascardwindow.cpp b/noncore/games/solitaire/canvascardwindow.cpp
index 4c365a5..e1c021e 100644
--- a/noncore/games/solitaire/canvascardwindow.cpp
+++ b/noncore/games/solitaire/canvascardwindow.cpp
@@ -8,32 +8,34 @@
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 "canvascardwindow.h" 21#include "canvascardwindow.h"
22#include "patiencecardgame.h" 22#include "patiencecardgame.h"
23#include "freecellcardgame.h" 23#include "freecellcardgame.h"
24#include "chicanecardgame.h"
25#include "harpcardgame.h"
24 26
25#include <qpe/resource.h> 27#include <qpe/resource.h>
26 28
27#include <qmainwindow.h> 29#include <qmainwindow.h>
28#include <qpopupmenu.h> 30#include <qpopupmenu.h>
29#include <qstyle.h> 31#include <qstyle.h>
30 32
31 33
32CanvasCardWindow::CanvasCardWindow(QWidget* parent, const char* name, WFlags f) : 34CanvasCardWindow::CanvasCardWindow(QWidget* parent, const char* name, WFlags f) :
33 QMainWindow(parent, name, f), canvas(230, 260), snapOn(TRUE), cardBack(4), gameType(0), 35 QMainWindow(parent, name, f), canvas(230, 260), snapOn(TRUE), cardBack(4), gameType(0),
34 cardGame(NULL) 36 cardGame(NULL)
35{ 37{
36 setIcon( Resource::loadPixmap( "cards" ) ); 38 setIcon( Resource::loadPixmap( "cards" ) );
37 39
38 // Create Playing Area for Games 40 // Create Playing Area for Games
39 if ( QPixmap::defaultDepth() < 12 ) { 41 if ( QPixmap::defaultDepth() < 12 ) {
@@ -46,54 +48,58 @@ CanvasCardWindow::CanvasCardWindow(QWidget* parent, const char* name, WFlags f)
46 canvas.setBackgroundPixmap(bg); 48 canvas.setBackgroundPixmap(bg);
47 } 49 }
48 50
49#if defined( QT_QWS_CASSIOPEIA ) 51#if defined( QT_QWS_CASSIOPEIA )
50 canvas.setAdvancePeriod(70); 52 canvas.setAdvancePeriod(70);
51#else 53#else
52 canvas.setAdvancePeriod(30); 54 canvas.setAdvancePeriod(30);
53#endif 55#endif
54 56
55 57
56#ifdef _PATIENCE_USE_ACCELS_ 58#ifdef _PATIENCE_USE_ACCELS_
57 QPEMenuBar* menu = menuBar(); 59 QPEMenuBar* menu = menuBar();
58 60
59 QPopupMenu* file = new QPopupMenu; 61 QPopupMenu* file = new QPopupMenu;
60 file->insertItem(tr("Patience"), this, SLOT(initPatience()), CTRL+Key_F); 62 file->insertItem(tr("Patience"), this, SLOT(initPatience()), CTRL+Key_F);
61 file->insertItem(tr("Freecell"), this, SLOT(initFreecell()), CTRL+Key_F); 63 file->insertItem(tr("Freecell"), this, SLOT(initFreecell()), CTRL+Key_F);
64 file->insertItem(tr("Chicane"), this, SLOT(initChicane()), CTRL+Key_F);
65 file->insertItem(tr("Harp"), this, SLOT(initHarp()), CTRL+Key_F);
62 menu->insertItem(tr("&Game"), file); 66 menu->insertItem(tr("&Game"), file);
63 67
64 menu->insertSeparator(); 68 menu->insertSeparator();
65 69
66 settings = new QPopupMenu; 70 settings = new QPopupMenu;
67 settings->insertItem(tr("&Change Card Backs"), this, SLOT(changeCardBacks()), Key_F2); 71 settings->insertItem(tr("&Change Card Backs"), this, SLOT(changeCardBacks()), Key_F2);
68 snap_id = settings->insertItem(tr("&Snap To Position"), this, SLOT(snapToggle()), Key_F3); 72 snap_id = settings->insertItem(tr("&Snap To Position"), this, SLOT(snapToggle()), Key_F3);
69 settings->setCheckable(TRUE); 73 settings->setCheckable(TRUE);
70 menu->insertItem(tr("&Settings"),settings); 74 menu->insertItem(tr("&Settings"),settings);
71 75
72 menu->insertSeparator(); 76 menu->insertSeparator();
73 77
74 QPopupMenu* help = new QPopupMenu; 78 QPopupMenu* help = new QPopupMenu;
75 help->insertItem(tr("&About"), this, SLOT(help()), Key_F1); 79 help->insertItem(tr("&About"), this, SLOT(help()), Key_F1);
76 help->setItemChecked(dbf_id, TRUE); 80 help->setItemChecked(dbf_id, TRUE);
77 menu->insertItem(tr("&Help"),help); 81 menu->insertItem(tr("&Help"),help);
78#else 82#else
79 QMenuBar* menu = menuBar(); 83 QMenuBar* menu = menuBar();
80 84
81 QPopupMenu* file = new QPopupMenu; 85 QPopupMenu* file = new QPopupMenu;
82 file->insertItem(tr("Patience"), this, SLOT(initPatience())); 86 file->insertItem(tr("Patience"), this, SLOT(initPatience()));
83 file->insertItem(tr("Freecell"), this, SLOT(initFreecell())); 87 file->insertItem(tr("Freecell"), this, SLOT(initFreecell()));
88 file->insertItem(tr("Chicane"), this, SLOT(initChicane()));
89 file->insertItem(tr("Harp"), this, SLOT(initHarp()));
84 menu->insertItem(tr("Play"), file); 90 menu->insertItem(tr("Play"), file);
85 91
86 menu->insertSeparator(); 92 menu->insertSeparator();
87 93
88 settings = new QPopupMenu; 94 settings = new QPopupMenu;
89 settings->setCheckable(TRUE); 95 settings->setCheckable(TRUE);
90 settings->insertItem(tr("Change Card Backs"), this, SLOT(changeCardBacks())); 96 settings->insertItem(tr("Change Card Backs"), this, SLOT(changeCardBacks()));
91 snap_id = settings->insertItem(tr("Snap To Position"), this, SLOT(snapToggle())); 97 snap_id = settings->insertItem(tr("Snap To Position"), this, SLOT(snapToggle()));
92 QString m; 98 QString m;
93 99
94 drawId = settings->insertItem(tr("Turn One Card"), this, SLOT(drawnToggle())); 100 drawId = settings->insertItem(tr("Turn One Card"), this, SLOT(drawnToggle()));
95 menu->insertItem(tr("Settings"),settings); 101 menu->insertItem(tr("Settings"),settings);
96 102
97#endif 103#endif
98 104
99 menu->show(); 105 menu->show();
@@ -105,32 +111,48 @@ CanvasCardWindow::CanvasCardWindow(QWidget* parent, const char* name, WFlags f)
105 gameType = cfg.readNumEntry( "GameType", -1 ); 111 gameType = cfg.readNumEntry( "GameType", -1 );
106 drawThree = cfg.readBoolEntry( "DrawThree", TRUE); 112 drawThree = cfg.readBoolEntry( "DrawThree", TRUE);
107 if ( gameType == 0 ) { 113 if ( gameType == 0 ) {
108 cardGame = new PatienceCardGame( &canvas, snapOn, this ); 114 cardGame = new PatienceCardGame( &canvas, snapOn, this );
109 cardGame->setNumberToDraw(drawThree ? 3 : 1); 115 cardGame->setNumberToDraw(drawThree ? 3 : 1);
110 setCaption(tr("Patience")); 116 setCaption(tr("Patience"));
111 setCentralWidget(cardGame); 117 setCentralWidget(cardGame);
112 cardGame->readConfig( cfg ); 118 cardGame->readConfig( cfg );
113 setCardBacks(); 119 setCardBacks();
114 } else if ( gameType == 1 ) { 120 } else if ( gameType == 1 ) {
115 cardGame = new FreecellCardGame( &canvas, snapOn, this ); 121 cardGame = new FreecellCardGame( &canvas, snapOn, this );
116 setCaption(tr("Freecell")); 122 setCaption(tr("Freecell"));
117 setCentralWidget(cardGame); 123 setCentralWidget(cardGame);
118 //cardGame->newGame(); // Until we know how to handle reading freecell config 124 //cardGame->newGame(); // Until we know how to handle reading freecell config
119 cardGame->readConfig( cfg ); 125 cardGame->readConfig( cfg );
120 setCardBacks(); 126 setCardBacks();
127 } else if ( gameType == 2 ) {
128 cardGame = new ChicaneCardGame( &canvas, snapOn, this );
129 cardGame->setNumberToDraw(1);
130 setCaption(tr("Chicane"));
131 setCentralWidget(cardGame);
132 //cardGame->newGame(); // Until we know how to handle reading freecell config
133 cardGame->readConfig( cfg );
134 setCardBacks();
135 } else if ( gameType == 3 ) {
136 cardGame = new HarpCardGame( &canvas, snapOn, this );
137 cardGame->setNumberToDraw(1);
138 setCaption(tr("Harp"));
139 setCentralWidget(cardGame);
140 //cardGame->newGame(); // Until we know how to handle reading freecell config
141 cardGame->readConfig( cfg );
142 setCardBacks();
121 } else { 143 } else {
122 // Probably there isn't a config file or it is broken 144 // Probably there isn't a config file or it is broken
123 // Start a new game 145 // Start a new game
124 initPatience(); 146 initPatience();
125 } 147 }
126 148
127 updateDraw(); 149 updateDraw();
128} 150}
129 151
130 152
131CanvasCardWindow::~CanvasCardWindow() 153CanvasCardWindow::~CanvasCardWindow()
132{ 154{
133 if (cardGame) { 155 if (cardGame) {
134 Config cfg("Patience"); 156 Config cfg("Patience");
135 cfg.setGroup( "GlobalSettings" ); 157 cfg.setGroup( "GlobalSettings" );
136 cfg.writeEntry( "GameType", gameType ); 158 cfg.writeEntry( "GameType", gameType );
@@ -168,32 +190,63 @@ void CanvasCardWindow::initPatience()
168 190
169void CanvasCardWindow::initFreecell() 191void CanvasCardWindow::initFreecell()
170{ 192{
171 // Create New Game 193 // Create New Game
172 if ( cardGame ) { 194 if ( cardGame ) {
173 delete cardGame; 195 delete cardGame;
174 } 196 }
175 cardGame = new FreecellCardGame( &canvas, snapOn, this ); 197 cardGame = new FreecellCardGame( &canvas, snapOn, this );
176 gameType = 1; 198 gameType = 1;
177 setCaption(tr("Freecell")); 199 setCaption(tr("Freecell"));
178 setCentralWidget(cardGame); 200 setCentralWidget(cardGame);
179 cardGame->newGame(); 201 cardGame->newGame();
180 setCardBacks(); 202 setCardBacks();
181} 203}
182 204
183 205
206void CanvasCardWindow::initChicane()
207{
208 // Create New Game
209 if ( cardGame ) {
210 delete cardGame;
211 }
212 cardGame = new ChicaneCardGame( &canvas, snapOn, this );
213 cardGame->setNumberToDraw(1);
214 gameType = 2;
215 setCaption(tr("Chicane"));
216 setCentralWidget(cardGame);
217 cardGame->newGame();
218 setCardBacks();
219}
220
221void CanvasCardWindow::initHarp()
222{
223 // Create New Game
224 if ( cardGame ) {
225 delete cardGame;
226 }
227 cardGame = new HarpCardGame( &canvas, snapOn, this );
228 cardGame->setNumberToDraw(1);
229 gameType = 3;
230 setCaption(tr("Harp"));
231 setCentralWidget(cardGame);
232 cardGame->newGame();
233 setCardBacks();
234}
235
236
184void CanvasCardWindow::snapToggle() 237void CanvasCardWindow::snapToggle()
185{ 238{
186 snapOn = !snapOn; 239 snapOn = !snapOn;
187 settings->setItemChecked(snap_id, snapOn); 240 settings->setItemChecked(snap_id, snapOn);
188 cardGame->toggleSnap(); 241 cardGame->toggleSnap();
189} 242}
190 243
191 244
192void CanvasCardWindow::drawnToggle() 245void CanvasCardWindow::drawnToggle()
193{ 246{
194 cardGame->toggleCardsDrawn(); 247 cardGame->toggleCardsDrawn();
195 updateDraw(); 248 updateDraw();
196} 249}
197 250
198void CanvasCardWindow::updateDraw() { 251void CanvasCardWindow::updateDraw() {
199 if(cardGame->cardsDrawn() == 3) 252 if(cardGame->cardsDrawn() == 3)
diff --git a/noncore/games/solitaire/canvascardwindow.h b/noncore/games/solitaire/canvascardwindow.h
index b75d40a..aa76730 100644
--- a/noncore/games/solitaire/canvascardwindow.h
+++ b/noncore/games/solitaire/canvascardwindow.h
@@ -32,32 +32,34 @@ class QPopupMenu;
32class CanvasCardWindow : public QMainWindow { 32class CanvasCardWindow : public QMainWindow {
33 Q_OBJECT 33 Q_OBJECT
34 34
35public: 35public:
36 CanvasCardWindow(QWidget* parent=0, const char* name=0, WFlags f=0); 36 CanvasCardWindow(QWidget* parent=0, const char* name=0, WFlags f=0);
37 virtual ~CanvasCardWindow(); 37 virtual ~CanvasCardWindow();
38 38
39public slots: 39public slots:
40 void setCardBacks(); 40 void setCardBacks();
41 void changeCardBacks(); 41 void changeCardBacks();
42 void snapToggle(); 42 void snapToggle();
43 void drawnToggle(); 43 void drawnToggle();
44 44
45private slots: 45private slots:
46 void initFreecell(); 46 void initFreecell();
47 void initPatience(); 47 void initPatience();
48 void initChicane();
49 void initHarp();
48 50
49protected: 51protected:
50 virtual void resizeEvent(QResizeEvent *e); 52 virtual void resizeEvent(QResizeEvent *e);
51 53
52 void updateDraw(); 54 void updateDraw();
53private: 55private:
54 QCanvas canvas; 56 QCanvas canvas;
55 bool snapOn; 57 bool snapOn;
56 bool drawThree; 58 bool drawThree;
57 int drawId; 59 int drawId;
58 int cardBack; 60 int cardBack;
59 int gameType; 61 int gameType;
60 CanvasCardGame *cardGame; 62 CanvasCardGame *cardGame;
61 63
62 QPopupMenu* options; 64 QPopupMenu* options;
63 QPopupMenu* settings; 65 QPopupMenu* settings;
diff --git a/noncore/games/solitaire/card.h b/noncore/games/solitaire/card.h
index eb30d30..68ce425 100644
--- a/noncore/games/solitaire/card.h
+++ b/noncore/games/solitaire/card.h
@@ -44,41 +44,45 @@ public:
44 Card( eValue v, eSuit s, bool f ) : 44 Card( eValue v, eSuit s, bool f ) :
45 val(v), suit(s), faceUp(f), showing(FALSE), ix(0), iy(0), iz(0), cardPile(NULL) { } 45 val(v), suit(s), faceUp(f), showing(FALSE), ix(0), iy(0), iz(0), cardPile(NULL) { }
46 virtual ~Card() { } 46 virtual ~Card() { }
47 47
48 eValue getValue() { return val; } 48 eValue getValue() { return val; }
49 eSuit getSuit() { return suit; } 49 eSuit getSuit() { return suit; }
50 50
51 void setCardPile(CardPile *p) { cardPile = p; } 51 void setCardPile(CardPile *p) { cardPile = p; }
52 CardPile *getCardPile() { return cardPile; } 52 CardPile *getCardPile() { return cardPile; }
53 53
54 void setFace(bool f) { faceUp = f; /* flip(); */ } 54 void setFace(bool f) { faceUp = f; /* flip(); */ }
55 bool isFacing() { return faceUp; } 55 bool isFacing() { return faceUp; }
56 56
57 bool isShowing() { return showing; } 57 bool isShowing() { return showing; }
58 bool isRed() { return ((suit == diamonds) || (suit == hearts)); } 58 bool isRed() { return ((suit == diamonds) || (suit == hearts)); }
59 59
60 int getDeckNumber() { return deckNumber; }
61 void setDeckNumber(int n) { deckNumber=n; }
62
60 int getX(void) { return ix; } 63 int getX(void) { return ix; }
61 int getY(void) { return iy; } 64 int getY(void) { return iy; }
62 int getZ(void) { return iz; } 65 int getZ(void) { return iz; }
63 void flip(void) { flipTo(getX(), getY()); } 66 void flip(void) { flipTo(getX(), getY()); }
64 67
65 virtual void setPos(int x, int y, int z) { ix = x; iy = y; iz = z; } 68 virtual void setPos(int x, int y, int z) { ix = x; iy = y; iz = z; }
66 virtual void move(int x, int y) { ix = x; iy = y; } 69 virtual void move(int x, int y) { ix = x; iy = y; }
67 virtual void move(QPoint p) { ix = p.x(); iy = p.y(); } 70 virtual void move(QPoint p) { ix = p.x(); iy = p.y(); }
68 virtual void flipTo(int x, int y, int steps = 8) { ix = x; iy = y; faceUp = !faceUp; redraw(); Q_UNUSED(steps); } 71 virtual void flipTo(int x, int y, int steps = 8) { ix = x; iy = y; faceUp = !faceUp; redraw(); Q_UNUSED(steps); }
69 virtual void showCard(void) { showing = TRUE; } 72 virtual void showCard(void) { showing = TRUE; }
70 virtual void hideCard(void) { showing = FALSE; } 73 virtual void hideCard(void) { showing = FALSE; }
71protected: 74protected:
72 virtual void redraw(void) { } 75 virtual void redraw(void) { }
73private: 76private:
74 eValue val; 77 eValue val;
75 eSuit suit; 78 eSuit suit;
76 bool faceUp; 79 bool faceUp;
77 bool showing; 80 bool showing;
81 int deckNumber;
78 int ix, iy, iz; 82 int ix, iy, iz;
79 CardPile *cardPile; 83 CardPile *cardPile;
80}; 84};
81 85
82 86
83#endif 87#endif
84 88
diff --git a/noncore/games/solitaire/carddeck.cpp b/noncore/games/solitaire/carddeck.cpp
index 87c043a..a2d0076 100644
--- a/noncore/games/solitaire/carddeck.cpp
+++ b/noncore/games/solitaire/carddeck.cpp
@@ -10,72 +10,82 @@
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 <stdlib.h> 20#include <stdlib.h>
21#include <time.h> 21#include <time.h>
22#include "card.h" 22#include "card.h"
23#include "carddeck.h" 23#include "carddeck.h"
24 24
25 25
26CardDeck::CardDeck(int jokers) : numberOfJokers(jokers), deckCreated(FALSE) 26CardDeck::CardDeck(int jokers, int numOfDecks) : numberOfJokers(jokers), numberOfDecks(numOfDecks), deckCreated(FALSE)
27{ 27{
28 cards = new (Card *)[getNumberOfCards()]; 28 cards = new (Card *)[getNumberOfCards()];
29} 29}
30 30
31 31
32CardDeck::~CardDeck() 32CardDeck::~CardDeck()
33{ 33{
34 for (int i = 0; i < getNumberOfCards(); i++) 34 for (int i = 0; i < getNumberOfCards(); i++)
35 delete cards[i]; 35 delete cards[i];
36 delete cards; 36 delete cards;
37} 37}
38 38
39 39
40void CardDeck::createDeck() 40void CardDeck::createDeck()
41{ 41{
42 if (!deckCreated) { 42 if (!deckCreated) {
43 for (int i = 0; i < 52; i++) 43 for (int j = 0; j < getNumberOfDecks(); j++) {
44 cards[i] = newCard( (eValue)((i % 13) + 1), (eSuit)((i / 13) + 1), FALSE ); 44 for (int i = 0; i < 52; i++) {
45 cards[i+j*52] = newCard( (eValue)((i % 13) + 1), (eSuit)((i / 13) + 1), FALSE);
46 cards[i+j*52]->setDeckNumber(j);
47 }
48 }
45 for (int i = 0; i < getNumberOfJokers(); i++) 49 for (int i = 0; i < getNumberOfJokers(); i++)
46 cards[52 + i] = newCard( jokerVal, jokerSuit, FALSE ); 50 cards[52*getNumberOfDecks() + i] = newCard( jokerVal, jokerSuit, FALSE);
47 deckCreated = TRUE; 51 deckCreated = TRUE;
48 } 52 }
49} 53}
50 54
51 55
52void CardDeck::shuffle() 56void CardDeck::shuffle()
53{ 57{
54 srand(time(NULL)); 58 srand(time(NULL));
55 for (int i = 0; i < getNumberOfCards(); i++) { 59 for (int i = 0; i < getNumberOfCards(); i++) {
56 int index = rand() % getNumberOfCards(); 60 int index = rand() % getNumberOfCards();
57 Card *tmpCard = cards[i]; 61 Card *tmpCard = cards[i];
58 cards[i] = cards[index]; 62 cards[i] = cards[index];
59 cards[index] = tmpCard; 63 cards[index] = tmpCard;
60 } 64 }
61} 65}
62 66
63 67
64int CardDeck::getNumberOfCards() 68int CardDeck::getNumberOfCards()
65{ 69{
66 return 52 + getNumberOfJokers(); 70 return 52*getNumberOfDecks() + getNumberOfJokers();
67} 71}
68 72
69 73
74int CardDeck::getNumberOfDecks()
75{
76 return numberOfDecks;
77}
78
79
70int CardDeck::getNumberOfJokers() 80int CardDeck::getNumberOfJokers()
71{ 81{
72 return numberOfJokers; 82 return numberOfJokers;
73} 83}
74 84
75 85
76Card *CardDeck::newCard( eValue v, eSuit s, bool f ) 86Card *CardDeck::newCard( eValue v, eSuit s, bool f)
77{ 87{
78 return new Card(v, s, f); 88 return new Card(v, s, f);
79} 89}
80 90
81 91
diff --git a/noncore/games/solitaire/carddeck.h b/noncore/games/solitaire/carddeck.h
index 9ad35a9..026834f 100644
--- a/noncore/games/solitaire/carddeck.h
+++ b/noncore/games/solitaire/carddeck.h
@@ -14,36 +14,38 @@
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 CARD_DECK_H 20#ifndef CARD_DECK_H
21#define CARD_DECK_H 21#define CARD_DECK_H
22 22
23 23
24class Card; 24class Card;
25 25
26 26
27class CardDeck 27class CardDeck
28{ 28{
29public: 29public:
30 CardDeck(int jokers = 0); 30 CardDeck(int jokers = 0, int numOfDecks = 1);
31 virtual ~CardDeck(); 31 virtual ~CardDeck();
32 32
33 void createDeck(); 33 void createDeck();
34 void shuffle(); 34 void shuffle();
35 int getNumberOfCards(); 35 int getNumberOfCards();
36 int getNumberOfDecks();
36 int getNumberOfJokers(); 37 int getNumberOfJokers();
37 38
38 virtual Card *newCard( eValue v, eSuit s, bool f ); 39 virtual Card *newCard( eValue v, eSuit s, bool f );
39 virtual void deal() { } 40 virtual void deal() { }
40 41
41 Card **cards; 42 Card **cards;
42private: 43private:
43 int numberOfJokers; 44 int numberOfJokers;
45 int numberOfDecks;
44 bool deckCreated; 46 bool deckCreated;
45}; 47};
46 48
47 49
48#endif 50#endif
49 51
diff --git a/noncore/games/solitaire/cardgame.h b/noncore/games/solitaire/cardgame.h
index dd7efab..2e37c7f 100644
--- a/noncore/games/solitaire/cardgame.h
+++ b/noncore/games/solitaire/cardgame.h
@@ -18,28 +18,28 @@
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef CARD_GAME_H 20#ifndef CARD_GAME_H
21#define CARD_GAME_H 21#define CARD_GAME_H
22 22
23 23
24#include <qpoint.h> 24#include <qpoint.h>
25#include "card.h" 25#include "card.h"
26#include "cardpile.h" 26#include "cardpile.h"
27#include "carddeck.h" 27#include "carddeck.h"
28#include "cardgamelayout.h" 28#include "cardgamelayout.h"
29 29
30 30
31class CardGame : public CardGameLayout, public CardDeck 31class CardGame : public CardGameLayout, public CardDeck
32{ 32{
33public: 33public:
34 CardGame(int numOfJokers = 0) : CardGameLayout(), CardDeck(numOfJokers) { } 34 CardGame(int numOfJokers = 0, int numOfDecks = 1) : CardGameLayout(), CardDeck(numOfJokers,numOfDecks) { }
35 virtual ~CardGame() { } 35 virtual ~CardGame() { }
36 virtual void newGame(); 36 virtual void newGame();
37 virtual void mousePress(QPoint p) { Q_UNUSED(p); } 37 virtual void mousePress(QPoint p) { Q_UNUSED(p); }
38 virtual void mouseRelease(QPoint p) { Q_UNUSED(p); } 38 virtual void mouseRelease(QPoint p) { Q_UNUSED(p); }
39 virtual void mouseMove(QPoint p) { Q_UNUSED(p); } 39 virtual void mouseMove(QPoint p) { Q_UNUSED(p); }
40private: 40private:
41}; 41};
42 42
43 43
44#endif 44#endif
45 45
diff --git a/noncore/games/solitaire/cardpile.cpp b/noncore/games/solitaire/cardpile.cpp
index 0b738d2..3b15e93 100644
--- a/noncore/games/solitaire/cardpile.cpp
+++ b/noncore/games/solitaire/cardpile.cpp
@@ -89,26 +89,26 @@ bool CardPile::removeCard(Card *c) {
89 if (dealing || isAllowedToBeMoved(c)) { 89 if (dealing || isAllowedToBeMoved(c)) {
90 take(find(c)); 90 take(find(c));
91 cardRemoved(c); 91 cardRemoved(c);
92 return TRUE; 92 return TRUE;
93 } 93 }
94 return FALSE; 94 return FALSE;
95} 95}
96 96
97 97
98void CardPile::writeConfig( Config& cfg, QString name ) { 98void CardPile::writeConfig( Config& cfg, QString name ) {
99 int numberOfCards = 0; 99 int numberOfCards = 0;
100 cfg.setGroup( name ); 100 cfg.setGroup( name );
101 Card *card = cardOnBottom(); 101 Card *card = cardOnBottom();
102 while ( card ) { 102 while ( card ) {
103 QString cardStr; 103 QString cardStr;
104 cardStr.sprintf( "%i", numberOfCards ); 104 cardStr.sprintf( "%i", numberOfCards );
105 int val = (int)card->getValue() - 1 + ( (int)card->getSuit() - 1 ) * 13; 105 int val = (int)card->getValue()-1 + ((int)card->getSuit()-1)*13 + (int)card->getDeckNumber()*52;
106 cfg.writeEntry( "Card" + cardStr, val ); 106 cfg.writeEntry( "Card" + cardStr, val );
107 cfg.writeEntry( "CardFacing" + cardStr, card->isFacing() ); 107 cfg.writeEntry( "CardFacing" + cardStr, card->isFacing() );
108 card = cardInfront( card ); 108 card = cardInfront( card );
109 numberOfCards++; 109 numberOfCards++;
110 } 110 }
111 cfg.writeEntry("NumberOfCards", numberOfCards); 111 cfg.writeEntry("NumberOfCards", numberOfCards);
112} 112}
113 113
114 114
diff --git a/noncore/games/solitaire/chicanecardgame.cpp b/noncore/games/solitaire/chicanecardgame.cpp
new file mode 100644
index 0000000..a242419
--- a/dev/null
+++ b/noncore/games/solitaire/chicanecardgame.cpp
@@ -0,0 +1,171 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
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
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
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.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**
20** Modified by C.A.Mader 2002
21**
22**********************************************************************/
23#include <qgfx_qws.h>
24#include "chicanecardgame.h"
25
26
27extern int highestZ;
28
29
30 ChicaneCardGame::ChicaneCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent, 2)// Use 2 Decks
31{
32 highestZ = 0;
33
34 for (int i = 0; i < 8; i++) {
35 discardPiles[i] = new ChicaneDiscardPile( 27 + i * 26, 10, canvas() );
36 addCardPile(discardPiles[i]);
37 }
38 for (int i = 0; i < 8; i++) {
39 workingPiles[i] = new ChicaneWorkingPile( 27 + i * 26, 50, canvas() );
40 addCardPile(workingPiles[i]);
41 }
42 faceDownDealingPile = new ChicaneFaceDownDeck( 2, 10, canvas() );
43}
44
45
46void ChicaneCardGame::deal(void)
47{
48 highestZ = 1;
49 int t = 0;
50
51 beginDealing();
52
53 for (int i = 0; i < 8; i++) {
54 for (int k = 0; k < 4; k++, t++) {
55 Card *card = cards[t];
56 workingPiles[i]->addCardToTop(card);
57 card->setCardPile( workingPiles[i] );
58 card->setPos( 0, 0, highestZ );
59 card->setFace(k==3);
60 card->move( workingPiles[i]->getCardPos( card ) );
61 card->showCard();
62 highestZ++;
63 }
64 }
65
66 for ( ; t < getNumberOfCards(); t++) {
67 Card *card = cards[t];
68 faceDownDealingPile->addCardToTop(card);
69 card->setCardPile( faceDownDealingPile );
70 QPoint p = faceDownDealingPile->getCardPos( card );
71 card->setPos( p.x(), p.y(), highestZ );
72 card->showCard();
73 highestZ++;
74 }
75
76 endDealing();
77}
78
79
80void ChicaneCardGame::readConfig( Config& cfg )
81{
82 cfg.setGroup("GameState");
83
84 // Create Cards, but don't shuffle or deal them yet
85 createDeck();
86
87 // Move the cards to their piles (deal them to their previous places)
88 beginDealing();
89
90 highestZ = 1;
91
92 for (int i = 0; i < 8; i++) {
93 QString pile;
94 pile.sprintf( "ChicaneDiscardPile%i", i );
95 readPile( cfg, discardPiles[i], pile, highestZ );
96 }
97
98 for (int i = 0; i < 8; i++) {
99 QString pile;
100 pile.sprintf( "ChicaneWorkingPile%i", i );
101 readPile( cfg, workingPiles[i], pile, highestZ );
102 }
103
104 readPile( cfg, faceDownDealingPile, "ChicaneFaceDownDealingPile", highestZ );
105
106 highestZ++;
107
108 endDealing();
109}
110
111
112void ChicaneCardGame::writeConfig( Config& cfg )
113{
114 cfg.setGroup("GameState");
115 for ( int i = 0; i < 8; i++ ) {
116 QString pile;
117 pile.sprintf( "ChicaneDiscardPile%i", i );
118 discardPiles[i]->writeConfig( cfg, pile );
119 }
120 for ( int i = 0; i < 8; i++ ) {
121 QString pile;
122 pile.sprintf( "ChicaneWorkingPile%i", i );
123 workingPiles[i]->writeConfig( cfg, pile );
124 }
125 faceDownDealingPile->writeConfig( cfg, "ChicaneFaceDownDealingPile" );
126}
127
128
129bool ChicaneCardGame::mousePressCard( Card *card, QPoint p )
130{
131 Q_UNUSED(p);
132
133 CanvasCard *item = (CanvasCard *)card;
134 if (item->isFacing() != TRUE) {
135 // From facedown stack
136 if ((item->x() == 2) && ((int)item->y() == 10)) { // Deal a row of 8 cards
137 // Move 8 cards, one to each workingPile
138 beginDealing();
139 for (int i=0; i<8 && faceDownDealingPile->cardOnTop(); i++) {
140 CanvasCard *card = (CanvasCard *)faceDownDealingPile->cardOnTop();
141 card->setZ(highestZ);
142 highestZ++;
143 faceDownDealingPile->removeCard(card);
144 workingPiles[i]->addCardToTop(card);
145 card->setCardPile( workingPiles[i] );
146 card->setFace(FALSE);
147 QPoint p = workingPiles[i]->getCardPos(card);
148 card->flipTo( p.x(), p.y() );
149 }
150 endDealing();
151 }
152 moving = NULL;
153 moved = FALSE;
154
155 return TRUE;
156 } else if ( !card->getCardPile()->isAllowedToBeMoved(card) ) {// Don't allow unclean columns to be moved
157 moving = NULL;
158 return TRUE;
159 }
160
161 return FALSE;
162}
163
164
165
166void ChicaneCardGame::mousePress(QPoint p)
167{
168 Q_UNUSED(p);
169}
170
171
diff --git a/noncore/games/solitaire/chicanecardgame.h b/noncore/games/solitaire/chicanecardgame.h
new file mode 100644
index 0000000..668f5f4
--- a/dev/null
+++ b/noncore/games/solitaire/chicanecardgame.h
@@ -0,0 +1,165 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
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
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
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.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef CHICANE_CARD_GAME_H
21#define CHICANE_CARD_GAME_H
22
23
24#include "patiencecardgame.h"
25
26
27class ChicaneFaceDownDeck : public PatienceFaceDownDeck
28{
29public:
30 ChicaneFaceDownDeck(int x, int y, QCanvas *canvas) :
31 PatienceFaceDownDeck(x, y, canvas) { }
32
33};
34
35
36class ChicaneDiscardPile : public PatienceDiscardPile
37{
38public:
39 ChicaneDiscardPile(int x, int y, QCanvas *canvas) :
40 PatienceDiscardPile(x, y, canvas) { }
41
42};
43
44
45class ChicaneWorkingPile : public PatienceWorkingPile
46{
47public:
48 ChicaneWorkingPile(int x, int y, QCanvas *canvas) :
49 PatienceWorkingPile(x, y, canvas) { }
50
51 virtual bool isAllowedOnTop(Card *card) {
52 if ( card->isFacing() &&
53 // ( ( ( cardOnTop() == NULL ) && (card->getValue() == king) ) || // diese Zeile sorgt dafür dass nur Kings auf leere Plätze dürfen
54 ( (cardOnTop() == NULL) || // auf einen Freiplatz darf alles!
55 ( (cardOnTop() != NULL) &&
56 ((int)card->getValue() + 1 == (int)cardOnTop()->getValue()) &&
57 (card->isRed() != cardOnTop()->isRed()) ) ) )
58 return TRUE;
59 return FALSE;
60 }
61 virtual bool isAllowedToBeMoved(Card *card) {
62 if (!card->isFacing()) return FALSE;
63
64 int nextExpectedValue = (int)card->getValue();
65 bool nextExpectedColor = card->isRed();
66
67 while ((card != NULL)) {
68 if ( (int)card->getValue() != nextExpectedValue )
69 return FALSE;
70 if ( card->isRed() != nextExpectedColor )
71 return FALSE;
72 nextExpectedValue--;;
73 nextExpectedColor = !nextExpectedColor;
74 card = cardInfront(card);
75 }
76 return TRUE;
77 }
78
79 virtual void cardRemoved(Card *card) {
80 Q_UNUSED(card);
81
82 Card *newTopCard = cardOnTop();
83
84 if ( !newTopCard ) {
85 top = QPoint( pileX, pileY );
86 setNextX( pileX );
87 setNextY( pileY );
88 return;
89 } else {
90 top = getCardPos(NULL);
91 if ( newTopCard->isFacing() == FALSE ) {
92 int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13;
93 // correct the position taking in to account the card is not
94 // yet flipped, but will become flipped
95 top = QPoint( top.x(), top.y() - 3 ); // Keine Verschiebung!
96 newTopCard->flipTo( top.x(), top.y() );
97 top = QPoint( top.x(), top.y() + offsetDown );
98 }
99 setNextX( top.x() );
100 setNextY( top.y() );
101 }
102 }
103 virtual QPoint getCardPos(Card *c) {
104 int x = pileX, y = pileY;
105 Card *card = cardOnBottom();
106 while ((card != c) && (card != NULL)) {
107 if (card->isFacing()) {
108 int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13;
109 y += offsetDown;
110 } else {
111 x += 0; // Keine Verschiebung!
112 y += 3;
113 }
114 card = cardInfront(card);
115 }
116 return QPoint( x, y );
117 }
118
119 virtual QPoint getHypertheticalNextCardPos(void) {
120// return top;
121 return QPoint( getNextX(), getNextY() );
122 }
123
124private:
125 QPoint top;
126
127};
128
129
130class ChicaneCardGame : public CanvasCardGame
131{
132public:
133 ChicaneCardGame(QCanvas *c, bool snap, QWidget *parent = 0);
134// virtual ~ChicaneCardGame();
135 virtual void deal(void);
136 virtual bool haveWeWon() {
137 return ( discardPiles[0]->kingOnTop() &&
138 discardPiles[1]->kingOnTop() &&
139 discardPiles[2]->kingOnTop() &&
140 discardPiles[3]->kingOnTop() &&
141 discardPiles[4]->kingOnTop() &&
142 discardPiles[5]->kingOnTop() &&
143 discardPiles[6]->kingOnTop() &&
144 discardPiles[7]->kingOnTop() );;
145 }
146 virtual void mousePress(QPoint p);
147 virtual void mouseRelease(QPoint p) { Q_UNUSED(p); }
148// virtual void mouseMove(QPoint p);
149 virtual bool mousePressCard(Card *card, QPoint p);
150 virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); }
151// virtual void mouseMoveCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); }
152 bool canTurnOverDeck(void) { return (FALSE); }
153 void throughDeck(void) { }
154 bool snapOn;
155 void writeConfig( Config& cfg );
156 void readConfig( Config& cfg );
157private:
158 ChicaneWorkingPile *workingPiles[8];
159 ChicaneDiscardPile *discardPiles[8];
160 ChicaneFaceDownDeck *faceDownDealingPile;
161};
162
163
164#endif
165
diff --git a/noncore/games/solitaire/harpcardgame.cpp b/noncore/games/solitaire/harpcardgame.cpp
new file mode 100644
index 0000000..22715ec
--- a/dev/null
+++ b/noncore/games/solitaire/harpcardgame.cpp
@@ -0,0 +1,171 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
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
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
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.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**
20** Modified by C.A.Mader 2002
21**
22**********************************************************************/
23#include <qgfx_qws.h>
24#include "harpcardgame.h"
25
26
27extern int highestZ;
28
29
30 HarpCardGame::HarpCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent, 2)// Use 2 Decks
31{
32 highestZ = 0;
33
34 for (int i = 0; i < 8; i++) {
35 discardPiles[i] = new HarpDiscardPile( 27 + i * 26, 10, canvas() );
36 addCardPile(discardPiles[i]);
37 }
38 for (int i = 0; i < 8; i++) {
39 workingPiles[i] = new HarpWorkingPile( 27 + i * 26, 50, canvas() );
40 addCardPile(workingPiles[i]);
41 }
42 faceDownDealingPile = new HarpFaceDownDeck( 2, 10, canvas() );
43}
44
45
46void HarpCardGame::deal(void)
47{
48 highestZ = 1;
49 int t = 0;
50
51 beginDealing();
52
53 for (int i = 0; i < 8; i++) {
54 for (int k = 0; k < i+1; k++, t++) {
55 Card *card = cards[t];
56 workingPiles[i]->addCardToTop(card);
57 card->setCardPile( workingPiles[i] );
58 card->setPos( 0, 0, highestZ );
59 card->setFace(k==i);
60 card->move( workingPiles[i]->getCardPos( card ) );
61 card->showCard();
62 highestZ++;
63 }
64 }
65
66 for ( ; t < getNumberOfCards(); t++) {
67 Card *card = cards[t];
68 faceDownDealingPile->addCardToTop(card);
69 card->setCardPile( faceDownDealingPile );
70 QPoint p = faceDownDealingPile->getCardPos( card );
71 card->setPos( p.x(), p.y(), highestZ );
72 card->showCard();
73 highestZ++;
74 }
75
76 endDealing();
77}
78
79
80void HarpCardGame::readConfig( Config& cfg )
81{
82 cfg.setGroup("GameState");
83
84 // Create Cards, but don't shuffle or deal them yet
85 createDeck();
86
87 // Move the cards to their piles (deal them to their previous places)
88 beginDealing();
89
90 highestZ = 1;
91
92 for (int i = 0; i < 8; i++) {
93 QString pile;
94 pile.sprintf( "HarpDiscardPile%i", i );
95 readPile( cfg, discardPiles[i], pile, highestZ );
96 }
97
98 for (int i = 0; i < 8; i++) {
99 QString pile;
100 pile.sprintf( "HarpWorkingPile%i", i );
101 readPile( cfg, workingPiles[i], pile, highestZ );
102 }
103
104 readPile( cfg, faceDownDealingPile, "HarpFaceDownDealingPile", highestZ );
105
106 highestZ++;
107
108 endDealing();
109}
110
111
112void HarpCardGame::writeConfig( Config& cfg )
113{
114 cfg.setGroup("GameState");
115 for ( int i = 0; i < 8; i++ ) {
116 QString pile;
117 pile.sprintf( "HarpDiscardPile%i", i );
118 discardPiles[i]->writeConfig( cfg, pile );
119 }
120 for ( int i = 0; i < 8; i++ ) {
121 QString pile;
122 pile.sprintf( "HarpWorkingPile%i", i );
123 workingPiles[i]->writeConfig( cfg, pile );
124 }
125 faceDownDealingPile->writeConfig( cfg, "HarpFaceDownDealingPile" );
126}
127
128
129bool HarpCardGame::mousePressCard( Card *card, QPoint p )
130{
131 Q_UNUSED(p);
132
133 CanvasCard *item = (CanvasCard *)card;
134 if (item->isFacing() != TRUE) {
135 // From facedown stack
136 if ((item->x() == 2) && ((int)item->y() == 10)) { // Deal a row of 8 cards
137 // Move 8 cards, one to each workingPile
138 beginDealing();
139 for (int i=0; i<8 && faceDownDealingPile->cardOnTop(); i++) {
140 CanvasCard *card = (CanvasCard *)faceDownDealingPile->cardOnTop();
141 card->setZ(highestZ);
142 highestZ++;
143 faceDownDealingPile->removeCard(card);
144 workingPiles[i]->addCardToTop(card);
145 card->setCardPile( workingPiles[i] );
146 card->setFace(FALSE);
147 QPoint p = workingPiles[i]->getCardPos(card);
148 card->flipTo( p.x(), p.y() );
149 }
150 endDealing();
151 }
152 moving = NULL;
153 moved = FALSE;
154
155 return TRUE;
156 } else if ( !card->getCardPile()->isAllowedToBeMoved(card) ) {// Don't allow unclean columns to be moved
157 moving = NULL;
158 return TRUE;
159 }
160
161 return FALSE;
162}
163
164
165
166void HarpCardGame::mousePress(QPoint p)
167{
168 Q_UNUSED(p);
169}
170
171
diff --git a/noncore/games/solitaire/harpcardgame.h b/noncore/games/solitaire/harpcardgame.h
new file mode 100644
index 0000000..d1733fd
--- a/dev/null
+++ b/noncore/games/solitaire/harpcardgame.h
@@ -0,0 +1,165 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
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
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
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.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef HARP_CARD_GAME_H
21#define HARP_CARD_GAME_H
22
23
24#include "patiencecardgame.h"
25
26
27class HarpFaceDownDeck : public PatienceFaceDownDeck
28{
29public:
30 HarpFaceDownDeck(int x, int y, QCanvas *canvas) :
31 PatienceFaceDownDeck(x, y, canvas) { }
32
33};
34
35
36class HarpDiscardPile : public PatienceDiscardPile
37{
38public:
39 HarpDiscardPile(int x, int y, QCanvas *canvas) :
40 PatienceDiscardPile(x, y, canvas) { }
41
42};
43
44
45class HarpWorkingPile : public PatienceWorkingPile
46{
47public:
48 HarpWorkingPile(int x, int y, QCanvas *canvas) :
49 PatienceWorkingPile(x, y, canvas) { }
50
51 virtual bool isAllowedOnTop(Card *card) {
52 if ( card->isFacing() &&
53 // ( ( ( cardOnTop() == NULL ) && (card->getValue() == king) ) || // diese Zeile sorgt dafür dass nur Kings auf leere Plätze dürfen
54 ( (cardOnTop() == NULL) || // auf einen Freiplatz darf alles!
55 ( (cardOnTop() != NULL) &&
56 ((int)card->getValue() + 1 == (int)cardOnTop()->getValue()) &&
57 (card->isRed() != cardOnTop()->isRed()) ) ) )
58 return TRUE;
59 return FALSE;
60 }
61 virtual bool isAllowedToBeMoved(Card *card) {
62 if (!card->isFacing()) return FALSE;
63
64 int nextExpectedValue = (int)card->getValue();
65 bool nextExpectedColor = card->isRed();
66
67 while ((card != NULL)) {
68 if ( (int)card->getValue() != nextExpectedValue )
69 return FALSE;
70 if ( card->isRed() != nextExpectedColor )
71 return FALSE;
72 nextExpectedValue--;;
73 nextExpectedColor = !nextExpectedColor;
74 card = cardInfront(card);
75 }
76 return TRUE;
77 }
78
79 virtual void cardRemoved(Card *card) {
80 Q_UNUSED(card);
81
82 Card *newTopCard = cardOnTop();
83
84 if ( !newTopCard ) {
85 top = QPoint( pileX, pileY );
86 setNextX( pileX );
87 setNextY( pileY );
88 return;
89 } else {
90 top = getCardPos(NULL);
91 if ( newTopCard->isFacing() == FALSE ) {
92 int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13;
93 // correct the position taking in to account the card is not
94 // yet flipped, but will become flipped
95 top = QPoint( top.x(), top.y() - 3 ); // Keine Verschiebung!
96 newTopCard->flipTo( top.x(), top.y() );
97 top = QPoint( top.x(), top.y() + offsetDown );
98 }
99 setNextX( top.x() );
100 setNextY( top.y() );
101 }
102 }
103 virtual QPoint getCardPos(Card *c) {
104 int x = pileX, y = pileY;
105 Card *card = cardOnBottom();
106 while ((card != c) && (card != NULL)) {
107 if (card->isFacing()) {
108 int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13;
109 y += offsetDown;
110 } else {
111 x += 0; // Keine Verschiebung!
112 y += 3;
113 }
114 card = cardInfront(card);
115 }
116 return QPoint( x, y );
117 }
118
119 virtual QPoint getHypertheticalNextCardPos(void) {
120// return top;
121 return QPoint( getNextX(), getNextY() );
122 }
123
124private:
125 QPoint top;
126
127};
128
129
130class HarpCardGame : public CanvasCardGame
131{
132public:
133 HarpCardGame(QCanvas *c, bool snap, QWidget *parent = 0);
134// virtual ~HarpCardGame();
135 virtual void deal(void);
136 virtual bool haveWeWon() {
137 return ( discardPiles[0]->kingOnTop() &&
138 discardPiles[1]->kingOnTop() &&
139 discardPiles[2]->kingOnTop() &&
140 discardPiles[3]->kingOnTop() &&
141 discardPiles[4]->kingOnTop() &&
142 discardPiles[5]->kingOnTop() &&
143 discardPiles[6]->kingOnTop() &&
144 discardPiles[7]->kingOnTop() );;
145 }
146 virtual void mousePress(QPoint p);
147 virtual void mouseRelease(QPoint p) { Q_UNUSED(p); }
148// virtual void mouseMove(QPoint p);
149 virtual bool mousePressCard(Card *card, QPoint p);
150 virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); }
151// virtual void mouseMoveCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); }
152 bool canTurnOverDeck(void) { return (FALSE); }
153 void throughDeck(void) { }
154 bool snapOn;
155 void writeConfig( Config& cfg );
156 void readConfig( Config& cfg );
157private:
158 HarpWorkingPile *workingPiles[8];
159 HarpDiscardPile *discardPiles[8];
160 HarpFaceDownDeck *faceDownDealingPile;
161};
162
163
164#endif
165
diff --git a/noncore/games/solitaire/patiencecardgame.cpp b/noncore/games/solitaire/patiencecardgame.cpp
index fc91b26..1b38072 100644
--- a/noncore/games/solitaire/patiencecardgame.cpp
+++ b/noncore/games/solitaire/patiencecardgame.cpp
@@ -181,36 +181,34 @@ bool PatienceCardGame::mousePressCard( Card *card, QPoint p )
181 CanvasCard *item = (CanvasCard *)card; 181 CanvasCard *item = (CanvasCard *)card;
182 if (item->isFacing() != TRUE) { 182 if (item->isFacing() != TRUE) {
183 // From facedown stack 183 // From facedown stack
184 if ((item->x() == 5) && ((int)item->y() == 10)) { 184 if ((item->x() == 5) && ((int)item->y() == 10)) {
185 item->setZ(highestZ); 185 item->setZ(highestZ);
186 highestZ++; 186 highestZ++;
187 187
188 // Added Code 188 // Added Code
189 faceDownDealingPile->removeCard(item); 189 faceDownDealingPile->removeCard(item);
190 faceUpDealingPile->addCardToTop(item); 190 faceUpDealingPile->addCardToTop(item);
191 item->setCardPile( faceUpDealingPile ); 191 item->setCardPile( faceUpDealingPile );
192 192
193 if ( qt_screen->deviceWidth() < 200 ) 193 if ( qt_screen->deviceWidth() < 200 )
194 item->flipTo( 30, (int)item->y() ); 194 item->flipTo( 30, (int)item->y() );
195 else 195 else
196 item->flipTo( 35, (int)item->y() ); 196 item->flipTo( 35, (int)item->y() );
197 } else { 197 } else return FALSE; // <- was missing, caused facedown card to react
198 // fix from cmader by tille 198 // to clicking, which is wrong
199 return false;
200 }
201 moving = NULL; 199 moving = NULL;
202 moved = FALSE; 200 moved = FALSE;
203 201
204 // move two other cards if we flip three at a time 202 // move two other cards if we flip three at a time
205 int flipped = 1; 203 int flipped = 1;
206 QCanvasItemList l = canvas()->collisions( p ); 204 QCanvasItemList l = canvas()->collisions( p );
207 for (QCanvasItemList::Iterator it = l.begin(); (it != l.end()) && (flipped != cardsDrawn()); ++it) { 205 for (QCanvasItemList::Iterator it = l.begin(); (it != l.end()) && (flipped != cardsDrawn()); ++it) {
208 if ( (*it)->rtti() == canvasCardId ) { 206 if ( (*it)->rtti() == canvasCardId ) {
209 CanvasCard *item = (CanvasCard *)*it; 207 CanvasCard *item = (CanvasCard *)*it;
210 if (item->animated()) 208 if (item->animated())
211 continue; 209 continue;
212 item->setZ(highestZ); 210 item->setZ(highestZ);
213 highestZ++; 211 highestZ++;
214 flipped++; 212 flipped++;
215 213
216 // Added Code 214 // Added Code
diff --git a/noncore/games/solitaire/solitaire.pro b/noncore/games/solitaire/solitaire.pro
index 01d87ed..b2ba5aa 100755
--- a/noncore/games/solitaire/solitaire.pro
+++ b/noncore/games/solitaire/solitaire.pro
@@ -1,21 +1,24 @@
1 TEMPLATE= app 1 TEMPLATE= app
2 CONFIG += qt warn_on release 2 CONFIG += qt warn_on release
3 DESTDIR = $(OPIEDIR)/bin 3 DESTDIR = $(OPIEDIR)/bin
4 HEADERS = canvascard.h canvasshapes.h cardgame.h cardgamelayout.h cardpile.h card.h carddeck.h canvascardgame.h freecellcardgame.h patiencecardgame.h canvascardwindow.h 4
5 SOURCES = canvascard.cpp canvasshapes.cpp cardgame.cpp cardgamelayout.cpp cardpile.cpp card.cpp carddeck.cpp canvascardgame.cpp freecellcardgame.cpp patiencecardgame.cpp canvascardwindow.cpp main.cpp 5 HEADERS = canvascard.h canvasshapes.h cardgame.h cardgamelayout.h cardpile.h card.h carddeck.h canvascardgame.h freecellcardgame.h chicanecardgame.h harpcardgame.h patiencecardgame.h canvascardwindow.h
6
7 SOURCES = canvascard.cpp canvasshapes.cpp cardgame.cpp cardgamelayout.cpp cardpile.cpp card.cpp carddeck.cpp canvascardgame.cpp freecellcardgame.cpp chicanecardgame.cpp harpcardgame.cpp patiencecardgame.cpp canvascardwindow.cpp main.cpp
8
6 TARGET = patience 9 TARGET = patience
7INCLUDEPATH += $(OPIEDIR)/include 10INCLUDEPATH += $(OPIEDIR)/include
8 DEPENDPATH+= $(OPIEDIR)/include 11 DEPENDPATH+= $(OPIEDIR)/include
9LIBS += -lqpe 12LIBS += -lqpe
10 REQUIRES= patience 13 REQUIRES= patience
11 14
12TRANSLATIONS = ../../../i18n/de/patience.ts \ 15TRANSLATIONS = ../../../i18n/de/patience.ts \
13 ../../../i18n/en/patience.ts \ 16 ../../../i18n/en/patience.ts \
14 ../../../i18n/es/patience.ts \ 17 ../../../i18n/es/patience.ts \
15 ../../../i18n/fr/patience.ts \ 18 ../../../i18n/fr/patience.ts \
16 ../../../i18n/hu/patience.ts \ 19 ../../../i18n/hu/patience.ts \
17 ../../../i18n/ja/patience.ts \ 20 ../../../i18n/ja/patience.ts \
18 ../../../i18n/ko/patience.ts \ 21 ../../../i18n/ko/patience.ts \
19 ../../../i18n/no/patience.ts \ 22 ../../../i18n/no/patience.ts \
20 ../../../i18n/pl/patience.ts \ 23 ../../../i18n/pl/patience.ts \
21 ../../../i18n/pt/patience.ts \ 24 ../../../i18n/pt/patience.ts \