author | tille <tille> | 2002-06-26 10:41:53 (UTC) |
---|---|---|
committer | tille <tille> | 2002-06-26 10:41:53 (UTC) |
commit | b72d90431bf1bf3235213612daad275836bcbb9f (patch) (unidiff) | |
tree | a6904f310e09d2d96f2dae6d84b6e76339aaf599 | |
parent | 28d91fba01e6eb728de997757a33f4328ee19e2f (diff) | |
download | opie-b72d90431bf1bf3235213612daad275836bcbb9f.zip opie-b72d90431bf1bf3235213612daad275836bcbb9f.tar.gz opie-b72d90431bf1bf3235213612daad275836bcbb9f.tar.bz2 |
bugreport #75 and fix from cmader
-rw-r--r-- | noncore/games/solitaire/patiencecardgame.cpp | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/noncore/games/solitaire/patiencecardgame.cpp b/noncore/games/solitaire/patiencecardgame.cpp index 1501d2f..fc91b26 100644 --- a/noncore/games/solitaire/patiencecardgame.cpp +++ b/noncore/games/solitaire/patiencecardgame.cpp | |||
@@ -1,257 +1,260 @@ | |||
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 "patiencecardgame.h" | 21 | #include "patiencecardgame.h" |
22 | 22 | ||
23 | 23 | ||
24 | int highestZ = 0; | 24 | int highestZ = 0; |
25 | 25 | ||
26 | 26 | ||
27 | PatienceCardGame::PatienceCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent) | 27 | PatienceCardGame::PatienceCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent) |
28 | { | 28 | { |
29 | numberOfTimesThroughDeck = 0; | 29 | numberOfTimesThroughDeck = 0; |
30 | highestZ = 0; | 30 | highestZ = 0; |
31 | 31 | ||
32 | if ( qt_screen->deviceWidth() < 200 ) { | 32 | if ( qt_screen->deviceWidth() < 200 ) { |
33 | circleCross = new CanvasCircleOrCross( 7, 16, canvas() ); | 33 | circleCross = new CanvasCircleOrCross( 7, 16, canvas() ); |
34 | rectangle = new CanvasRoundRect( 30, 10, canvas() ); | 34 | rectangle = new CanvasRoundRect( 30, 10, canvas() ); |
35 | 35 | ||
36 | for (int i = 0; i < 4; i++) { | 36 | for (int i = 0; i < 4; i++) { |
37 | discardPiles[i] = new PatienceDiscardPile( 78 + i * 23, 10, canvas() ); | 37 | discardPiles[i] = new PatienceDiscardPile( 78 + i * 23, 10, canvas() ); |
38 | addCardPile(discardPiles[i]); | 38 | addCardPile(discardPiles[i]); |
39 | } | 39 | } |
40 | for (int i = 0; i < 7; i++) { | 40 | for (int i = 0; i < 7; i++) { |
41 | workingPiles[i] = new PatienceWorkingPile( 5 + i * 23, 50, canvas() ); | 41 | workingPiles[i] = new PatienceWorkingPile( 5 + i * 23, 50, canvas() ); |
42 | addCardPile(workingPiles[i]); | 42 | addCardPile(workingPiles[i]); |
43 | } | 43 | } |
44 | faceDownDealingPile = new PatienceFaceDownDeck( 5, 10, canvas() ); | 44 | faceDownDealingPile = new PatienceFaceDownDeck( 5, 10, canvas() ); |
45 | faceUpDealingPile = new PatienceFaceUpDeck( 30, 10, canvas() ); | 45 | faceUpDealingPile = new PatienceFaceUpDeck( 30, 10, canvas() ); |
46 | } else { | 46 | } else { |
47 | circleCross = new CanvasCircleOrCross( 7, 18, canvas() ); | 47 | circleCross = new CanvasCircleOrCross( 7, 18, canvas() ); |
48 | rectangle = new CanvasRoundRect( 35, 10, canvas() ); | 48 | rectangle = new CanvasRoundRect( 35, 10, canvas() ); |
49 | 49 | ||
50 | for (int i = 0; i < 4; i++) { | 50 | for (int i = 0; i < 4; i++) { |
51 | discardPiles[i] = new PatienceDiscardPile( 110 + i * 30, 10, canvas() ); | 51 | discardPiles[i] = new PatienceDiscardPile( 110 + i * 30, 10, canvas() ); |
52 | addCardPile(discardPiles[i]); | 52 | addCardPile(discardPiles[i]); |
53 | } | 53 | } |
54 | for (int i = 0; i < 7; i++) { | 54 | for (int i = 0; i < 7; i++) { |
55 | workingPiles[i] = new PatienceWorkingPile( 10 + i * 30, 50, canvas() ); | 55 | workingPiles[i] = new PatienceWorkingPile( 10 + i * 30, 50, canvas() ); |
56 | addCardPile(workingPiles[i]); | 56 | addCardPile(workingPiles[i]); |
57 | } | 57 | } |
58 | faceDownDealingPile = new PatienceFaceDownDeck( 5, 10, canvas() ); | 58 | faceDownDealingPile = new PatienceFaceDownDeck( 5, 10, canvas() ); |
59 | faceUpDealingPile = new PatienceFaceUpDeck( 35, 10, canvas() ); | 59 | faceUpDealingPile = new PatienceFaceUpDeck( 35, 10, canvas() ); |
60 | } | 60 | } |
61 | } | 61 | } |
62 | 62 | ||
63 | 63 | ||
64 | PatienceCardGame::~PatienceCardGame() | 64 | PatienceCardGame::~PatienceCardGame() |
65 | { | 65 | { |
66 | delete circleCross; | 66 | delete circleCross; |
67 | delete rectangle; | 67 | delete rectangle; |
68 | delete faceDownDealingPile; | 68 | delete faceDownDealingPile; |
69 | delete faceUpDealingPile; | 69 | delete faceUpDealingPile; |
70 | } | 70 | } |
71 | 71 | ||
72 | 72 | ||
73 | void PatienceCardGame::deal(void) | 73 | void PatienceCardGame::deal(void) |
74 | { | 74 | { |
75 | highestZ = 1; | 75 | highestZ = 1; |
76 | int t = 0; | 76 | int t = 0; |
77 | 77 | ||
78 | beginDealing(); | 78 | beginDealing(); |
79 | 79 | ||
80 | for (int i = 0; i < 7; i++) { | 80 | for (int i = 0; i < 7; i++) { |
81 | cards[t]->setFace(TRUE); | 81 | cards[t]->setFace(TRUE); |
82 | for (int k = i; k < 7; k++, t++) { | 82 | for (int k = i; k < 7; k++, t++) { |
83 | Card *card = cards[t]; | 83 | Card *card = cards[t]; |
84 | workingPiles[k]->addCardToTop(card); | 84 | workingPiles[k]->addCardToTop(card); |
85 | card->setCardPile( workingPiles[k] ); | 85 | card->setCardPile( workingPiles[k] ); |
86 | QPoint p = workingPiles[k]->getCardPos( card ); | 86 | QPoint p = workingPiles[k]->getCardPos( card ); |
87 | card->setPos( p.x(), p.y(), highestZ ); | 87 | card->setPos( p.x(), p.y(), highestZ ); |
88 | card->showCard(); | 88 | card->showCard(); |
89 | highestZ++; | 89 | highestZ++; |
90 | } | 90 | } |
91 | } | 91 | } |
92 | 92 | ||
93 | for ( ; t < 52; t++) { | 93 | for ( ; t < 52; t++) { |
94 | Card *card = cards[t]; | 94 | Card *card = cards[t]; |
95 | faceDownDealingPile->addCardToTop(card); | 95 | faceDownDealingPile->addCardToTop(card); |
96 | card->setCardPile( faceDownDealingPile ); | 96 | card->setCardPile( faceDownDealingPile ); |
97 | QPoint p = faceDownDealingPile->getCardPos( card ); | 97 | QPoint p = faceDownDealingPile->getCardPos( card ); |
98 | card->setPos( p.x(), p.y(), highestZ ); | 98 | card->setPos( p.x(), p.y(), highestZ ); |
99 | card->showCard(); | 99 | card->showCard(); |
100 | highestZ++; | 100 | highestZ++; |
101 | } | 101 | } |
102 | 102 | ||
103 | endDealing(); | 103 | endDealing(); |
104 | } | 104 | } |
105 | 105 | ||
106 | 106 | ||
107 | void PatienceCardGame::readConfig( Config& cfg ) | 107 | void PatienceCardGame::readConfig( Config& cfg ) |
108 | { | 108 | { |
109 | cfg.setGroup("GameState"); | 109 | cfg.setGroup("GameState"); |
110 | 110 | ||
111 | // Do we have a config file to read in? | 111 | // Do we have a config file to read in? |
112 | if ( !cfg.hasKey("numberOfTimesThroughDeck") ) { | 112 | if ( !cfg.hasKey("numberOfTimesThroughDeck") ) { |
113 | // if not, create a new game | 113 | // if not, create a new game |
114 | newGame(); | 114 | newGame(); |
115 | return; | 115 | return; |
116 | } | 116 | } |
117 | // We have a config file, lets read it in and use it | 117 | // We have a config file, lets read it in and use it |
118 | 118 | ||
119 | // Create Cards, but don't shuffle or deal them yet | 119 | // Create Cards, but don't shuffle or deal them yet |
120 | createDeck(); | 120 | createDeck(); |
121 | 121 | ||
122 | // How many times through the deck have we been | 122 | // How many times through the deck have we been |
123 | numberOfTimesThroughDeck = cfg.readNumEntry("NumberOfTimesThroughDeck"); | 123 | numberOfTimesThroughDeck = cfg.readNumEntry("NumberOfTimesThroughDeck"); |
124 | 124 | ||
125 | // restore state to the circle/cross under the dealing pile | 125 | // restore state to the circle/cross under the dealing pile |
126 | if ( canTurnOverDeck() ) | 126 | if ( canTurnOverDeck() ) |
127 | circleCross->setCircle(); | 127 | circleCross->setCircle(); |
128 | else | 128 | else |
129 | circleCross->setCross(); | 129 | circleCross->setCross(); |
130 | 130 | ||
131 | // Move the cards to their piles (deal them to their previous places) | 131 | // Move the cards to their piles (deal them to their previous places) |
132 | beginDealing(); | 132 | beginDealing(); |
133 | 133 | ||
134 | highestZ = 1; | 134 | highestZ = 1; |
135 | 135 | ||
136 | for (int k = 0; k < 7; k++) { | 136 | for (int k = 0; k < 7; k++) { |
137 | QString pile; | 137 | QString pile; |
138 | pile.sprintf( "WorkingPile%i", k ); | 138 | pile.sprintf( "WorkingPile%i", k ); |
139 | readPile( cfg, workingPiles[k], pile, highestZ ); | 139 | readPile( cfg, workingPiles[k], pile, highestZ ); |
140 | } | 140 | } |
141 | 141 | ||
142 | for (int k = 0; k < 4; k++) { | 142 | for (int k = 0; k < 4; k++) { |
143 | QString pile; | 143 | QString pile; |
144 | pile.sprintf( "DiscardPile%i", k ); | 144 | pile.sprintf( "DiscardPile%i", k ); |
145 | readPile( cfg, discardPiles[k], pile, highestZ ); | 145 | readPile( cfg, discardPiles[k], pile, highestZ ); |
146 | } | 146 | } |
147 | 147 | ||
148 | readPile( cfg, faceDownDealingPile, "FaceDownDealingPile", highestZ ); | 148 | readPile( cfg, faceDownDealingPile, "FaceDownDealingPile", highestZ ); |
149 | readPile( cfg, faceUpDealingPile, "FaceUpDealingPile", highestZ ); | 149 | readPile( cfg, faceUpDealingPile, "FaceUpDealingPile", highestZ ); |
150 | 150 | ||
151 | highestZ++; | 151 | highestZ++; |
152 | 152 | ||
153 | endDealing(); | 153 | endDealing(); |
154 | } | 154 | } |
155 | 155 | ||
156 | 156 | ||
157 | void PatienceCardGame::writeConfig( Config& cfg ) | 157 | void PatienceCardGame::writeConfig( Config& cfg ) |
158 | { | 158 | { |
159 | cfg.setGroup("GameState"); | 159 | cfg.setGroup("GameState"); |
160 | cfg.writeEntry("numberOfTimesThroughDeck", numberOfTimesThroughDeck); | 160 | cfg.writeEntry("numberOfTimesThroughDeck", numberOfTimesThroughDeck); |
161 | 161 | ||
162 | for ( int i = 0; i < 7; i++ ) { | 162 | for ( int i = 0; i < 7; i++ ) { |
163 | QString pile; | 163 | QString pile; |
164 | pile.sprintf( "WorkingPile%i", i ); | 164 | pile.sprintf( "WorkingPile%i", i ); |
165 | workingPiles[i]->writeConfig( cfg, pile ); | 165 | workingPiles[i]->writeConfig( cfg, pile ); |
166 | } | 166 | } |
167 | for ( int i = 0; i < 4; i++ ) { | 167 | for ( int i = 0; i < 4; i++ ) { |
168 | QString pile; | 168 | QString pile; |
169 | pile.sprintf( "DiscardPile%i", i ); | 169 | pile.sprintf( "DiscardPile%i", i ); |
170 | discardPiles[i]->writeConfig( cfg, pile ); | 170 | discardPiles[i]->writeConfig( cfg, pile ); |
171 | } | 171 | } |
172 | faceDownDealingPile->writeConfig( cfg, "FaceDownDealingPile" ); | 172 | faceDownDealingPile->writeConfig( cfg, "FaceDownDealingPile" ); |
173 | faceUpDealingPile->writeConfig( cfg, "FaceUpDealingPile" ); | 173 | faceUpDealingPile->writeConfig( cfg, "FaceUpDealingPile" ); |
174 | } | 174 | } |
175 | 175 | ||
176 | 176 | ||
177 | bool PatienceCardGame::mousePressCard( Card *card, QPoint p ) | 177 | bool PatienceCardGame::mousePressCard( Card *card, QPoint p ) |
178 | { | 178 | { |
179 | Q_UNUSED(p); | 179 | Q_UNUSED(p); |
180 | 180 | ||
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 { | ||
198 | // fix from cmader by tille | ||
199 | return false; | ||
197 | } | 200 | } |
198 | moving = NULL; | 201 | moving = NULL; |
199 | moved = FALSE; | 202 | moved = FALSE; |
200 | 203 | ||
201 | // move two other cards if we flip three at a time | 204 | // move two other cards if we flip three at a time |
202 | int flipped = 1; | 205 | int flipped = 1; |
203 | QCanvasItemList l = canvas()->collisions( p ); | 206 | QCanvasItemList l = canvas()->collisions( p ); |
204 | for (QCanvasItemList::Iterator it = l.begin(); (it != l.end()) && (flipped != cardsDrawn()); ++it) { | 207 | for (QCanvasItemList::Iterator it = l.begin(); (it != l.end()) && (flipped != cardsDrawn()); ++it) { |
205 | if ( (*it)->rtti() == canvasCardId ) { | 208 | if ( (*it)->rtti() == canvasCardId ) { |
206 | CanvasCard *item = (CanvasCard *)*it; | 209 | CanvasCard *item = (CanvasCard *)*it; |
207 | if (item->animated()) | 210 | if (item->animated()) |
208 | continue; | 211 | continue; |
209 | item->setZ(highestZ); | 212 | item->setZ(highestZ); |
210 | highestZ++; | 213 | highestZ++; |
211 | flipped++; | 214 | flipped++; |
212 | 215 | ||
213 | // Added Code | 216 | // Added Code |
214 | faceDownDealingPile->removeCard(item); | 217 | faceDownDealingPile->removeCard(item); |
215 | faceUpDealingPile->addCardToTop(item); | 218 | faceUpDealingPile->addCardToTop(item); |
216 | item->setCardPile( faceUpDealingPile ); | 219 | item->setCardPile( faceUpDealingPile ); |
217 | 220 | ||
218 | if ( qt_screen->deviceWidth() < 200 ) | 221 | if ( qt_screen->deviceWidth() < 200 ) |
219 | item->flipTo( 30, (int)item->y(), 8 * flipped ); | 222 | item->flipTo( 30, (int)item->y(), 8 * flipped ); |
220 | else | 223 | else |
221 | item->flipTo( 35, (int)item->y(), 8 * flipped ); | 224 | item->flipTo( 35, (int)item->y(), 8 * flipped ); |
222 | } | 225 | } |
223 | } | 226 | } |
224 | 227 | ||
225 | return TRUE; | 228 | return TRUE; |
226 | } | 229 | } |
227 | 230 | ||
228 | return FALSE; | 231 | return FALSE; |
229 | } | 232 | } |
230 | 233 | ||
231 | 234 | ||
232 | void PatienceCardGame::mousePress(QPoint p) | 235 | void PatienceCardGame::mousePress(QPoint p) |
233 | { | 236 | { |
234 | if ( canTurnOverDeck() && | 237 | if ( canTurnOverDeck() && |
235 | (p.x() > 5) && (p.x() < 28) && | 238 | (p.x() > 5) && (p.x() < 28) && |
236 | (p.y() > 10) && (p.y() < 46) ) { | 239 | (p.y() > 10) && (p.y() < 46) ) { |
237 | 240 | ||
238 | beginDealing(); | 241 | beginDealing(); |
239 | Card *card = faceUpDealingPile->cardOnTop(); | 242 | Card *card = faceUpDealingPile->cardOnTop(); |
240 | while ( card ) { | 243 | while ( card ) { |
241 | card->setPos( 5, 10, highestZ ); | 244 | card->setPos( 5, 10, highestZ ); |
242 | card->setFace( FALSE ); | 245 | card->setFace( FALSE ); |
243 | faceUpDealingPile->removeCard( card ); | 246 | faceUpDealingPile->removeCard( card ); |
244 | faceDownDealingPile->addCardToTop( card ); | 247 | faceDownDealingPile->addCardToTop( card ); |
245 | card->setCardPile( faceDownDealingPile ); | 248 | card->setCardPile( faceDownDealingPile ); |
246 | card = faceUpDealingPile->cardOnTop(); | 249 | card = faceUpDealingPile->cardOnTop(); |
247 | highestZ++; | 250 | highestZ++; |
248 | } | 251 | } |
249 | endDealing(); | 252 | endDealing(); |
250 | 253 | ||
251 | throughDeck(); | 254 | throughDeck(); |
252 | 255 | ||
253 | moved = TRUE; | 256 | moved = TRUE; |
254 | } | 257 | } |
255 | } | 258 | } |
256 | 259 | ||
257 | 260 | ||