Diffstat (limited to 'noncore/games/solitaire/teeclubcardgame.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/solitaire/teeclubcardgame.cpp | 194 |
1 files changed, 194 insertions, 0 deletions
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 | |||
27 | extern 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 | |||
46 | void 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 | |||
82 | void 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 | |||
102 | void 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 | |||
137 | void 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 | |||
154 | bool 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 | |||
189 | void TeeclubCardGame::mousePress(QPoint p) | ||
190 | { | ||
191 | Q_UNUSED(p); | ||
192 | } | ||
193 | |||
194 | |||