summaryrefslogtreecommitdiff
authortille <tille>2002-07-10 13:05:07 (UTC)
committer tille <tille>2002-07-10 13:05:07 (UTC)
commit5d989e509abecf74aaa4eb88abf52a6821d19501 (patch) (unidiff)
tree3e61348802a9ea05980e91e13344a45be509b7d1
parent32954f729822e2d25f9e116400cbf2522a88ce42 (diff)
downloadopie-5d989e509abecf74aaa4eb88abf52a6821d19501.zip
opie-5d989e509abecf74aaa4eb88abf52a6821d19501.tar.gz
opie-5d989e509abecf74aaa4eb88abf52a6821d19501.tar.bz2
cam implemented new game teeclub and pile resizing
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/solitaire/canvascardgame.cpp4
-rw-r--r--noncore/games/solitaire/canvascardwindow.cpp28
-rw-r--r--noncore/games/solitaire/canvascardwindow.h1
-rw-r--r--noncore/games/solitaire/cardgamelayout.cpp2
-rw-r--r--noncore/games/solitaire/cardpile.cpp3
-rw-r--r--noncore/games/solitaire/cardpile.h14
-rwxr-xr-xnoncore/games/solitaire/solitaire.pro35
-rw-r--r--noncore/games/solitaire/teeclubcardgame.cpp194
-rw-r--r--noncore/games/solitaire/teeclubcardgame.h217
9 files changed, 476 insertions, 22 deletions
diff --git a/noncore/games/solitaire/canvascardgame.cpp b/noncore/games/solitaire/canvascardgame.cpp
index 357e798..4404b04 100644
--- a/noncore/games/solitaire/canvascardgame.cpp
+++ b/noncore/games/solitaire/canvascardgame.cpp
@@ -372,14 +372,14 @@ void CanvasCardGame::readPile( Config& cfg, CardPile *pile, QString name, int& h
372 cardStr.sprintf( "%i", i ); 372 cardStr.sprintf( "%i", i );
373 int val = cfg.readNumEntry( "Card" + cardStr ); 373 int val = cfg.readNumEntry( "Card" + cardStr );
374 bool facing = cfg.readBoolEntry( "CardFacing" + cardStr ); 374 bool facing = cfg.readBoolEntry( "CardFacing" + cardStr );
375 375
376 card = cards[ val ]; 376 card = cards[ val ];
377 card->setFace(facing); 377 card->setFace(facing);
378 pile->addCardToTop(card); 378 card->setCardPile(pile); // cam: setCardPile muss vor addCardToTop passieren
379 card->setCardPile(pile); 379 pile->addCardToTop(card); // weil sonst absturz wg cardAddedToTop
380 QPoint p = pile->getCardPos( card ); 380 QPoint p = pile->getCardPos( card );
381 card->setPos( p.x(), p.y(), highestZ ); 381 card->setPos( p.x(), p.y(), highestZ );
382 card->showCard(); 382 card->showCard();
383 highestZ++; 383 highestZ++;
384 } 384 }
385} 385}
diff --git a/noncore/games/solitaire/canvascardwindow.cpp b/noncore/games/solitaire/canvascardwindow.cpp
index e1c021e..450b4db 100644
--- a/noncore/games/solitaire/canvascardwindow.cpp
+++ b/noncore/games/solitaire/canvascardwindow.cpp
@@ -20,12 +20,13 @@
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" 24#include "chicanecardgame.h"
25#include "harpcardgame.h" 25#include "harpcardgame.h"
26#include "teeclubcardgame.h"
26 27
27#include <qpe/resource.h> 28#include <qpe/resource.h>
28 29
29#include <qmainwindow.h> 30#include <qmainwindow.h>
30#include <qpopupmenu.h> 31#include <qpopupmenu.h>
31#include <qstyle.h> 32#include <qstyle.h>
@@ -60,12 +61,13 @@ CanvasCardWindow::CanvasCardWindow(QWidget* parent, const char* name, WFlags f)
60 61
61 QPopupMenu* file = new QPopupMenu; 62 QPopupMenu* file = new QPopupMenu;
62 file->insertItem(tr("Patience"), this, SLOT(initPatience()), CTRL+Key_F); 63 file->insertItem(tr("Patience"), this, SLOT(initPatience()), CTRL+Key_F);
63 file->insertItem(tr("Freecell"), this, SLOT(initFreecell()), CTRL+Key_F); 64 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("Chicane"), this, SLOT(initChicane()), CTRL+Key_F);
65 file->insertItem(tr("Harp"), this, SLOT(initHarp()), CTRL+Key_F); 66 file->insertItem(tr("Harp"), this, SLOT(initHarp()), CTRL+Key_F);
67 file->insertItem(tr("Teeclub"), this, SLOT(initTeeclub()), CTRL+Key_F);
66 menu->insertItem(tr("&Game"), file); 68 menu->insertItem(tr("&Game"), file);
67 69
68 menu->insertSeparator(); 70 menu->insertSeparator();
69 71
70 settings = new QPopupMenu; 72 settings = new QPopupMenu;
71 settings->insertItem(tr("&Change Card Backs"), this, SLOT(changeCardBacks()), Key_F2); 73 settings->insertItem(tr("&Change Card Backs"), this, SLOT(changeCardBacks()), Key_F2);
@@ -84,12 +86,13 @@ CanvasCardWindow::CanvasCardWindow(QWidget* parent, const char* name, WFlags f)
84 86
85 QPopupMenu* file = new QPopupMenu; 87 QPopupMenu* file = new QPopupMenu;
86 file->insertItem(tr("Patience"), this, SLOT(initPatience())); 88 file->insertItem(tr("Patience"), this, SLOT(initPatience()));
87 file->insertItem(tr("Freecell"), this, SLOT(initFreecell())); 89 file->insertItem(tr("Freecell"), this, SLOT(initFreecell()));
88 file->insertItem(tr("Chicane"), this, SLOT(initChicane())); 90 file->insertItem(tr("Chicane"), this, SLOT(initChicane()));
89 file->insertItem(tr("Harp"), this, SLOT(initHarp())); 91 file->insertItem(tr("Harp"), this, SLOT(initHarp()));
92 file->insertItem(tr("Teeclub"), this, SLOT(initTeeclub()));
90 menu->insertItem(tr("Play"), file); 93 menu->insertItem(tr("Play"), file);
91 94
92 menu->insertSeparator(); 95 menu->insertSeparator();
93 96
94 settings = new QPopupMenu; 97 settings = new QPopupMenu;
95 settings->setCheckable(TRUE); 98 settings->setCheckable(TRUE);
@@ -126,21 +129,26 @@ CanvasCardWindow::CanvasCardWindow(QWidget* parent, const char* name, WFlags f)
126 setCardBacks(); 129 setCardBacks();
127 } else if ( gameType == 2 ) { 130 } else if ( gameType == 2 ) {
128 cardGame = new ChicaneCardGame( &canvas, snapOn, this ); 131 cardGame = new ChicaneCardGame( &canvas, snapOn, this );
129 cardGame->setNumberToDraw(1); 132 cardGame->setNumberToDraw(1);
130 setCaption(tr("Chicane")); 133 setCaption(tr("Chicane"));
131 setCentralWidget(cardGame); 134 setCentralWidget(cardGame);
132 //cardGame->newGame(); // Until we know how to handle reading freecell config
133 cardGame->readConfig( cfg ); 135 cardGame->readConfig( cfg );
134 setCardBacks(); 136 setCardBacks();
135 } else if ( gameType == 3 ) { 137 } else if ( gameType == 3 ) {
136 cardGame = new HarpCardGame( &canvas, snapOn, this ); 138 cardGame = new HarpCardGame( &canvas, snapOn, this );
137 cardGame->setNumberToDraw(1); 139 cardGame->setNumberToDraw(1);
138 setCaption(tr("Harp")); 140 setCaption(tr("Harp"));
139 setCentralWidget(cardGame); 141 setCentralWidget(cardGame);
140 //cardGame->newGame(); // Until we know how to handle reading freecell config 142 cardGame->readConfig( cfg );
143 setCardBacks();
144 } else if ( gameType == 4 ) {
145 cardGame = new TeeclubCardGame( &canvas, snapOn, this );
146 cardGame->setNumberToDraw(1);
147 setCaption(tr("Teeclub"));
148 setCentralWidget(cardGame);
141 cardGame->readConfig( cfg ); 149 cardGame->readConfig( cfg );
142 setCardBacks(); 150 setCardBacks();
143 } else { 151 } else {
144 // Probably there isn't a config file or it is broken 152 // Probably there isn't a config file or it is broken
145 // Start a new game 153 // Start a new game
146 initPatience(); 154 initPatience();
@@ -231,12 +239,28 @@ void CanvasCardWindow::initHarp()
231 setCentralWidget(cardGame); 239 setCentralWidget(cardGame);
232 cardGame->newGame(); 240 cardGame->newGame();
233 setCardBacks(); 241 setCardBacks();
234} 242}
235 243
236 244
245void CanvasCardWindow::initTeeclub()
246{
247 // Create New Game
248 if ( cardGame ) {
249 delete cardGame;
250 }
251 cardGame = new TeeclubCardGame( &canvas, snapOn, this );
252 cardGame->setNumberToDraw(1);
253 gameType = 4;
254 setCaption(tr("Teeclub"));
255 setCentralWidget(cardGame);
256 cardGame->newGame();
257 setCardBacks();
258}
259
260
237void CanvasCardWindow::snapToggle() 261void CanvasCardWindow::snapToggle()
238{ 262{
239 snapOn = !snapOn; 263 snapOn = !snapOn;
240 settings->setItemChecked(snap_id, snapOn); 264 settings->setItemChecked(snap_id, snapOn);
241 cardGame->toggleSnap(); 265 cardGame->toggleSnap();
242} 266}
diff --git a/noncore/games/solitaire/canvascardwindow.h b/noncore/games/solitaire/canvascardwindow.h
index aa76730..eddb184 100644
--- a/noncore/games/solitaire/canvascardwindow.h
+++ b/noncore/games/solitaire/canvascardwindow.h
@@ -44,12 +44,13 @@ public slots:
44 44
45private slots: 45private slots:
46 void initFreecell(); 46 void initFreecell();
47 void initPatience(); 47 void initPatience();
48 void initChicane(); 48 void initChicane();
49 void initHarp(); 49 void initHarp();
50 void initTeeclub();
50 51
51protected: 52protected:
52 virtual void resizeEvent(QResizeEvent *e); 53 virtual void resizeEvent(QResizeEvent *e);
53 54
54 void updateDraw(); 55 void updateDraw();
55private: 56private:
diff --git a/noncore/games/solitaire/cardgamelayout.cpp b/noncore/games/solitaire/cardgamelayout.cpp
index e21d08a..1ceee8d 100644
--- a/noncore/games/solitaire/cardgamelayout.cpp
+++ b/noncore/games/solitaire/cardgamelayout.cpp
@@ -15,13 +15,13 @@
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 "cardgamelayout.h" 20#include "cardgamelayout.h"
21#include "card.h" 21
22 22
23CardGameLayout::~CardGameLayout() 23CardGameLayout::~CardGameLayout()
24{ 24{
25 // Should I just do setAutoDelete( TRUE ); ? 25 // Should I just do setAutoDelete( TRUE ); ?
26 for (CardPile *p = first(); p != NULL; p = next()) 26 for (CardPile *p = first(); p != NULL; p = next())
27 delete p; 27 delete p;
diff --git a/noncore/games/solitaire/cardpile.cpp b/noncore/games/solitaire/cardpile.cpp
index 3b15e93..aace2e2 100644
--- a/noncore/games/solitaire/cardpile.cpp
+++ b/noncore/games/solitaire/cardpile.cpp
@@ -24,20 +24,21 @@
24#include <qpe/config.h> 24#include <qpe/config.h>
25#include <qpoint.h> 25#include <qpoint.h>
26 26
27#include <qlist.h> 27#include <qlist.h>
28 28
29 29
30CardPile::CardPile(int x, int y) : pileX(x), pileY(y), dealing(FALSE) { 30CardPile::CardPile(int x, int y) : pileX(x), pileY(y), dealing(FALSE), PileResize(FALSE) {
31 pileWidth = 0; 31 pileWidth = 0;
32 pileHeight = 0; 32 pileHeight = 0;
33 pileNextX = pileX; 33 pileNextX = pileX;
34 pileNextY = pileY; 34 pileNextY = pileY;
35 pileCenterX = x + pileWidth / 2; 35 pileCenterX = x + pileWidth / 2;
36 pileCenterY = y + pileHeight / 2; 36 pileCenterY = y + pileHeight / 2;
37 pileRadius = (pileWidth > pileHeight) ? pileWidth : pileHeight; 37 pileRadius = (pileWidth > pileHeight) ? pileWidth : pileHeight;
38 pileOffsetDown = 13;
38} 39}
39 40
40 41
41int CardPile::distanceFromPile(int x, int y) { 42int CardPile::distanceFromPile(int x, int y) {
42 return (pileCenterX-x)*(pileCenterX-x)+(pileCenterY-y)*(pileCenterY-y); 43 return (pileCenterX-x)*(pileCenterX-x)+(pileCenterY-y)*(pileCenterY-y);
43} 44}
diff --git a/noncore/games/solitaire/cardpile.h b/noncore/games/solitaire/cardpile.h
index c515bbc..1eb2499 100644
--- a/noncore/games/solitaire/cardpile.h
+++ b/noncore/games/solitaire/cardpile.h
@@ -48,23 +48,35 @@ public:
48 int getX() { return pileX; } 48 int getX() { return pileX; }
49 int getY() { return pileY; } 49 int getY() { return pileY; }
50 int getNextX() { return pileNextX; } 50 int getNextX() { return pileNextX; }
51 int getNextY() { return pileNextY; } 51 int getNextY() { return pileNextY; }
52 int getWidth() { return pileWidth; } 52 int getWidth() { return pileWidth; }
53 int getHeight() { return pileHeight; } 53 int getHeight() { return pileHeight; }
54 int getOffsetDown() { return pileOffsetDown; }
55 int getAnzCardsInPile() {
56 int anz=0;
57 Card *card = cardOnBottom();
58 while (card != NULL) { anz++; card = cardInfront(card); }
59 return anz;
60 }
54 61
55 void setX(int x) { pileX = x; } 62 void setX(int x) { pileX = x; }
56 void setY(int y) { pileY = y; } 63 void setY(int y) { pileY = y; }
57 void setNextX(int x) { pileNextX = x; } 64 void setNextX(int x) { pileNextX = x; }
58 void setNextY(int y) { pileNextY = y; } 65 void setNextY(int y) { pileNextY = y; }
59 void setWidth(int width) { pileWidth = width; } 66 void setWidth(int width) { pileWidth = width; }
60 void setHeight(int height) { pileHeight = height; } 67 void setHeight(int height) { pileHeight = height; }
68 void setOffsetDown(int down) { pileOffsetDown = down; }
61 69
62 void beginDealing() { dealing = TRUE; } 70 void beginDealing() { dealing = TRUE; }
63 void endDealing() { dealing = FALSE; } 71 void endDealing() { dealing = FALSE; }
64 bool isDealing() { return dealing; } 72 bool isDealing() { return dealing; }
73
74 void beginPileResize() { PileResize = TRUE; }
75 void endPileResize() { PileResize = FALSE; }
76 bool isPileResize() { return PileResize; }
65 77
66 int distanceFromPile(int x, int y); 78 int distanceFromPile(int x, int y);
67 int distanceFromNextPos(int x, int y); 79 int distanceFromNextPos(int x, int y);
68 80
69 Card *cardOnTop() { return getLast(); } 81 Card *cardOnTop() { return getLast(); }
70 Card *cardOnBottom() { return getFirst(); } 82 Card *cardOnBottom() { return getFirst(); }
@@ -89,13 +101,15 @@ public:
89protected: 101protected:
90 int pileX, pileY; 102 int pileX, pileY;
91 int pileNextX, pileNextY; 103 int pileNextX, pileNextY;
92 int pileWidth, pileHeight; 104 int pileWidth, pileHeight;
93 int pileCenterX, pileCenterY; 105 int pileCenterX, pileCenterY;
94 int pileRadius; 106 int pileRadius;
107 int pileOffsetDown;
95private: 108private:
96 bool dealing; 109 bool dealing;
110 bool PileResize;
97}; 111};
98 112
99 113
100#endif 114#endif
101 115
diff --git a/noncore/games/solitaire/solitaire.pro b/noncore/games/solitaire/solitaire.pro
index b2ba5aa..d08dab0 100755
--- a/noncore/games/solitaire/solitaire.pro
+++ b/noncore/games/solitaire/solitaire.pro
@@ -1,28 +1,31 @@
1 TEMPLATE= app 1 TEMPLATE= app
2
2 CONFIG += qt warn_on release 3 CONFIG += qt warn_on release
3 DESTDIR = $(OPIEDIR)/bin 4 DESTDIR = $(OPIEDIR)/bin
4 5
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 HEADERS = canvascard.h canvasshapes.h cardgame.h cardgamelayout.h cardpile.h card.h carddeck.h canvascardgame.h freecellcardgame.h chicanecardgame.h harpcardgame.h teeclubcardgame.h patiencecardgame.h canvascardwindow.h
6 7
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 SOURCES = canvascard.cpp canvasshapes.cpp cardgame.cpp cardgamelayout.cpp cardpile.cpp card.cpp carddeck.cpp canvascardgame.cpp freecellcardgame.cpp chicanecardgame.cpp harpcardgame.cpp teeclubcardgame.cpp patiencecardgame.cpp canvascardwindow.cpp main.cpp
8 9
9 TARGET = patience 10 TARGET = patience
11
10INCLUDEPATH += $(OPIEDIR)/include 12INCLUDEPATH += $(OPIEDIR)/include
11 DEPENDPATH+= $(OPIEDIR)/include 13 DEPENDPATH+= $(OPIEDIR)/include
12LIBS += -lqpe 14LIBS += -lqpe
15
13 REQUIRES= patience 16 REQUIRES= patience
14 17
15TRANSLATIONS = ../../../i18n/de/patience.ts \ 18TRANSLATIONS = ../i18n/de/patience.ts
16 ../../../i18n/en/patience.ts \ 19TRANSLATIONS += ../i18n/es/patience.ts
17 ../../../i18n/es/patience.ts \ 20TRANSLATIONS += ../i18n/pt/patience.ts
18 ../../../i18n/fr/patience.ts \ 21TRANSLATIONS += ../i18n/pt_BR/patience.ts
19 ../../../i18n/hu/patience.ts \ 22TRANSLATIONS += ../i18n/en/patience.ts
20 ../../../i18n/ja/patience.ts \ 23TRANSLATIONS += ../i18n/hu/patience.ts
21 ../../../i18n/ko/patience.ts \ 24TRANSLATIONS += ../i18n/ja/patience.ts
22 ../../../i18n/no/patience.ts \ 25TRANSLATIONS += ../i18n/sl/patience.ts
23 ../../../i18n/pl/patience.ts \ 26TRANSLATIONS += ../i18n/ko/patience.ts
24 ../../../i18n/pt/patience.ts \ 27TRANSLATIONS += ../i18n/pl/patience.ts
25 ../../../i18n/pt_BR/patience.ts \ 28TRANSLATIONS += ../i18n/no/patience.ts
26 ../../../i18n/sl/patience.ts \ 29TRANSLATIONS += ../i18n/fr/patience.ts
27 ../../../i18n/zh_CN/patience.ts \ 30TRANSLATIONS += ../i18n/zh_CN/patience.ts
28 ../../../i18n/zh_TW/patience.ts 31TRANSLATIONS += ../i18n/zh_TW/patience.ts
diff --git a/noncore/games/solitaire/teeclubcardgame.cpp b/noncore/games/solitaire/teeclubcardgame.cpp
new file mode 100644
index 0000000..e15da96
--- a/dev/null
+++ b/noncore/games/solitaire/teeclubcardgame.cpp
@@ -0,0 +1,194 @@
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 "teeclubcardgame.h"
25
26
27extern int highestZ;
28
29
30 TeeclubCardGame::TeeclubCardGame(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 TeeclubDiscardPile( 27 + i * 26, 10, canvas() );
36 addCardPile(discardPiles[i]);
37 }
38 for (int i = 0; i < 9; i++) {
39 workingPiles[i] = new TeeclubWorkingPile( 2 + i * 26, 50, canvas() );
40 addCardPile(workingPiles[i]);
41 }
42 faceDownDealingPile = new TeeclubFaceDownDeck( 2, 10, canvas() );
43}
44
45
46void TeeclubCardGame::deal(void)
47{
48 highestZ = 1;
49 int t = 0;
50
51 beginDealing();
52
53 for (int i = 0; i < 9; i++) {
54 workingPiles[i]->setOffsetDown(13);
55 workingPiles[i]->beginPileResize();
56 for (int k = 0; k < 5; k++, t++) {
57 Card *card = cards[t];
58 workingPiles[i]->addCardToTop(card);
59 card->setCardPile( workingPiles[i] );
60 card->setPos( 0, 0, highestZ );
61 card->setFace(TRUE);
62 card->move( workingPiles[i]->getCardPos( card ) );
63 card->showCard();
64 highestZ++;
65 }
66 }
67
68 for ( ; t < getNumberOfCards(); t++) {
69 Card *card = cards[t];
70 faceDownDealingPile->addCardToTop(card);
71 card->setCardPile( faceDownDealingPile );
72 QPoint p = faceDownDealingPile->getCardPos( card );
73 card->setPos( p.x(), p.y(), highestZ );
74 card->showCard();
75 highestZ++;
76 }
77
78 endDealing();
79}
80
81
82void TeeclubCardGame::resizePiles()
83{
84 beginDealing();
85 for (int i = 0; i < 9; i++) {
86 while ((workingPiles[i]->getCardPos(NULL).y() > 230) && (workingPiles[i]->getOffsetDown()>1)) {
87 // Resizen des Stapels
88 workingPiles[i]->setOffsetDown(workingPiles[i]->getOffsetDown()-1);
89 Card *card = workingPiles[i]->cardOnBottom();
90 int p=0;
91 while (card != NULL) {
92 card->setPos( 0, 0, p++ );
93 card->move( workingPiles[i]->getCardPos( card ) );
94 card = workingPiles[i]->cardInfront(card);
95 }
96 }
97 }
98 endDealing();
99}
100
101
102void TeeclubCardGame::readConfig( Config& cfg )
103{
104 cfg.setGroup("GameState");
105
106 // Create Cards, but don't shuffle or deal them yet
107 createDeck();
108
109 // Move the cards to their piles (deal them to their previous places)
110 beginDealing();
111
112 highestZ = 1;
113
114 for (int i = 0; i < 8; i++) {
115 QString pile;
116 pile.sprintf( "TeeclubDiscardPile%i", i );
117 readPile( cfg, discardPiles[i], pile, highestZ );
118 }
119
120 for (int i = 0; i < 9; i++) {
121 workingPiles[i]->endPileResize();
122 QString pile;
123 pile.sprintf( "TeeclubWorkingPile%i", i );
124 readPile( cfg, workingPiles[i], pile, highestZ );
125 workingPiles[i]->beginPileResize();
126 }
127
128 readPile( cfg, faceDownDealingPile, "TeeclubFaceDownDealingPile", highestZ );
129
130 highestZ++;
131
132 endDealing();
133 resizePiles();
134}
135
136
137void TeeclubCardGame::writeConfig( Config& cfg )
138{
139 cfg.setGroup("GameState");
140 for ( int i = 0; i < 8; i++ ) {
141 QString pile;
142 pile.sprintf( "TeeclubDiscardPile%i", i );
143 discardPiles[i]->writeConfig( cfg, pile );
144 }
145 for ( int i = 0; i < 9; i++ ) {
146 QString pile;
147 pile.sprintf( "TeeclubWorkingPile%i", i );
148 workingPiles[i]->writeConfig( cfg, pile );
149 }
150 faceDownDealingPile->writeConfig( cfg, "TeeclubFaceDownDealingPile" );
151}
152
153
154bool TeeclubCardGame::mousePressCard( Card *card, QPoint p )
155{
156 Q_UNUSED(p);
157
158 CanvasCard *item = (CanvasCard *)card;
159 if (item->isFacing() != TRUE) {
160 // From facedown stack
161 if ((item->x() == 2) && ((int)item->y() == 10)) { // Deal 1 card
162 // Move 8 cards, one to each workingPile
163 beginDealing();
164 CanvasCard *card = (CanvasCard *)faceDownDealingPile->cardOnTop();
165 card->setZ(highestZ);
166 highestZ++;
167 faceDownDealingPile->removeCard(card);
168 workingPiles[0]->addCardToTop(card);
169 card->setCardPile( workingPiles[0] );
170 card->setFace(FALSE);
171 QPoint p = workingPiles[0]->getCardPos(card);
172 card->flipTo( p.x(), p.y() );
173 endDealing();
174 }
175 moving = NULL;
176 moved = FALSE;
177
178 return TRUE;
179 } else if ( !card->getCardPile()->isAllowedToBeMoved(card) ) {// Don't allow unclean columns to be moved
180 moving = NULL;
181 return TRUE;
182 }
183
184 return FALSE;
185}
186
187
188
189void TeeclubCardGame::mousePress(QPoint p)
190{
191 Q_UNUSED(p);
192}
193
194
diff --git a/noncore/games/solitaire/teeclubcardgame.h b/noncore/games/solitaire/teeclubcardgame.h
new file mode 100644
index 0000000..06d49f8
--- a/dev/null
+++ b/noncore/games/solitaire/teeclubcardgame.h
@@ -0,0 +1,217 @@
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 TEECLUB_CARD_GAME_H
21#define TEECLUB_CARD_GAME_H
22
23
24#include "patiencecardgame.h"
25
26
27class TeeclubFaceDownDeck : public PatienceFaceDownDeck
28{
29public:
30 TeeclubFaceDownDeck(int x, int y, QCanvas *canvas) :
31 PatienceFaceDownDeck(x, y, canvas) { }
32
33};
34
35
36class TeeclubDiscardPile : public CardPile, public CanvasRoundRect
37{
38public:
39 TeeclubDiscardPile(int x, int y, QCanvas *canvas)
40 : CardPile(x, y), CanvasRoundRect(x, y, canvas) { }
41 virtual bool isAllowedOnTop(Card *card) {
42 if ( card->isFacing() && ( card->getCardPile()->cardInfront(card) == NULL ) &&
43 ( ( ( cardOnTop() == NULL ) && ( card->getValue() == ace ) ) ||
44 ( ( cardOnTop() != NULL ) &&
45 ( (int)card->getValue() == (int)cardOnTop()->getValue() + 1 ) &&
46 ( card->getSuit() == cardOnTop()->getSuit() ) ) ) )
47 return TRUE;
48 return FALSE;
49 }
50 virtual bool isAllowedToBeMoved(Card *card) {
51 if (card->isFacing()) return FALSE;
52 return FALSE; // die Toten ruhn
53 }
54};
55
56
57class TeeclubWorkingPile : public PatienceWorkingPile
58{
59public:
60 TeeclubWorkingPile(int x, int y, QCanvas *canvas) :
61 PatienceWorkingPile(x, y, canvas) { }
62
63 virtual bool isAllowedOnTop(Card *card) {
64 if ( card->isFacing() &&
65 // ( ( ( cardOnTop() == NULL ) && (card->getValue() == king) ) || // diese Zeile sorgt dafür dass nur Kings auf leere Plätze dürfen
66 ( (cardOnTop() == NULL) || // auf einen Freiplatz darf alles!
67 ( (cardOnTop() != NULL) &&
68 ((int)card->getValue() + 1 == (int)cardOnTop()->getValue()) // bei teeclub sind die farben zum Anlegen egal
69 ) ) )
70 return TRUE;
71 return FALSE;
72 }
73
74 virtual bool isAllowedToBeMoved(Card *card) {
75 if (!card->isFacing()) return FALSE;
76
77 int nextExpectedValue = (int)card->getValue();
78 eSuit nextExpectedSuit = card->getSuit();
79
80 while ((card != NULL)) {
81 if ( (int)card->getValue() != nextExpectedValue )
82 return FALSE;
83 if ( card->getSuit() != nextExpectedSuit )
84 return FALSE;
85 nextExpectedValue--;;
86 card = cardInfront(card);
87 }
88 return TRUE;
89 }
90
91 virtual void cardRemoved(Card *card) {
92 Q_UNUSED(card);
93
94 Card *newTopCard = cardOnTop();
95
96 if ( !newTopCard ) {
97 top = QPoint( pileX, pileY );
98 setNextX( pileX );
99 setNextY( pileY );
100 setOffsetDown(13);
101 return;
102 } else {
103 top = getCardPos(NULL);
104 if ( newTopCard->isFacing() == FALSE ) {
105 int offsetDown = newTopCard->getCardPile()->getOffsetDown();
106 // correct the position taking in to account the card is not
107 // yet flipped, but will become flipped
108 top = QPoint( top.x(), top.y() - 3 ); // Keine seitliche Verschiebung!
109 newTopCard->flipTo( top.x(), top.y() );
110 top = QPoint( top.x(), top.y() + offsetDown );
111 }
112 setNextX( top.x() );
113 setNextY( top.y() );
114 }
115
116 if ((getCardPos(NULL).y() < 230) && (getOffsetDown()<13)) {
117 // Resizen des Stapels
118 beginDealing();
119 setOffsetDown(getOffsetDown()+1);
120 Card *card = cardOnBottom();
121 int p=0;
122 while (card != NULL) {
123 card->setPos( 0, 0, p++ );
124 card->move( getCardPos( card ) );
125 card = cardInfront(card);
126 }
127 endDealing();
128 }
129 }
130
131 virtual QPoint getCardPos(Card *c) {
132 int x = pileX, y = pileY;
133 Card *card = cardOnBottom();
134 while ((card != c) && (card != NULL)) {
135 if (card->isFacing()) {
136 int offsetDown = card->getCardPile()->getOffsetDown();
137 y += offsetDown;
138 } else {
139 x += 0; // Keine seitliche Verschiebung!
140 y += 3;
141 }
142 card = cardInfront(card);
143 }
144 return QPoint( x, y );
145 }
146
147 virtual QPoint getHypertheticalNextCardPos(void) {
148 return QPoint( getNextX(), getNextY() );
149 }
150
151 virtual void cardAddedToTop(Card *c) {
152 Q_UNUSED(c);
153 setNextX( getCardPos(NULL).x() );
154 setNextY( getCardPos(NULL).y() );
155
156 while (isPileResize() && (getCardPos(NULL).y() > 230) && (getOffsetDown()>1)) {
157 // Resizen des Stapels
158 beginDealing();
159 setOffsetDown(getOffsetDown()-1);
160 Card *card = cardOnBottom();
161 int p=0;
162 while (card != NULL) {
163 card->setPos( 0, 0, p++ );
164 card->move( getCardPos( card ) );
165 card = cardInfront(card);
166 }
167 endDealing();
168 }
169
170 }
171
172
173
174
175private:
176 QPoint top;
177
178};
179
180
181class TeeclubCardGame : public CanvasCardGame
182{
183public:
184 TeeclubCardGame(QCanvas *c, bool snap, QWidget *parent = 0);
185// virtual ~TeeclubCardGame();
186 virtual void deal(void);
187 virtual bool haveWeWon() {
188 return ( discardPiles[0]->kingOnTop() &&
189 discardPiles[1]->kingOnTop() &&
190 discardPiles[2]->kingOnTop() &&
191 discardPiles[3]->kingOnTop() &&
192 discardPiles[4]->kingOnTop() &&
193 discardPiles[5]->kingOnTop() &&
194 discardPiles[6]->kingOnTop() &&
195 discardPiles[7]->kingOnTop() );;
196 }
197 virtual void mousePress(QPoint p);
198 virtual void mouseRelease(QPoint p) { Q_UNUSED(p); }
199// virtual void mouseMove(QPoint p);
200 virtual bool mousePressCard(Card *card, QPoint p);
201 virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); }
202// virtual void mouseMoveCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); }
203 bool canTurnOverDeck(void) { return (FALSE); }
204 void throughDeck(void) { }
205 bool snapOn;
206 void writeConfig( Config& cfg );
207 void readConfig( Config& cfg );
208 void resizePiles();
209private:
210 TeeclubWorkingPile *workingPiles[9];
211 TeeclubDiscardPile *discardPiles[8];
212 TeeclubFaceDownDeck *faceDownDealingPile;
213};
214
215
216#endif
217