-rw-r--r-- | noncore/games/solitaire/canvascardgame.cpp | 4 | ||||
-rw-r--r-- | noncore/games/solitaire/chicanecardgame.cpp | 8 | ||||
-rw-r--r-- | noncore/games/solitaire/chicanecardgame.h | 17 | ||||
-rw-r--r-- | noncore/games/solitaire/harpcardgame.cpp | 10 | ||||
-rw-r--r-- | noncore/games/solitaire/harpcardgame.h | 18 | ||||
-rw-r--r-- | noncore/games/solitaire/teeclubcardgame.cpp | 12 | ||||
-rw-r--r-- | noncore/games/solitaire/teeclubcardgame.h | 27 |
7 files changed, 74 insertions, 22 deletions
diff --git a/noncore/games/solitaire/canvascardgame.cpp b/noncore/games/solitaire/canvascardgame.cpp index 4404b04..8e07cc8 100644 --- a/noncore/games/solitaire/canvascardgame.cpp +++ b/noncore/games/solitaire/canvascardgame.cpp | |||
@@ -1,387 +1,387 @@ | |||
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 | 20 | ||
21 | #include "cardgame.h" | 21 | #include "cardgame.h" |
22 | #include "canvasshapes.h" | 22 | #include "canvasshapes.h" |
23 | #include "canvascard.h" | 23 | #include "canvascard.h" |
24 | #include "canvascardgame.h" | 24 | #include "canvascardgame.h" |
25 | 25 | ||
26 | #include <qpe/resource.h> | 26 | #include <qpe/resource.h> |
27 | #include <qpe/config.h> | 27 | #include <qpe/config.h> |
28 | 28 | ||
29 | #include <qmainwindow.h> | 29 | #include <qmainwindow.h> |
30 | #include <qpe/qpemenubar.h> | 30 | #include <qpe/qpemenubar.h> |
31 | #include <qpainter.h> | 31 | #include <qpainter.h> |
32 | #include <qgfx_qws.h> | 32 | #include <qgfx_qws.h> |
33 | 33 | ||
34 | #include <stdlib.h> | 34 | #include <stdlib.h> |
35 | #include <limits.h> | 35 | #include <limits.h> |
36 | #include <time.h> | 36 | #include <time.h> |
37 | #include <math.h> | 37 | #include <math.h> |
38 | 38 | ||
39 | 39 | ||
40 | extern int highestZ; | 40 | extern int highestZ; |
41 | 41 | ||
42 | 42 | ||
43 | class CanvasCardPile : public QCanvasRectangle | 43 | class CanvasCardPile : public QCanvasRectangle |
44 | { | 44 | { |
45 | public: | 45 | public: |
46 | CanvasCardPile( CanvasCardGame *ccg, QCanvas *canvas ) : QCanvasRectangle( canvas ), parent( ccg ) { | 46 | CanvasCardPile( CanvasCardGame *ccg, QCanvas *canvas ) : QCanvasRectangle( canvas ), parent( ccg ) { |
47 | pile = new QPixmap( 0, 0 ); | 47 | pile = new QPixmap( 0, 0 ); |
48 | pileHeight = 0; | 48 | pileHeight = 0; |
49 | firstCard = NULL; | 49 | firstCard = NULL; |
50 | } | 50 | } |
51 | 51 | ||
52 | void addCard( CanvasCard *card ); | 52 | void addCard( CanvasCard *card ); |
53 | void advance(int stage); | 53 | void advance(int stage); |
54 | void animatedMove() { animatedMove(savedX, savedY); } | 54 | void animatedMove() { animatedMove(savedX, savedY); } |
55 | void savePos(void) { savedX = (int)x(); savedY = (int)y(); } | 55 | void savePos(void) { savedX = (int)x(); savedY = (int)y(); } |
56 | void animatedMove(int x2, int y2, int steps = 7 ); | 56 | void animatedMove(int x2, int y2, int steps = 7 ); |
57 | 57 | ||
58 | protected: | 58 | protected: |
59 | virtual void draw( QPainter& p ); | 59 | virtual void draw( QPainter& p ); |
60 | 60 | ||
61 | private: | 61 | private: |
62 | CanvasCardGame *parent; | 62 | CanvasCardGame *parent; |
63 | QPixmap *pile; | 63 | QPixmap *pile; |
64 | QImage tempImage32; | 64 | QImage tempImage32; |
65 | CanvasCard *firstCard; | 65 | CanvasCard *firstCard; |
66 | int pileHeight; | 66 | int pileHeight; |
67 | int destX, destY; | 67 | int destX, destY; |
68 | int savedX, savedY; | 68 | int savedX, savedY; |
69 | int animSteps; | 69 | int animSteps; |
70 | }; | 70 | }; |
71 | 71 | ||
72 | 72 | ||
73 | void CanvasCardPile::addCard( CanvasCard *card ) | 73 | void CanvasCardPile::addCard( CanvasCard *card ) |
74 | { | 74 | { |
75 | int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13; | 75 | int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13; |
76 | int cardHeight = ( qt_screen->deviceWidth() < 200 ) ? 27 : 36; | 76 | int cardHeight = ( qt_screen->deviceWidth() < 200 ) ? 27 : 36; |
77 | int cardWidth = ( qt_screen->deviceWidth() < 200 ) ? 20 : 23; | 77 | int cardWidth = ( qt_screen->deviceWidth() < 200 ) ? 20 : 23; |
78 | 78 | ||
79 | if ( !firstCard ) | 79 | if ( !firstCard ) |
80 | firstCard = card; | 80 | firstCard = card; |
81 | 81 | ||
82 | int height = cardHeight + pileHeight * offsetDown; | 82 | int height = cardHeight + pileHeight * offsetDown; |
83 | setSize( cardWidth, height ); | 83 | setSize( cardWidth, height ); |
84 | pile->resize( cardWidth, height ); | 84 | pile->resize( cardWidth, height ); |
85 | QPainter p( pile ); | 85 | QPainter p( pile ); |
86 | p.translate( -card->x(), -card->y() + pileHeight * offsetDown ); | 86 | p.translate( -card->x(), -card->y() + pileHeight * offsetDown ); |
87 | card->draw( p ); | 87 | card->draw( p ); |
88 | pileHeight++; | 88 | pileHeight++; |
89 | 89 | ||
90 | QImage tempImage; | 90 | QImage tempImage; |
91 | tempImage = *pile; | 91 | tempImage = *pile; |
92 | tempImage32 = tempImage.convertDepth( 32 ); | 92 | tempImage32 = tempImage.convertDepth( 32 ); |
93 | tempImage32.setAlphaBuffer( TRUE ); | 93 | tempImage32.setAlphaBuffer( TRUE ); |
94 | for ( int i = 0; i < tempImage32.width(); i++ ) | 94 | for ( int i = 0; i < tempImage32.width(); i++ ) |
95 | for ( int j = 0; j < tempImage32.height(); j++ ) { | 95 | for ( int j = 0; j < tempImage32.height(); j++ ) { |
96 | QRgb col = tempImage32.pixel( i, j ); | 96 | QRgb col = tempImage32.pixel( i, j ); |
97 | int a = 255-j*220/tempImage32.height(); | 97 | int a = 255-j*220/tempImage32.height(); |
98 | QRgb alpha = qRgba( qRed( col ), qGreen( col ), qBlue( col ), a ); | 98 | QRgb alpha = qRgba( qRed( col ), qGreen( col ), qBlue( col ), a ); |
99 | tempImage32.setPixel( i, j, alpha ); | 99 | tempImage32.setPixel( i, j, alpha ); |
100 | } | 100 | } |
101 | 101 | ||
102 | QRgb alpha = qRgba( 0, 0, 0, 0 ); | 102 | QRgb alpha = qRgba( 0, 0, 0, 0 ); |
103 | tempImage32.setPixel( 1, 0, alpha ); | 103 | tempImage32.setPixel( 1, 0, alpha ); |
104 | tempImage32.setPixel( 0, 0, alpha ); | 104 | tempImage32.setPixel( 0, 0, alpha ); |
105 | tempImage32.setPixel( 0, 1, alpha ); | 105 | tempImage32.setPixel( 0, 1, alpha ); |
106 | 106 | ||
107 | tempImage32.setPixel( cardWidth - 2, 0, alpha ); | 107 | tempImage32.setPixel( cardWidth - 2, 0, alpha ); |
108 | tempImage32.setPixel( cardWidth - 1, 0, alpha ); | 108 | tempImage32.setPixel( cardWidth - 1, 0, alpha ); |
109 | tempImage32.setPixel( cardWidth - 1, 1, alpha ); | 109 | tempImage32.setPixel( cardWidth - 1, 1, alpha ); |
110 | height--; | 110 | height--; |
111 | tempImage32.setPixel( 1, height, alpha ); | 111 | tempImage32.setPixel( 1, height, alpha ); |
112 | tempImage32.setPixel( 0, height - 1, alpha ); | 112 | tempImage32.setPixel( 0, height - 1, alpha ); |
113 | tempImage32.setPixel( 0, height, alpha ); | 113 | tempImage32.setPixel( 0, height, alpha ); |
114 | 114 | ||
115 | tempImage32.setPixel( cardWidth - 2, height, alpha ); | 115 | tempImage32.setPixel( cardWidth - 2, height, alpha ); |
116 | tempImage32.setPixel( cardWidth - 1, height, alpha ); | 116 | tempImage32.setPixel( cardWidth - 1, height, alpha ); |
117 | tempImage32.setPixel( cardWidth - 1, height - 1, alpha ); | 117 | tempImage32.setPixel( cardWidth - 1, height - 1, alpha ); |
118 | } | 118 | } |
119 | 119 | ||
120 | 120 | ||
121 | void CanvasCardPile::advance(int stage) | 121 | void CanvasCardPile::advance(int stage) |
122 | { | 122 | { |
123 | if ( stage==1 ) { | 123 | if ( stage==1 ) { |
124 | if ( animSteps-- <= 0 ) { | 124 | if ( animSteps-- <= 0 ) { |
125 | CanvasCard *item = firstCard; | 125 | CanvasCard *item = firstCard; |
126 | while (item) { | 126 | while (item) { |
127 | item->show(); | 127 | item->show(); |
128 | item = (CanvasCard *)item->getCardPile()->cardInfront(item); | 128 | item = (CanvasCard *)item->getCardPile()->cardInfront(item); |
129 | } | 129 | } |
130 | setVelocity(0,0); | 130 | setVelocity(0,0); |
131 | setAnimated(FALSE); | 131 | setAnimated(FALSE); |
132 | parent->cancelMoving(); | 132 | parent->cancelMoving(); |
133 | hide(); | 133 | hide(); |
134 | move(destX,destY); // exact | 134 | move(destX,destY); // exact |
135 | } | 135 | } |
136 | } | 136 | } |
137 | QCanvasRectangle::advance(stage); | 137 | QCanvasRectangle::advance(stage); |
138 | } | 138 | } |
139 | 139 | ||
140 | 140 | ||
141 | void CanvasCardPile::animatedMove(int x2, int y2, int steps ) | 141 | void CanvasCardPile::animatedMove(int x2, int y2, int steps ) |
142 | { | 142 | { |
143 | destX = x2; | 143 | destX = x2; |
144 | destY = y2; | 144 | destY = y2; |
145 | 145 | ||
146 | double x1 = x(), y1 = y(), dx = x2 - x1, dy = y2 - y1; | 146 | double x1 = x(), y1 = y(), dx = x2 - x1, dy = y2 - y1; |
147 | 147 | ||
148 | // Ensure a good speed | 148 | // Ensure a good speed |
149 | while ( fabs(dx/steps)+fabs(dy/steps) < 5.0 && steps > 4 ) | 149 | while ( fabs(dx/steps)+fabs(dy/steps) < 5.0 && steps > 4 ) |
150 | steps--; | 150 | steps--; |
151 | 151 | ||
152 | setAnimated(TRUE); | 152 | setAnimated(TRUE); |
153 | setVelocity(dx/steps, dy/steps); | 153 | setVelocity(dx/steps, dy/steps); |
154 | 154 | ||
155 | animSteps = steps; | 155 | animSteps = steps; |
156 | } | 156 | } |
157 | 157 | ||
158 | 158 | ||
159 | void CanvasCardPile::draw( QPainter& p ) | 159 | void CanvasCardPile::draw( QPainter& p ) |
160 | { | 160 | { |
161 | int ix = (int)x(), iy = (int)y(); | 161 | int ix = (int)x(), iy = (int)y(); |
162 | p.drawImage( ix, iy, tempImage32 ); | 162 | p.drawImage( ix, iy, tempImage32 ); |
163 | } | 163 | } |
164 | 164 | ||
165 | 165 | ||
166 | CanvasCardGame::~CanvasCardGame() { | 166 | CanvasCardGame::~CanvasCardGame() { |
167 | // the deletion stuff should be fixed now and only deletes | 167 | // the deletion stuff should be fixed now and only deletes |
168 | // items created by this CardGame. I haven't verified there are zero | 168 | // items created by this CardGame. I haven't verified there are zero |
169 | // memory leaks yet | 169 | // memory leaks yet |
170 | if ( alphaCardPile ) | 170 | if ( alphaCardPile ) |
171 | delete alphaCardPile; | 171 | delete alphaCardPile; |
172 | } | 172 | } |
173 | 173 | ||
174 | 174 | ||
175 | void CanvasCardGame::gameWon() { | 175 | void CanvasCardGame::gameWon() { |
176 | 176 | ||
177 | srand(time(NULL)); | 177 | srand(time(NULL)); |
178 | 178 | ||
179 | QCanvasItemList list = canvas()->allItems(); | 179 | QCanvasItemList list = canvas()->allItems(); |
180 | QCanvasItemList::Iterator it = list.begin(); | 180 | QCanvasItemList::Iterator it = list.begin(); |
181 | 181 | ||
182 | for (; it != list.end(); ++it) { | 182 | for (; it != list.end(); ++it) { |
183 | if ( (*it)->rtti() == canvasCardId ) { | 183 | if ( (*it)->rtti() == canvasCardId ) { |
184 | // disperse the cards everywhere | 184 | // disperse the cards everywhere |
185 | int x = 300 - rand() % 1000; | 185 | int x = 300 - rand() % 1000; |
186 | int y = 300 + rand() % 200; | 186 | int y = 300 + rand() % 200; |
187 | ((CanvasCard *)*it)->animatedMove( x, y, 50 ); | 187 | ((CanvasCard *)*it)->animatedMove( x, y, 50 ); |
188 | } | 188 | } |
189 | } | 189 | } |
190 | } | 190 | } |
191 | 191 | ||
192 | 192 | ||
193 | void CanvasCardGame::contentsMousePressEvent(QMouseEvent *e) { | 193 | void CanvasCardGame::contentsMousePressEvent(QMouseEvent *e) { |
194 | 194 | ||
195 | if ( moving ) | 195 | if ( moving ) |
196 | return; | 196 | return; |
197 | 197 | ||
198 | QCanvasItemList l = canvas()->collisions( e->pos() ); | 198 | QCanvasItemList l = canvas()->collisions( e->pos() ); |
199 | 199 | ||
200 | for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) { | 200 | for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) { |
201 | 201 | ||
202 | if ( (*it)->rtti() == canvasCardId ) { | 202 | if ( (*it)->rtti() == canvasCardId ) { |
203 | 203 | ||
204 | moving = (CanvasCard *)*it; | 204 | moving = (CanvasCard *)*it; |
205 | 205 | ||
206 | if ( moving->animated() ) | 206 | if ( moving->animated() ) |
207 | return; | 207 | return; |
208 | 208 | ||
209 | cardXOff = (int)(e->pos().x() - moving->x()); | 209 | cardXOff = (int)(e->pos().x() - moving->x()); |
210 | cardYOff = (int)(e->pos().y() - moving->y()); | 210 | cardYOff = (int)(e->pos().y() - moving->y()); |
211 | 211 | ||
212 | if ( !mousePressCard( moving, e->pos() ) ) { | 212 | if ( !mousePressCard( moving, e->pos() ) ) { |
213 | CanvasCard *card = moving; | 213 | CanvasCard *card = moving; |
214 | 214 | ||
215 | if ( alphaCardPile ) | 215 | if ( alphaCardPile ) |
216 | delete alphaCardPile; | 216 | delete alphaCardPile; |
217 | 217 | ||
218 | alphaCardPile = new CanvasCardPile( this, canvas() ); | 218 | alphaCardPile = new CanvasCardPile( this, canvas() ); |
219 | alphaCardPile->move( card->x(), card->y() ); | 219 | alphaCardPile->move( card->x(), card->y() ); |
220 | alphaCardPile->savePos(); | 220 | alphaCardPile->savePos(); |
221 | alphaCardPile->show(); | 221 | alphaCardPile->show(); |
222 | 222 | ||
223 | while (card) { | 223 | while (card) { |
224 | alphaCardPile->addCard( card ); | 224 | alphaCardPile->addCard( card ); |
225 | card->hide(); | 225 | card->hide(); |
226 | card = (CanvasCard *)card->getCardPile()->cardInfront(card); | 226 | card = (CanvasCard *)card->getCardPile()->cardInfront(card); |
227 | } | 227 | } |
228 | 228 | ||
229 | alphaCardPile->setZ( INT_MAX ); | 229 | alphaCardPile->setZ( INT_MAX ); |
230 | 230 | ||
231 | moved = TRUE; | 231 | moved = TRUE; |
232 | } else { | 232 | } else { |
233 | if ( alphaCardPile ) | 233 | if ( alphaCardPile ) |
234 | alphaCardPile->hide(); | 234 | alphaCardPile->hide(); |
235 | } | 235 | } |
236 | return; | 236 | return; |
237 | } | 237 | } |
238 | } | 238 | } |
239 | 239 | ||
240 | mousePress( e->pos() ); | 240 | mousePress( e->pos() ); |
241 | } | 241 | } |
242 | 242 | ||
243 | /* | 243 | /* |
244 | // | 244 | // |
245 | // Should have some intelligent way to make double clicking on a | 245 | // Should have some intelligent way to make double clicking on a |
246 | // card send it to the most appropriate pile | 246 | // card send it to the most appropriate pile |
247 | // | 247 | // |
248 | void CanvasCardGame::contentsMouseDoubleClickEvent(QMouseEvent *e) { | 248 | void CanvasCardGame::contentsMouseDoubleClickEvent(QMouseEvent *e) { |
249 | QCanvasItemList l = canvas()->collisions( e->pos() ); | 249 | QCanvasItemList l = canvas()->collisions( e->pos() ); |
250 | for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) { | 250 | for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) { |
251 | if ( (*it)->rtti() == canvasCardId ) { | 251 | if ( (*it)->rtti() == canvasCardId ) { |
252 | CanvasCard *card = (CanvasCard *)*it; | 252 | CanvasCard *card = (CanvasCard *)*it; |
253 | 253 | ||
254 | if ( card->animated() ) | 254 | if ( card->animated() ) |
255 | return; | 255 | return; |
256 | 256 | ||
257 | if ( card->getCardPile()->isAllowedToBeMoved(card) ) { | 257 | if ( card->getCardPile()->isAllowedToBeMoved(card) ) { |
258 | if (card->getCardPile()->cardInfront(card) == NULL) { | 258 | if (card->getCardPile()->cardInfront(card) == NULL) { |
259 | CardPile *pile = first(); | 259 | CardPile *pile = first(); |
260 | if (pile && pile->isAllowedOnTop(card)) { | 260 | if (pile && pile->isAllowedOnTop(card)) { |
261 | // move card to this pile | 261 | // move card to this pile |
262 | return; | 262 | return; |
263 | } | 263 | } |
264 | } | 264 | } |
265 | } | 265 | } |
266 | } | 266 | } |
267 | } | 267 | } |
268 | } | 268 | } |
269 | */ | 269 | */ |
270 | 270 | ||
271 | void CanvasCardGame::contentsMouseMoveEvent(QMouseEvent *e) { | 271 | void CanvasCardGame::contentsMouseMoveEvent(QMouseEvent *e) { |
272 | 272 | ||
273 | QPoint p = e->pos(); | 273 | QPoint p = e->pos(); |
274 | 274 | ||
275 | if ( moving ) { | 275 | if ( moving ) { |
276 | 276 | ||
277 | moved = TRUE; | 277 | moved = TRUE; |
278 | 278 | ||
279 | if (moving->isFacing() != TRUE) | 279 | if (moving->isFacing() != TRUE) |
280 | return; | 280 | return; |
281 | 281 | ||
282 | int tx = (int)p.x() - cardXOff; | 282 | int tx = (int)p.x() - cardXOff; |
283 | int ty = (int)p.y() - cardYOff; | 283 | int ty = (int)p.y() - cardYOff; |
284 | 284 | ||
285 | if (snapOn == TRUE) { | 285 | if (snapOn == TRUE) { |
286 | CardPile *pile = closestPile( tx, ty, 50 ); | 286 | CardPile *pile = closestPile( tx, ty, 50 ); |
287 | if ( pile && pile->isAllowedOnTop( moving ) ) { | 287 | if ( pile && pile->isAllowedOnTop( moving ) ) { |
288 | QPoint p = pile->getHypertheticalNextCardPos(); | 288 | QPoint p = pile->getHypertheticalNextCardPos(); |
289 | if ( alphaCardPile ) | 289 | if ( alphaCardPile ) |
290 | alphaCardPile->move( p.x(), p.y() ); | 290 | alphaCardPile->move( p.x(), p.y() ); |
291 | return; | 291 | return; |
292 | } | 292 | } |
293 | } | 293 | } |
294 | 294 | ||
295 | if ( alphaCardPile ) | 295 | if ( alphaCardPile ) |
296 | alphaCardPile->move( tx, ty ); | 296 | alphaCardPile->move( tx, ty ); |
297 | } | 297 | } |
298 | 298 | ||
299 | } | 299 | } |
300 | 300 | ||
301 | 301 | ||
302 | void CanvasCardGame::contentsMouseReleaseEvent(QMouseEvent *e) | 302 | void CanvasCardGame::contentsMouseReleaseEvent(QMouseEvent *e) |
303 | { | 303 | { |
304 | QPoint p = e->pos(); | 304 | QPoint p = e->pos(); |
305 | 305 | ||
306 | Q_UNUSED(p); | 306 | Q_UNUSED(p); |
307 | 307 | ||
308 | if ( moving ) { | 308 | if ( moving ) { |
309 | 309 | ||
310 | CanvasCard *item = moving; | 310 | CanvasCard *item = moving; |
311 | 311 | ||
312 | if ( item->animated() ) | 312 | if ( item->animated() ) |
313 | return; | 313 | return; |
314 | 314 | ||
315 | if ( alphaCardPile ) | 315 | if ( alphaCardPile ) |
316 | if ( moved ) { | 316 | if ( moved ) { |
317 | 317 | ||
318 | CardPile *pile = closestPile((int)alphaCardPile->x(), (int)alphaCardPile->y(), 30); | 318 | CardPile *pile = closestPile((int)alphaCardPile->x(), (int)alphaCardPile->y(), 30); |
319 | 319 | ||
320 | if (pile && pile->isAllowedOnTop(item)) { | 320 | if (pile && pile->isAllowedOnTop(item)) { |
321 | CardPile *oldPile = item->getCardPile(); | 321 | CardPile *oldPile = item->getCardPile(); |
322 | Card *c = NULL; | 322 | Card *c = NULL; |
323 | if ( oldPile != pile) { | 323 | if ( oldPile != pile) { |
324 | while ( item ) { | 324 | while ( item ) { |
325 | item->show(); | 325 | item->show(); |
326 | if ( oldPile ) { | 326 | if ( oldPile ) { |
327 | c = oldPile->cardInfront(item); | 327 | c = oldPile->cardInfront(item); |
328 | oldPile->removeCard(item); | 328 | oldPile->removeCard(item); |
329 | } | 329 | } |
330 | pile->addCardToTop(item); | 330 | pile->addCardToTop(item); |
331 | item->setCardPile(pile); | 331 | item->setCardPile(pile); |
332 | //item->move( pile->getCardPos(item) ); | 332 | //item->move( pile->getCardPos(item) ); |
333 | QPoint p = pile->getCardPos(item); | 333 | QPoint p = pile->getCardPos(item); |
334 | item->setPos( p.x(), p.y(), highestZ ); | 334 | item->setPos( p.x(), p.y(), highestZ ); |
335 | highestZ++; | 335 | highestZ++; |
336 | 336 | ||
337 | if (item->getValue() == king && haveWeWon()) { | 337 | if (item->getValue() == king && haveWeWon()) { |
338 | alphaCardPile->hide(); | 338 | alphaCardPile->hide(); |
339 | gameWon(); | 339 | gameWon(); |
340 | moving = NULL; | 340 | moving = NULL; |
341 | return; | 341 | return; |
342 | } | 342 | } |
343 | 343 | ||
344 | if (oldPile) { | 344 | if (oldPile) { |
345 | item = (CanvasCard *)c; | 345 | item = (CanvasCard *)c; |
346 | } else { | 346 | } else { |
347 | item = NULL; | 347 | item = NULL; |
348 | } | 348 | } |
349 | } | 349 | } |
350 | alphaCardPile->hide(); | 350 | alphaCardPile->hide(); |
351 | moving = NULL; | 351 | moving = NULL; |
352 | return; | 352 | return; |
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 | ||
364 | void CanvasCardGame::readPile( Config& cfg, CardPile *pile, QString name, int& highestZ ) | 364 | void 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 | ||
370 | for ( int i = 0; i < numberOfCards; i++ ) { | 370 | for ( int i = 0; i < numberOfCards; i++ ) { |
371 | QString cardStr; | 371 | QString cardStr; |
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 | card->setCardPile(pile); // cam: setCardPile muss vor addCardToTop passieren | 378 | card->setCardPile(pile); // cam: setCardPile has to happen bevor addCardToTop |
379 | pile->addCardToTop(card); // weil sonst absturz wg cardAddedToTop | 379 | pile->addCardToTop(card); // due to a empty pointer if you use 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 | } |
386 | 386 | ||
387 | 387 | ||
diff --git a/noncore/games/solitaire/chicanecardgame.cpp b/noncore/games/solitaire/chicanecardgame.cpp index a242419..6729a94 100644 --- a/noncore/games/solitaire/chicanecardgame.cpp +++ b/noncore/games/solitaire/chicanecardgame.cpp | |||
@@ -1,171 +1,177 @@ | |||
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 | ** Modified by C.A.Mader 2002 | 20 | ** created on base of patiencecardgame by cam (C.A.Mader) 2002 |
21 | ** Rules for this game: | ||
22 | **use 2 decks = 104 cards | ||
23 | **deal 8 rows with 3 hidden cards and one open card | ||
24 | ** append red to black and vice versa | ||
25 | **each card can be layed on a free place | ||
26 | **deal 8 cards at once | ||
21 | ** | 27 | ** |
22 | **********************************************************************/ | 28 | **********************************************************************/ |
23 | #include <qgfx_qws.h> | 29 | #include <qgfx_qws.h> |
24 | #include "chicanecardgame.h" | 30 | #include "chicanecardgame.h" |
25 | 31 | ||
26 | 32 | ||
27 | extern int highestZ; | 33 | extern int highestZ; |
28 | 34 | ||
29 | 35 | ||
30 | ChicaneCardGame::ChicaneCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent, 2)// Use 2 Decks | 36 | ChicaneCardGame::ChicaneCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent, 2)// Use 2 Decks |
31 | { | 37 | { |
32 | highestZ = 0; | 38 | highestZ = 0; |
33 | 39 | ||
34 | for (int i = 0; i < 8; i++) { | 40 | for (int i = 0; i < 8; i++) { |
35 | discardPiles[i] = new ChicaneDiscardPile( 27 + i * 26, 10, canvas() ); | 41 | discardPiles[i] = new ChicaneDiscardPile( 27 + i * 26, 10, canvas() ); |
36 | addCardPile(discardPiles[i]); | 42 | addCardPile(discardPiles[i]); |
37 | } | 43 | } |
38 | for (int i = 0; i < 8; i++) { | 44 | for (int i = 0; i < 8; i++) { |
39 | workingPiles[i] = new ChicaneWorkingPile( 27 + i * 26, 50, canvas() ); | 45 | workingPiles[i] = new ChicaneWorkingPile( 27 + i * 26, 50, canvas() ); |
40 | addCardPile(workingPiles[i]); | 46 | addCardPile(workingPiles[i]); |
41 | } | 47 | } |
42 | faceDownDealingPile = new ChicaneFaceDownDeck( 2, 10, canvas() ); | 48 | faceDownDealingPile = new ChicaneFaceDownDeck( 2, 10, canvas() ); |
43 | } | 49 | } |
44 | 50 | ||
45 | 51 | ||
46 | void ChicaneCardGame::deal(void) | 52 | void ChicaneCardGame::deal(void) |
47 | { | 53 | { |
48 | highestZ = 1; | 54 | highestZ = 1; |
49 | int t = 0; | 55 | int t = 0; |
50 | 56 | ||
51 | beginDealing(); | 57 | beginDealing(); |
52 | 58 | ||
53 | for (int i = 0; i < 8; i++) { | 59 | for (int i = 0; i < 8; i++) { |
54 | for (int k = 0; k < 4; k++, t++) { | 60 | for (int k = 0; k < 4; k++, t++) { |
55 | Card *card = cards[t]; | 61 | Card *card = cards[t]; |
56 | workingPiles[i]->addCardToTop(card); | 62 | workingPiles[i]->addCardToTop(card); |
57 | card->setCardPile( workingPiles[i] ); | 63 | card->setCardPile( workingPiles[i] ); |
58 | card->setPos( 0, 0, highestZ ); | 64 | card->setPos( 0, 0, highestZ ); |
59 | card->setFace(k==3); | 65 | card->setFace(k==3); |
60 | card->move( workingPiles[i]->getCardPos( card ) ); | 66 | card->move( workingPiles[i]->getCardPos( card ) ); |
61 | card->showCard(); | 67 | card->showCard(); |
62 | highestZ++; | 68 | highestZ++; |
63 | } | 69 | } |
64 | } | 70 | } |
65 | 71 | ||
66 | for ( ; t < getNumberOfCards(); t++) { | 72 | for ( ; t < getNumberOfCards(); t++) { |
67 | Card *card = cards[t]; | 73 | Card *card = cards[t]; |
68 | faceDownDealingPile->addCardToTop(card); | 74 | faceDownDealingPile->addCardToTop(card); |
69 | card->setCardPile( faceDownDealingPile ); | 75 | card->setCardPile( faceDownDealingPile ); |
70 | QPoint p = faceDownDealingPile->getCardPos( card ); | 76 | QPoint p = faceDownDealingPile->getCardPos( card ); |
71 | card->setPos( p.x(), p.y(), highestZ ); | 77 | card->setPos( p.x(), p.y(), highestZ ); |
72 | card->showCard(); | 78 | card->showCard(); |
73 | highestZ++; | 79 | highestZ++; |
74 | } | 80 | } |
75 | 81 | ||
76 | endDealing(); | 82 | endDealing(); |
77 | } | 83 | } |
78 | 84 | ||
79 | 85 | ||
80 | void ChicaneCardGame::readConfig( Config& cfg ) | 86 | void ChicaneCardGame::readConfig( Config& cfg ) |
81 | { | 87 | { |
82 | cfg.setGroup("GameState"); | 88 | cfg.setGroup("GameState"); |
83 | 89 | ||
84 | // Create Cards, but don't shuffle or deal them yet | 90 | // Create Cards, but don't shuffle or deal them yet |
85 | createDeck(); | 91 | createDeck(); |
86 | 92 | ||
87 | // Move the cards to their piles (deal them to their previous places) | 93 | // Move the cards to their piles (deal them to their previous places) |
88 | beginDealing(); | 94 | beginDealing(); |
89 | 95 | ||
90 | highestZ = 1; | 96 | highestZ = 1; |
91 | 97 | ||
92 | for (int i = 0; i < 8; i++) { | 98 | for (int i = 0; i < 8; i++) { |
93 | QString pile; | 99 | QString pile; |
94 | pile.sprintf( "ChicaneDiscardPile%i", i ); | 100 | pile.sprintf( "ChicaneDiscardPile%i", i ); |
95 | readPile( cfg, discardPiles[i], pile, highestZ ); | 101 | readPile( cfg, discardPiles[i], pile, highestZ ); |
96 | } | 102 | } |
97 | 103 | ||
98 | for (int i = 0; i < 8; i++) { | 104 | for (int i = 0; i < 8; i++) { |
99 | QString pile; | 105 | QString pile; |
100 | pile.sprintf( "ChicaneWorkingPile%i", i ); | 106 | pile.sprintf( "ChicaneWorkingPile%i", i ); |
101 | readPile( cfg, workingPiles[i], pile, highestZ ); | 107 | readPile( cfg, workingPiles[i], pile, highestZ ); |
102 | } | 108 | } |
103 | 109 | ||
104 | readPile( cfg, faceDownDealingPile, "ChicaneFaceDownDealingPile", highestZ ); | 110 | readPile( cfg, faceDownDealingPile, "ChicaneFaceDownDealingPile", highestZ ); |
105 | 111 | ||
106 | highestZ++; | 112 | highestZ++; |
107 | 113 | ||
108 | endDealing(); | 114 | endDealing(); |
109 | } | 115 | } |
110 | 116 | ||
111 | 117 | ||
112 | void ChicaneCardGame::writeConfig( Config& cfg ) | 118 | void ChicaneCardGame::writeConfig( Config& cfg ) |
113 | { | 119 | { |
114 | cfg.setGroup("GameState"); | 120 | cfg.setGroup("GameState"); |
115 | for ( int i = 0; i < 8; i++ ) { | 121 | for ( int i = 0; i < 8; i++ ) { |
116 | QString pile; | 122 | QString pile; |
117 | pile.sprintf( "ChicaneDiscardPile%i", i ); | 123 | pile.sprintf( "ChicaneDiscardPile%i", i ); |
118 | discardPiles[i]->writeConfig( cfg, pile ); | 124 | discardPiles[i]->writeConfig( cfg, pile ); |
119 | } | 125 | } |
120 | for ( int i = 0; i < 8; i++ ) { | 126 | for ( int i = 0; i < 8; i++ ) { |
121 | QString pile; | 127 | QString pile; |
122 | pile.sprintf( "ChicaneWorkingPile%i", i ); | 128 | pile.sprintf( "ChicaneWorkingPile%i", i ); |
123 | workingPiles[i]->writeConfig( cfg, pile ); | 129 | workingPiles[i]->writeConfig( cfg, pile ); |
124 | } | 130 | } |
125 | faceDownDealingPile->writeConfig( cfg, "ChicaneFaceDownDealingPile" ); | 131 | faceDownDealingPile->writeConfig( cfg, "ChicaneFaceDownDealingPile" ); |
126 | } | 132 | } |
127 | 133 | ||
128 | 134 | ||
129 | bool ChicaneCardGame::mousePressCard( Card *card, QPoint p ) | 135 | bool ChicaneCardGame::mousePressCard( Card *card, QPoint p ) |
130 | { | 136 | { |
131 | Q_UNUSED(p); | 137 | Q_UNUSED(p); |
132 | 138 | ||
133 | CanvasCard *item = (CanvasCard *)card; | 139 | CanvasCard *item = (CanvasCard *)card; |
134 | if (item->isFacing() != TRUE) { | 140 | if (item->isFacing() != TRUE) { |
135 | // From facedown stack | 141 | // From facedown stack |
136 | if ((item->x() == 2) && ((int)item->y() == 10)) { // Deal a row of 8 cards | 142 | if ((item->x() == 2) && ((int)item->y() == 10)) { // Deal a row of 8 cards |
137 | // Move 8 cards, one to each workingPile | 143 | // Move 8 cards, one to each workingPile |
138 | beginDealing(); | 144 | beginDealing(); |
139 | for (int i=0; i<8 && faceDownDealingPile->cardOnTop(); i++) { | 145 | for (int i=0; i<8 && faceDownDealingPile->cardOnTop(); i++) { |
140 | CanvasCard *card = (CanvasCard *)faceDownDealingPile->cardOnTop(); | 146 | CanvasCard *card = (CanvasCard *)faceDownDealingPile->cardOnTop(); |
141 | card->setZ(highestZ); | 147 | card->setZ(highestZ); |
142 | highestZ++; | 148 | highestZ++; |
143 | faceDownDealingPile->removeCard(card); | 149 | faceDownDealingPile->removeCard(card); |
144 | workingPiles[i]->addCardToTop(card); | 150 | workingPiles[i]->addCardToTop(card); |
145 | card->setCardPile( workingPiles[i] ); | 151 | card->setCardPile( workingPiles[i] ); |
146 | card->setFace(FALSE); | 152 | card->setFace(FALSE); |
147 | QPoint p = workingPiles[i]->getCardPos(card); | 153 | QPoint p = workingPiles[i]->getCardPos(card); |
148 | card->flipTo( p.x(), p.y() ); | 154 | card->flipTo( p.x(), p.y() ); |
149 | } | 155 | } |
150 | endDealing(); | 156 | endDealing(); |
151 | } | 157 | } |
152 | moving = NULL; | 158 | moving = NULL; |
153 | moved = FALSE; | 159 | moved = FALSE; |
154 | 160 | ||
155 | return TRUE; | 161 | return TRUE; |
156 | } else if ( !card->getCardPile()->isAllowedToBeMoved(card) ) {// Don't allow unclean columns to be moved | 162 | } else if ( !card->getCardPile()->isAllowedToBeMoved(card) ) {// Don't allow unclean columns to be moved |
157 | moving = NULL; | 163 | moving = NULL; |
158 | return TRUE; | 164 | return TRUE; |
159 | } | 165 | } |
160 | 166 | ||
161 | return FALSE; | 167 | return FALSE; |
162 | } | 168 | } |
163 | 169 | ||
164 | 170 | ||
165 | 171 | ||
166 | void ChicaneCardGame::mousePress(QPoint p) | 172 | void ChicaneCardGame::mousePress(QPoint p) |
167 | { | 173 | { |
168 | Q_UNUSED(p); | 174 | Q_UNUSED(p); |
169 | } | 175 | } |
170 | 176 | ||
171 | 177 | ||
diff --git a/noncore/games/solitaire/chicanecardgame.h b/noncore/games/solitaire/chicanecardgame.h index 668f5f4..f6bd08e 100644 --- a/noncore/games/solitaire/chicanecardgame.h +++ b/noncore/games/solitaire/chicanecardgame.h | |||
@@ -1,165 +1,174 @@ | |||
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 | ** | ||
20 | ** created on base of patiencecardgame by cam (C.A.Mader) 2002 | ||
21 | ** Rules for this game: | ||
22 | ** use 2 decks = 104 cards | ||
23 | ** deal 8 rows with 3 hidden cards and one open card | ||
24 | ** append red to black and vice versa | ||
25 | ** each card can be layed on a free place | ||
26 | ** deal 8 cards at once | ||
27 | ** | ||
19 | **********************************************************************/ | 28 | **********************************************************************/ |
20 | #ifndef CHICANE_CARD_GAME_H | 29 | #ifndef CHICANE_CARD_GAME_H |
21 | #define CHICANE_CARD_GAME_H | 30 | #define CHICANE_CARD_GAME_H |
22 | 31 | ||
23 | 32 | ||
24 | #include "patiencecardgame.h" | 33 | #include "patiencecardgame.h" |
25 | 34 | ||
26 | 35 | ||
27 | class ChicaneFaceDownDeck : public PatienceFaceDownDeck | 36 | class ChicaneFaceDownDeck : public PatienceFaceDownDeck |
28 | { | 37 | { |
29 | public: | 38 | public: |
30 | ChicaneFaceDownDeck(int x, int y, QCanvas *canvas) : | 39 | ChicaneFaceDownDeck(int x, int y, QCanvas *canvas) : |
31 | PatienceFaceDownDeck(x, y, canvas) { } | 40 | PatienceFaceDownDeck(x, y, canvas) { } |
32 | 41 | ||
33 | }; | 42 | }; |
34 | 43 | ||
35 | 44 | ||
36 | class ChicaneDiscardPile : public PatienceDiscardPile | 45 | class ChicaneDiscardPile : public PatienceDiscardPile |
37 | { | 46 | { |
38 | public: | 47 | public: |
39 | ChicaneDiscardPile(int x, int y, QCanvas *canvas) : | 48 | ChicaneDiscardPile(int x, int y, QCanvas *canvas) : |
40 | PatienceDiscardPile(x, y, canvas) { } | 49 | PatienceDiscardPile(x, y, canvas) { } |
41 | 50 | ||
42 | }; | 51 | }; |
43 | 52 | ||
44 | 53 | ||
45 | class ChicaneWorkingPile : public PatienceWorkingPile | 54 | class ChicaneWorkingPile : public PatienceWorkingPile |
46 | { | 55 | { |
47 | public: | 56 | public: |
48 | ChicaneWorkingPile(int x, int y, QCanvas *canvas) : | 57 | ChicaneWorkingPile(int x, int y, QCanvas *canvas) : |
49 | PatienceWorkingPile(x, y, canvas) { } | 58 | PatienceWorkingPile(x, y, canvas) { } |
50 | 59 | ||
51 | virtual bool isAllowedOnTop(Card *card) { | 60 | virtual bool isAllowedOnTop(Card *card) { |
52 | if ( card->isFacing() && | 61 | if ( card->isFacing() && |
53 | // ( ( ( cardOnTop() == NULL ) && (card->getValue() == king) ) || // diese Zeile sorgt dafür dass nur Kings auf leere Plätze dürfen | 62 | // ( ( ( cardOnTop() == NULL ) && (card->getValue() == king) ) || // only kings are allowed on empty places |
54 | ( (cardOnTop() == NULL) || // auf einen Freiplatz darf alles! | 63 | ( (cardOnTop() == NULL) || // each card can use an empty place |
55 | ( (cardOnTop() != NULL) && | 64 | ( (cardOnTop() != NULL) && |
56 | ((int)card->getValue() + 1 == (int)cardOnTop()->getValue()) && | 65 | ((int)card->getValue() + 1 == (int)cardOnTop()->getValue()) && |
57 | (card->isRed() != cardOnTop()->isRed()) ) ) ) | 66 | (card->isRed() != cardOnTop()->isRed()) ) ) ) |
58 | return TRUE; | 67 | return TRUE; |
59 | return FALSE; | 68 | return FALSE; |
60 | } | 69 | } |
61 | virtual bool isAllowedToBeMoved(Card *card) { | 70 | virtual bool isAllowedToBeMoved(Card *card) { |
62 | if (!card->isFacing()) return FALSE; | 71 | if (!card->isFacing()) return FALSE; |
63 | 72 | ||
64 | int nextExpectedValue = (int)card->getValue(); | 73 | int nextExpectedValue = (int)card->getValue(); |
65 | bool nextExpectedColor = card->isRed(); | 74 | bool nextExpectedColor = card->isRed(); |
66 | 75 | ||
67 | while ((card != NULL)) { | 76 | while ((card != NULL)) { |
68 | if ( (int)card->getValue() != nextExpectedValue ) | 77 | if ( (int)card->getValue() != nextExpectedValue ) |
69 | return FALSE; | 78 | return FALSE; |
70 | if ( card->isRed() != nextExpectedColor ) | 79 | if ( card->isRed() != nextExpectedColor ) |
71 | return FALSE; | 80 | return FALSE; |
72 | nextExpectedValue--;; | 81 | nextExpectedValue--;; |
73 | nextExpectedColor = !nextExpectedColor; | 82 | nextExpectedColor = !nextExpectedColor; |
74 | card = cardInfront(card); | 83 | card = cardInfront(card); |
75 | } | 84 | } |
76 | return TRUE; | 85 | return TRUE; |
77 | } | 86 | } |
78 | 87 | ||
79 | virtual void cardRemoved(Card *card) { | 88 | virtual void cardRemoved(Card *card) { |
80 | Q_UNUSED(card); | 89 | Q_UNUSED(card); |
81 | 90 | ||
82 | Card *newTopCard = cardOnTop(); | 91 | Card *newTopCard = cardOnTop(); |
83 | 92 | ||
84 | if ( !newTopCard ) { | 93 | if ( !newTopCard ) { |
85 | top = QPoint( pileX, pileY ); | 94 | top = QPoint( pileX, pileY ); |
86 | setNextX( pileX ); | 95 | setNextX( pileX ); |
87 | setNextY( pileY ); | 96 | setNextY( pileY ); |
88 | return; | 97 | return; |
89 | } else { | 98 | } else { |
90 | top = getCardPos(NULL); | 99 | top = getCardPos(NULL); |
91 | if ( newTopCard->isFacing() == FALSE ) { | 100 | if ( newTopCard->isFacing() == FALSE ) { |
92 | int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13; | 101 | int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13; |
93 | // correct the position taking in to account the card is not | 102 | // correct the position taking in to account the card is not |
94 | // yet flipped, but will become flipped | 103 | // yet flipped, but will become flipped |
95 | top = QPoint( top.x(), top.y() - 3 ); // Keine Verschiebung! | 104 | top = QPoint( top.x(), top.y() - 3 ); // no moving to the side |
96 | newTopCard->flipTo( top.x(), top.y() ); | 105 | newTopCard->flipTo( top.x(), top.y() ); |
97 | top = QPoint( top.x(), top.y() + offsetDown ); | 106 | top = QPoint( top.x(), top.y() + offsetDown ); |
98 | } | 107 | } |
99 | setNextX( top.x() ); | 108 | setNextX( top.x() ); |
100 | setNextY( top.y() ); | 109 | setNextY( top.y() ); |
101 | } | 110 | } |
102 | } | 111 | } |
103 | virtual QPoint getCardPos(Card *c) { | 112 | virtual QPoint getCardPos(Card *c) { |
104 | int x = pileX, y = pileY; | 113 | int x = pileX, y = pileY; |
105 | Card *card = cardOnBottom(); | 114 | Card *card = cardOnBottom(); |
106 | while ((card != c) && (card != NULL)) { | 115 | while ((card != c) && (card != NULL)) { |
107 | if (card->isFacing()) { | 116 | if (card->isFacing()) { |
108 | int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13; | 117 | int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13; |
109 | y += offsetDown; | 118 | y += offsetDown; |
110 | } else { | 119 | } else { |
111 | x += 0; // Keine Verschiebung! | 120 | x += 0; // no moving to the side |
112 | y += 3; | 121 | y += 3; |
113 | } | 122 | } |
114 | card = cardInfront(card); | 123 | card = cardInfront(card); |
115 | } | 124 | } |
116 | return QPoint( x, y ); | 125 | return QPoint( x, y ); |
117 | } | 126 | } |
118 | 127 | ||
119 | virtual QPoint getHypertheticalNextCardPos(void) { | 128 | virtual QPoint getHypertheticalNextCardPos(void) { |
120 | // return top; | 129 | // return top; |
121 | return QPoint( getNextX(), getNextY() ); | 130 | return QPoint( getNextX(), getNextY() ); |
122 | } | 131 | } |
123 | 132 | ||
124 | private: | 133 | private: |
125 | QPoint top; | 134 | QPoint top; |
126 | 135 | ||
127 | }; | 136 | }; |
128 | 137 | ||
129 | 138 | ||
130 | class ChicaneCardGame : public CanvasCardGame | 139 | class ChicaneCardGame : public CanvasCardGame |
131 | { | 140 | { |
132 | public: | 141 | public: |
133 | ChicaneCardGame(QCanvas *c, bool snap, QWidget *parent = 0); | 142 | ChicaneCardGame(QCanvas *c, bool snap, QWidget *parent = 0); |
134 | // virtual ~ChicaneCardGame(); | 143 | // virtual ~ChicaneCardGame(); |
135 | virtual void deal(void); | 144 | virtual void deal(void); |
136 | virtual bool haveWeWon() { | 145 | virtual bool haveWeWon() { |
137 | return ( discardPiles[0]->kingOnTop() && | 146 | return ( discardPiles[0]->kingOnTop() && |
138 | discardPiles[1]->kingOnTop() && | 147 | discardPiles[1]->kingOnTop() && |
139 | discardPiles[2]->kingOnTop() && | 148 | discardPiles[2]->kingOnTop() && |
140 | discardPiles[3]->kingOnTop() && | 149 | discardPiles[3]->kingOnTop() && |
141 | discardPiles[4]->kingOnTop() && | 150 | discardPiles[4]->kingOnTop() && |
142 | discardPiles[5]->kingOnTop() && | 151 | discardPiles[5]->kingOnTop() && |
143 | discardPiles[6]->kingOnTop() && | 152 | discardPiles[6]->kingOnTop() && |
144 | discardPiles[7]->kingOnTop() );; | 153 | discardPiles[7]->kingOnTop() );; |
145 | } | 154 | } |
146 | virtual void mousePress(QPoint p); | 155 | virtual void mousePress(QPoint p); |
147 | virtual void mouseRelease(QPoint p) { Q_UNUSED(p); } | 156 | virtual void mouseRelease(QPoint p) { Q_UNUSED(p); } |
148 | // virtual void mouseMove(QPoint p); | 157 | // virtual void mouseMove(QPoint p); |
149 | virtual bool mousePressCard(Card *card, QPoint p); | 158 | virtual bool mousePressCard(Card *card, QPoint p); |
150 | virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); } | 159 | 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); } | 160 | // virtual void mouseMoveCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); } |
152 | bool canTurnOverDeck(void) { return (FALSE); } | 161 | bool canTurnOverDeck(void) { return (FALSE); } |
153 | void throughDeck(void) { } | 162 | void throughDeck(void) { } |
154 | bool snapOn; | 163 | bool snapOn; |
155 | void writeConfig( Config& cfg ); | 164 | void writeConfig( Config& cfg ); |
156 | void readConfig( Config& cfg ); | 165 | void readConfig( Config& cfg ); |
157 | private: | 166 | private: |
158 | ChicaneWorkingPile *workingPiles[8]; | 167 | ChicaneWorkingPile *workingPiles[8]; |
159 | ChicaneDiscardPile *discardPiles[8]; | 168 | ChicaneDiscardPile *discardPiles[8]; |
160 | ChicaneFaceDownDeck *faceDownDealingPile; | 169 | ChicaneFaceDownDeck *faceDownDealingPile; |
161 | }; | 170 | }; |
162 | 171 | ||
163 | 172 | ||
164 | #endif | 173 | #endif |
165 | 174 | ||
diff --git a/noncore/games/solitaire/harpcardgame.cpp b/noncore/games/solitaire/harpcardgame.cpp index 22715ec..0711622 100644 --- a/noncore/games/solitaire/harpcardgame.cpp +++ b/noncore/games/solitaire/harpcardgame.cpp | |||
@@ -1,171 +1,179 @@ | |||
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 | ** Modified by C.A.Mader 2002 | 20 | ** created on base of patiencecardgame by cam (C.A.Mader) 2002 |
21 | ** Rules for this game: | ||
22 | ** use 2 decks = 104 cards | ||
23 | ** deal 8 rows with one open card in the first place | ||
24 | ** one hidden and one open in the second place and so on | ||
25 | ** append red to black and vice versa | ||
26 | ** each card can be layed on a free place | ||
27 | ** deal 8 cards at once | ||
28 | ** | ||
21 | ** | 29 | ** |
22 | **********************************************************************/ | 30 | **********************************************************************/ |
23 | #include <qgfx_qws.h> | 31 | #include <qgfx_qws.h> |
24 | #include "harpcardgame.h" | 32 | #include "harpcardgame.h" |
25 | 33 | ||
26 | 34 | ||
27 | extern int highestZ; | 35 | extern int highestZ; |
28 | 36 | ||
29 | 37 | ||
30 | HarpCardGame::HarpCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent, 2)// Use 2 Decks | 38 | HarpCardGame::HarpCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent, 2)// Use 2 Decks |
31 | { | 39 | { |
32 | highestZ = 0; | 40 | highestZ = 0; |
33 | 41 | ||
34 | for (int i = 0; i < 8; i++) { | 42 | for (int i = 0; i < 8; i++) { |
35 | discardPiles[i] = new HarpDiscardPile( 27 + i * 26, 10, canvas() ); | 43 | discardPiles[i] = new HarpDiscardPile( 27 + i * 26, 10, canvas() ); |
36 | addCardPile(discardPiles[i]); | 44 | addCardPile(discardPiles[i]); |
37 | } | 45 | } |
38 | for (int i = 0; i < 8; i++) { | 46 | for (int i = 0; i < 8; i++) { |
39 | workingPiles[i] = new HarpWorkingPile( 27 + i * 26, 50, canvas() ); | 47 | workingPiles[i] = new HarpWorkingPile( 27 + i * 26, 50, canvas() ); |
40 | addCardPile(workingPiles[i]); | 48 | addCardPile(workingPiles[i]); |
41 | } | 49 | } |
42 | faceDownDealingPile = new HarpFaceDownDeck( 2, 10, canvas() ); | 50 | faceDownDealingPile = new HarpFaceDownDeck( 2, 10, canvas() ); |
43 | } | 51 | } |
44 | 52 | ||
45 | 53 | ||
46 | void HarpCardGame::deal(void) | 54 | void HarpCardGame::deal(void) |
47 | { | 55 | { |
48 | highestZ = 1; | 56 | highestZ = 1; |
49 | int t = 0; | 57 | int t = 0; |
50 | 58 | ||
51 | beginDealing(); | 59 | beginDealing(); |
52 | 60 | ||
53 | for (int i = 0; i < 8; i++) { | 61 | for (int i = 0; i < 8; i++) { |
54 | for (int k = 0; k < i+1; k++, t++) { | 62 | for (int k = 0; k < i+1; k++, t++) { |
55 | Card *card = cards[t]; | 63 | Card *card = cards[t]; |
56 | workingPiles[i]->addCardToTop(card); | 64 | workingPiles[i]->addCardToTop(card); |
57 | card->setCardPile( workingPiles[i] ); | 65 | card->setCardPile( workingPiles[i] ); |
58 | card->setPos( 0, 0, highestZ ); | 66 | card->setPos( 0, 0, highestZ ); |
59 | card->setFace(k==i); | 67 | card->setFace(k==i); |
60 | card->move( workingPiles[i]->getCardPos( card ) ); | 68 | card->move( workingPiles[i]->getCardPos( card ) ); |
61 | card->showCard(); | 69 | card->showCard(); |
62 | highestZ++; | 70 | highestZ++; |
63 | } | 71 | } |
64 | } | 72 | } |
65 | 73 | ||
66 | for ( ; t < getNumberOfCards(); t++) { | 74 | for ( ; t < getNumberOfCards(); t++) { |
67 | Card *card = cards[t]; | 75 | Card *card = cards[t]; |
68 | faceDownDealingPile->addCardToTop(card); | 76 | faceDownDealingPile->addCardToTop(card); |
69 | card->setCardPile( faceDownDealingPile ); | 77 | card->setCardPile( faceDownDealingPile ); |
70 | QPoint p = faceDownDealingPile->getCardPos( card ); | 78 | QPoint p = faceDownDealingPile->getCardPos( card ); |
71 | card->setPos( p.x(), p.y(), highestZ ); | 79 | card->setPos( p.x(), p.y(), highestZ ); |
72 | card->showCard(); | 80 | card->showCard(); |
73 | highestZ++; | 81 | highestZ++; |
74 | } | 82 | } |
75 | 83 | ||
76 | endDealing(); | 84 | endDealing(); |
77 | } | 85 | } |
78 | 86 | ||
79 | 87 | ||
80 | void HarpCardGame::readConfig( Config& cfg ) | 88 | void HarpCardGame::readConfig( Config& cfg ) |
81 | { | 89 | { |
82 | cfg.setGroup("GameState"); | 90 | cfg.setGroup("GameState"); |
83 | 91 | ||
84 | // Create Cards, but don't shuffle or deal them yet | 92 | // Create Cards, but don't shuffle or deal them yet |
85 | createDeck(); | 93 | createDeck(); |
86 | 94 | ||
87 | // Move the cards to their piles (deal them to their previous places) | 95 | // Move the cards to their piles (deal them to their previous places) |
88 | beginDealing(); | 96 | beginDealing(); |
89 | 97 | ||
90 | highestZ = 1; | 98 | highestZ = 1; |
91 | 99 | ||
92 | for (int i = 0; i < 8; i++) { | 100 | for (int i = 0; i < 8; i++) { |
93 | QString pile; | 101 | QString pile; |
94 | pile.sprintf( "HarpDiscardPile%i", i ); | 102 | pile.sprintf( "HarpDiscardPile%i", i ); |
95 | readPile( cfg, discardPiles[i], pile, highestZ ); | 103 | readPile( cfg, discardPiles[i], pile, highestZ ); |
96 | } | 104 | } |
97 | 105 | ||
98 | for (int i = 0; i < 8; i++) { | 106 | for (int i = 0; i < 8; i++) { |
99 | QString pile; | 107 | QString pile; |
100 | pile.sprintf( "HarpWorkingPile%i", i ); | 108 | pile.sprintf( "HarpWorkingPile%i", i ); |
101 | readPile( cfg, workingPiles[i], pile, highestZ ); | 109 | readPile( cfg, workingPiles[i], pile, highestZ ); |
102 | } | 110 | } |
103 | 111 | ||
104 | readPile( cfg, faceDownDealingPile, "HarpFaceDownDealingPile", highestZ ); | 112 | readPile( cfg, faceDownDealingPile, "HarpFaceDownDealingPile", highestZ ); |
105 | 113 | ||
106 | highestZ++; | 114 | highestZ++; |
107 | 115 | ||
108 | endDealing(); | 116 | endDealing(); |
109 | } | 117 | } |
110 | 118 | ||
111 | 119 | ||
112 | void HarpCardGame::writeConfig( Config& cfg ) | 120 | void HarpCardGame::writeConfig( Config& cfg ) |
113 | { | 121 | { |
114 | cfg.setGroup("GameState"); | 122 | cfg.setGroup("GameState"); |
115 | for ( int i = 0; i < 8; i++ ) { | 123 | for ( int i = 0; i < 8; i++ ) { |
116 | QString pile; | 124 | QString pile; |
117 | pile.sprintf( "HarpDiscardPile%i", i ); | 125 | pile.sprintf( "HarpDiscardPile%i", i ); |
118 | discardPiles[i]->writeConfig( cfg, pile ); | 126 | discardPiles[i]->writeConfig( cfg, pile ); |
119 | } | 127 | } |
120 | for ( int i = 0; i < 8; i++ ) { | 128 | for ( int i = 0; i < 8; i++ ) { |
121 | QString pile; | 129 | QString pile; |
122 | pile.sprintf( "HarpWorkingPile%i", i ); | 130 | pile.sprintf( "HarpWorkingPile%i", i ); |
123 | workingPiles[i]->writeConfig( cfg, pile ); | 131 | workingPiles[i]->writeConfig( cfg, pile ); |
124 | } | 132 | } |
125 | faceDownDealingPile->writeConfig( cfg, "HarpFaceDownDealingPile" ); | 133 | faceDownDealingPile->writeConfig( cfg, "HarpFaceDownDealingPile" ); |
126 | } | 134 | } |
127 | 135 | ||
128 | 136 | ||
129 | bool HarpCardGame::mousePressCard( Card *card, QPoint p ) | 137 | bool HarpCardGame::mousePressCard( Card *card, QPoint p ) |
130 | { | 138 | { |
131 | Q_UNUSED(p); | 139 | Q_UNUSED(p); |
132 | 140 | ||
133 | CanvasCard *item = (CanvasCard *)card; | 141 | CanvasCard *item = (CanvasCard *)card; |
134 | if (item->isFacing() != TRUE) { | 142 | if (item->isFacing() != TRUE) { |
135 | // From facedown stack | 143 | // From facedown stack |
136 | if ((item->x() == 2) && ((int)item->y() == 10)) { // Deal a row of 8 cards | 144 | if ((item->x() == 2) && ((int)item->y() == 10)) { // Deal a row of 8 cards |
137 | // Move 8 cards, one to each workingPile | 145 | // Move 8 cards, one to each workingPile |
138 | beginDealing(); | 146 | beginDealing(); |
139 | for (int i=0; i<8 && faceDownDealingPile->cardOnTop(); i++) { | 147 | for (int i=0; i<8 && faceDownDealingPile->cardOnTop(); i++) { |
140 | CanvasCard *card = (CanvasCard *)faceDownDealingPile->cardOnTop(); | 148 | CanvasCard *card = (CanvasCard *)faceDownDealingPile->cardOnTop(); |
141 | card->setZ(highestZ); | 149 | card->setZ(highestZ); |
142 | highestZ++; | 150 | highestZ++; |
143 | faceDownDealingPile->removeCard(card); | 151 | faceDownDealingPile->removeCard(card); |
144 | workingPiles[i]->addCardToTop(card); | 152 | workingPiles[i]->addCardToTop(card); |
145 | card->setCardPile( workingPiles[i] ); | 153 | card->setCardPile( workingPiles[i] ); |
146 | card->setFace(FALSE); | 154 | card->setFace(FALSE); |
147 | QPoint p = workingPiles[i]->getCardPos(card); | 155 | QPoint p = workingPiles[i]->getCardPos(card); |
148 | card->flipTo( p.x(), p.y() ); | 156 | card->flipTo( p.x(), p.y() ); |
149 | } | 157 | } |
150 | endDealing(); | 158 | endDealing(); |
151 | } | 159 | } |
152 | moving = NULL; | 160 | moving = NULL; |
153 | moved = FALSE; | 161 | moved = FALSE; |
154 | 162 | ||
155 | return TRUE; | 163 | return TRUE; |
156 | } else if ( !card->getCardPile()->isAllowedToBeMoved(card) ) {// Don't allow unclean columns to be moved | 164 | } else if ( !card->getCardPile()->isAllowedToBeMoved(card) ) {// Don't allow unclean columns to be moved |
157 | moving = NULL; | 165 | moving = NULL; |
158 | return TRUE; | 166 | return TRUE; |
159 | } | 167 | } |
160 | 168 | ||
161 | return FALSE; | 169 | return FALSE; |
162 | } | 170 | } |
163 | 171 | ||
164 | 172 | ||
165 | 173 | ||
166 | void HarpCardGame::mousePress(QPoint p) | 174 | void HarpCardGame::mousePress(QPoint p) |
167 | { | 175 | { |
168 | Q_UNUSED(p); | 176 | Q_UNUSED(p); |
169 | } | 177 | } |
170 | 178 | ||
171 | 179 | ||
diff --git a/noncore/games/solitaire/harpcardgame.h b/noncore/games/solitaire/harpcardgame.h index d1733fd..18b95e3 100644 --- a/noncore/games/solitaire/harpcardgame.h +++ b/noncore/games/solitaire/harpcardgame.h | |||
@@ -1,165 +1,175 @@ | |||
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 | ** | ||
20 | ** created on base of patiencecardgame by cam (C.A.Mader) 2002 | ||
21 | ** Rules for this game: | ||
22 | ** use 2 decks = 104 cards | ||
23 | ** deal 8 rows with one open card in the first place | ||
24 | **one hidden and one open in the second place and so on | ||
25 | ** append red to black and vice versa | ||
26 | ** each card can be layed on a free place | ||
27 | ** deal 8 cards at once | ||
28 | ** | ||
19 | **********************************************************************/ | 29 | **********************************************************************/ |
20 | #ifndef HARP_CARD_GAME_H | 30 | #ifndef HARP_CARD_GAME_H |
21 | #define HARP_CARD_GAME_H | 31 | #define HARP_CARD_GAME_H |
22 | 32 | ||
23 | 33 | ||
24 | #include "patiencecardgame.h" | 34 | #include "patiencecardgame.h" |
25 | 35 | ||
26 | 36 | ||
27 | class HarpFaceDownDeck : public PatienceFaceDownDeck | 37 | class HarpFaceDownDeck : public PatienceFaceDownDeck |
28 | { | 38 | { |
29 | public: | 39 | public: |
30 | HarpFaceDownDeck(int x, int y, QCanvas *canvas) : | 40 | HarpFaceDownDeck(int x, int y, QCanvas *canvas) : |
31 | PatienceFaceDownDeck(x, y, canvas) { } | 41 | PatienceFaceDownDeck(x, y, canvas) { } |
32 | 42 | ||
33 | }; | 43 | }; |
34 | 44 | ||
35 | 45 | ||
36 | class HarpDiscardPile : public PatienceDiscardPile | 46 | class HarpDiscardPile : public PatienceDiscardPile |
37 | { | 47 | { |
38 | public: | 48 | public: |
39 | HarpDiscardPile(int x, int y, QCanvas *canvas) : | 49 | HarpDiscardPile(int x, int y, QCanvas *canvas) : |
40 | PatienceDiscardPile(x, y, canvas) { } | 50 | PatienceDiscardPile(x, y, canvas) { } |
41 | 51 | ||
42 | }; | 52 | }; |
43 | 53 | ||
44 | 54 | ||
45 | class HarpWorkingPile : public PatienceWorkingPile | 55 | class HarpWorkingPile : public PatienceWorkingPile |
46 | { | 56 | { |
47 | public: | 57 | public: |
48 | HarpWorkingPile(int x, int y, QCanvas *canvas) : | 58 | HarpWorkingPile(int x, int y, QCanvas *canvas) : |
49 | PatienceWorkingPile(x, y, canvas) { } | 59 | PatienceWorkingPile(x, y, canvas) { } |
50 | 60 | ||
51 | virtual bool isAllowedOnTop(Card *card) { | 61 | virtual bool isAllowedOnTop(Card *card) { |
52 | if ( card->isFacing() && | 62 | if ( card->isFacing() && |
53 | // ( ( ( cardOnTop() == NULL ) && (card->getValue() == king) ) || // diese Zeile sorgt dafür dass nur Kings auf leere Plätze dürfen | 63 | // ( ( ( cardOnTop() == NULL ) && (card->getValue() == king) ) || // only kings are allowed on empty places |
54 | ( (cardOnTop() == NULL) || // auf einen Freiplatz darf alles! | 64 | ( (cardOnTop() == NULL) || // aeach card can use an emply place |
55 | ( (cardOnTop() != NULL) && | 65 | ( (cardOnTop() != NULL) && |
56 | ((int)card->getValue() + 1 == (int)cardOnTop()->getValue()) && | 66 | ((int)card->getValue() + 1 == (int)cardOnTop()->getValue()) && |
57 | (card->isRed() != cardOnTop()->isRed()) ) ) ) | 67 | (card->isRed() != cardOnTop()->isRed()) ) ) ) |
58 | return TRUE; | 68 | return TRUE; |
59 | return FALSE; | 69 | return FALSE; |
60 | } | 70 | } |
61 | virtual bool isAllowedToBeMoved(Card *card) { | 71 | virtual bool isAllowedToBeMoved(Card *card) { |
62 | if (!card->isFacing()) return FALSE; | 72 | if (!card->isFacing()) return FALSE; |
63 | 73 | ||
64 | int nextExpectedValue = (int)card->getValue(); | 74 | int nextExpectedValue = (int)card->getValue(); |
65 | bool nextExpectedColor = card->isRed(); | 75 | bool nextExpectedColor = card->isRed(); |
66 | 76 | ||
67 | while ((card != NULL)) { | 77 | while ((card != NULL)) { |
68 | if ( (int)card->getValue() != nextExpectedValue ) | 78 | if ( (int)card->getValue() != nextExpectedValue ) |
69 | return FALSE; | 79 | return FALSE; |
70 | if ( card->isRed() != nextExpectedColor ) | 80 | if ( card->isRed() != nextExpectedColor ) |
71 | return FALSE; | 81 | return FALSE; |
72 | nextExpectedValue--;; | 82 | nextExpectedValue--;; |
73 | nextExpectedColor = !nextExpectedColor; | 83 | nextExpectedColor = !nextExpectedColor; |
74 | card = cardInfront(card); | 84 | card = cardInfront(card); |
75 | } | 85 | } |
76 | return TRUE; | 86 | return TRUE; |
77 | } | 87 | } |
78 | 88 | ||
79 | virtual void cardRemoved(Card *card) { | 89 | virtual void cardRemoved(Card *card) { |
80 | Q_UNUSED(card); | 90 | Q_UNUSED(card); |
81 | 91 | ||
82 | Card *newTopCard = cardOnTop(); | 92 | Card *newTopCard = cardOnTop(); |
83 | 93 | ||
84 | if ( !newTopCard ) { | 94 | if ( !newTopCard ) { |
85 | top = QPoint( pileX, pileY ); | 95 | top = QPoint( pileX, pileY ); |
86 | setNextX( pileX ); | 96 | setNextX( pileX ); |
87 | setNextY( pileY ); | 97 | setNextY( pileY ); |
88 | return; | 98 | return; |
89 | } else { | 99 | } else { |
90 | top = getCardPos(NULL); | 100 | top = getCardPos(NULL); |
91 | if ( newTopCard->isFacing() == FALSE ) { | 101 | if ( newTopCard->isFacing() == FALSE ) { |
92 | int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13; | 102 | int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13; |
93 | // correct the position taking in to account the card is not | 103 | // correct the position taking in to account the card is not |
94 | // yet flipped, but will become flipped | 104 | // yet flipped, but will become flipped |
95 | top = QPoint( top.x(), top.y() - 3 ); // Keine Verschiebung! | 105 | top = QPoint( top.x(), top.y() - 3 ); // no moving to the side |
96 | newTopCard->flipTo( top.x(), top.y() ); | 106 | newTopCard->flipTo( top.x(), top.y() ); |
97 | top = QPoint( top.x(), top.y() + offsetDown ); | 107 | top = QPoint( top.x(), top.y() + offsetDown ); |
98 | } | 108 | } |
99 | setNextX( top.x() ); | 109 | setNextX( top.x() ); |
100 | setNextY( top.y() ); | 110 | setNextY( top.y() ); |
101 | } | 111 | } |
102 | } | 112 | } |
103 | virtual QPoint getCardPos(Card *c) { | 113 | virtual QPoint getCardPos(Card *c) { |
104 | int x = pileX, y = pileY; | 114 | int x = pileX, y = pileY; |
105 | Card *card = cardOnBottom(); | 115 | Card *card = cardOnBottom(); |
106 | while ((card != c) && (card != NULL)) { | 116 | while ((card != c) && (card != NULL)) { |
107 | if (card->isFacing()) { | 117 | if (card->isFacing()) { |
108 | int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13; | 118 | int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13; |
109 | y += offsetDown; | 119 | y += offsetDown; |
110 | } else { | 120 | } else { |
111 | x += 0; // Keine Verschiebung! | 121 | x += 0; // no moving to the side |
112 | y += 3; | 122 | y += 3; |
113 | } | 123 | } |
114 | card = cardInfront(card); | 124 | card = cardInfront(card); |
115 | } | 125 | } |
116 | return QPoint( x, y ); | 126 | return QPoint( x, y ); |
117 | } | 127 | } |
118 | 128 | ||
119 | virtual QPoint getHypertheticalNextCardPos(void) { | 129 | virtual QPoint getHypertheticalNextCardPos(void) { |
120 | // return top; | 130 | // return top; |
121 | return QPoint( getNextX(), getNextY() ); | 131 | return QPoint( getNextX(), getNextY() ); |
122 | } | 132 | } |
123 | 133 | ||
124 | private: | 134 | private: |
125 | QPoint top; | 135 | QPoint top; |
126 | 136 | ||
127 | }; | 137 | }; |
128 | 138 | ||
129 | 139 | ||
130 | class HarpCardGame : public CanvasCardGame | 140 | class HarpCardGame : public CanvasCardGame |
131 | { | 141 | { |
132 | public: | 142 | public: |
133 | HarpCardGame(QCanvas *c, bool snap, QWidget *parent = 0); | 143 | HarpCardGame(QCanvas *c, bool snap, QWidget *parent = 0); |
134 | // virtual ~HarpCardGame(); | 144 | // virtual ~HarpCardGame(); |
135 | virtual void deal(void); | 145 | virtual void deal(void); |
136 | virtual bool haveWeWon() { | 146 | virtual bool haveWeWon() { |
137 | return ( discardPiles[0]->kingOnTop() && | 147 | return ( discardPiles[0]->kingOnTop() && |
138 | discardPiles[1]->kingOnTop() && | 148 | discardPiles[1]->kingOnTop() && |
139 | discardPiles[2]->kingOnTop() && | 149 | discardPiles[2]->kingOnTop() && |
140 | discardPiles[3]->kingOnTop() && | 150 | discardPiles[3]->kingOnTop() && |
141 | discardPiles[4]->kingOnTop() && | 151 | discardPiles[4]->kingOnTop() && |
142 | discardPiles[5]->kingOnTop() && | 152 | discardPiles[5]->kingOnTop() && |
143 | discardPiles[6]->kingOnTop() && | 153 | discardPiles[6]->kingOnTop() && |
144 | discardPiles[7]->kingOnTop() );; | 154 | discardPiles[7]->kingOnTop() );; |
145 | } | 155 | } |
146 | virtual void mousePress(QPoint p); | 156 | virtual void mousePress(QPoint p); |
147 | virtual void mouseRelease(QPoint p) { Q_UNUSED(p); } | 157 | virtual void mouseRelease(QPoint p) { Q_UNUSED(p); } |
148 | // virtual void mouseMove(QPoint p); | 158 | // virtual void mouseMove(QPoint p); |
149 | virtual bool mousePressCard(Card *card, QPoint p); | 159 | virtual bool mousePressCard(Card *card, QPoint p); |
150 | virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); } | 160 | 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); } | 161 | // virtual void mouseMoveCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); } |
152 | bool canTurnOverDeck(void) { return (FALSE); } | 162 | bool canTurnOverDeck(void) { return (FALSE); } |
153 | void throughDeck(void) { } | 163 | void throughDeck(void) { } |
154 | bool snapOn; | 164 | bool snapOn; |
155 | void writeConfig( Config& cfg ); | 165 | void writeConfig( Config& cfg ); |
156 | void readConfig( Config& cfg ); | 166 | void readConfig( Config& cfg ); |
157 | private: | 167 | private: |
158 | HarpWorkingPile *workingPiles[8]; | 168 | HarpWorkingPile *workingPiles[8]; |
159 | HarpDiscardPile *discardPiles[8]; | 169 | HarpDiscardPile *discardPiles[8]; |
160 | HarpFaceDownDeck *faceDownDealingPile; | 170 | HarpFaceDownDeck *faceDownDealingPile; |
161 | }; | 171 | }; |
162 | 172 | ||
163 | 173 | ||
164 | #endif | 174 | #endif |
165 | 175 | ||
diff --git a/noncore/games/solitaire/teeclubcardgame.cpp b/noncore/games/solitaire/teeclubcardgame.cpp index e15da96..0941e0d 100644 --- a/noncore/games/solitaire/teeclubcardgame.cpp +++ b/noncore/games/solitaire/teeclubcardgame.cpp | |||
@@ -1,194 +1,202 @@ | |||
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 | ** Modified by C.A.Mader 2002 | 20 | ** created on base of patiencecardgame by cam (C.A.Mader) 2002 |
21 | ** Rules for this game: | ||
22 | ** use 2 decks = 104 cards | ||
23 | ** deal 9 rows with 5 open cards each | ||
24 | ** append one card to each other card which is one step higher | ||
25 | ** move only columns of cards which are equal in suit | ||
26 | ** each card can be layed on a free place | ||
27 | ** deal 1 card at once on the first pile | ||
28 | ** | ||
21 | ** | 29 | ** |
22 | **********************************************************************/ | 30 | **********************************************************************/ |
23 | #include <qgfx_qws.h> | 31 | #include <qgfx_qws.h> |
24 | #include "teeclubcardgame.h" | 32 | #include "teeclubcardgame.h" |
25 | 33 | ||
26 | 34 | ||
27 | extern int highestZ; | 35 | extern int highestZ; |
28 | 36 | ||
29 | 37 | ||
30 | TeeclubCardGame::TeeclubCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent, 2)// Use 2 Decks | 38 | TeeclubCardGame::TeeclubCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent, 2)// Use 2 Decks |
31 | { | 39 | { |
32 | highestZ = 0; | 40 | highestZ = 0; |
33 | 41 | ||
34 | for (int i = 0; i < 8; i++) { | 42 | for (int i = 0; i < 8; i++) { |
35 | discardPiles[i] = new TeeclubDiscardPile( 27 + i * 26, 10, canvas() ); | 43 | discardPiles[i] = new TeeclubDiscardPile( 27 + i * 26, 10, canvas() ); |
36 | addCardPile(discardPiles[i]); | 44 | addCardPile(discardPiles[i]); |
37 | } | 45 | } |
38 | for (int i = 0; i < 9; i++) { | 46 | for (int i = 0; i < 9; i++) { |
39 | workingPiles[i] = new TeeclubWorkingPile( 2 + i * 26, 50, canvas() ); | 47 | workingPiles[i] = new TeeclubWorkingPile( 2 + i * 26, 50, canvas() ); |
40 | addCardPile(workingPiles[i]); | 48 | addCardPile(workingPiles[i]); |
41 | } | 49 | } |
42 | faceDownDealingPile = new TeeclubFaceDownDeck( 2, 10, canvas() ); | 50 | faceDownDealingPile = new TeeclubFaceDownDeck( 2, 10, canvas() ); |
43 | } | 51 | } |
44 | 52 | ||
45 | 53 | ||
46 | void TeeclubCardGame::deal(void) | 54 | void TeeclubCardGame::deal(void) |
47 | { | 55 | { |
48 | highestZ = 1; | 56 | highestZ = 1; |
49 | int t = 0; | 57 | int t = 0; |
50 | 58 | ||
51 | beginDealing(); | 59 | beginDealing(); |
52 | 60 | ||
53 | for (int i = 0; i < 9; i++) { | 61 | for (int i = 0; i < 9; i++) { |
54 | workingPiles[i]->setOffsetDown(13); | 62 | workingPiles[i]->setOffsetDown(13); |
55 | workingPiles[i]->beginPileResize(); | 63 | workingPiles[i]->beginPileResize(); |
56 | for (int k = 0; k < 5; k++, t++) { | 64 | for (int k = 0; k < 5; k++, t++) { |
57 | Card *card = cards[t]; | 65 | Card *card = cards[t]; |
58 | workingPiles[i]->addCardToTop(card); | 66 | workingPiles[i]->addCardToTop(card); |
59 | card->setCardPile( workingPiles[i] ); | 67 | card->setCardPile( workingPiles[i] ); |
60 | card->setPos( 0, 0, highestZ ); | 68 | card->setPos( 0, 0, highestZ ); |
61 | card->setFace(TRUE); | 69 | card->setFace(TRUE); |
62 | card->move( workingPiles[i]->getCardPos( card ) ); | 70 | card->move( workingPiles[i]->getCardPos( card ) ); |
63 | card->showCard(); | 71 | card->showCard(); |
64 | highestZ++; | 72 | highestZ++; |
65 | } | 73 | } |
66 | } | 74 | } |
67 | 75 | ||
68 | for ( ; t < getNumberOfCards(); t++) { | 76 | for ( ; t < getNumberOfCards(); t++) { |
69 | Card *card = cards[t]; | 77 | Card *card = cards[t]; |
70 | faceDownDealingPile->addCardToTop(card); | 78 | faceDownDealingPile->addCardToTop(card); |
71 | card->setCardPile( faceDownDealingPile ); | 79 | card->setCardPile( faceDownDealingPile ); |
72 | QPoint p = faceDownDealingPile->getCardPos( card ); | 80 | QPoint p = faceDownDealingPile->getCardPos( card ); |
73 | card->setPos( p.x(), p.y(), highestZ ); | 81 | card->setPos( p.x(), p.y(), highestZ ); |
74 | card->showCard(); | 82 | card->showCard(); |
75 | highestZ++; | 83 | highestZ++; |
76 | } | 84 | } |
77 | 85 | ||
78 | endDealing(); | 86 | endDealing(); |
79 | } | 87 | } |
80 | 88 | ||
81 | 89 | ||
82 | void TeeclubCardGame::resizePiles() | 90 | void TeeclubCardGame::resizePiles() |
83 | { | 91 | { |
84 | beginDealing(); | 92 | beginDealing(); |
85 | for (int i = 0; i < 9; i++) { | 93 | for (int i = 0; i < 9; i++) { |
86 | while ((workingPiles[i]->getCardPos(NULL).y() > 230) && (workingPiles[i]->getOffsetDown()>1)) { | 94 | while ((workingPiles[i]->getCardPos(NULL).y() > 230) && (workingPiles[i]->getOffsetDown()>1)) { |
87 | // Resizen des Stapels | 95 | // resize the pile |
88 | workingPiles[i]->setOffsetDown(workingPiles[i]->getOffsetDown()-1); | 96 | workingPiles[i]->setOffsetDown(workingPiles[i]->getOffsetDown()-1); |
89 | Card *card = workingPiles[i]->cardOnBottom(); | 97 | Card *card = workingPiles[i]->cardOnBottom(); |
90 | int p=0; | 98 | int p=0; |
91 | while (card != NULL) { | 99 | while (card != NULL) { |
92 | card->setPos( 0, 0, p++ ); | 100 | card->setPos( 0, 0, p++ ); |
93 | card->move( workingPiles[i]->getCardPos( card ) ); | 101 | card->move( workingPiles[i]->getCardPos( card ) ); |
94 | card = workingPiles[i]->cardInfront(card); | 102 | card = workingPiles[i]->cardInfront(card); |
95 | } | 103 | } |
96 | } | 104 | } |
97 | } | 105 | } |
98 | endDealing(); | 106 | endDealing(); |
99 | } | 107 | } |
100 | 108 | ||
101 | 109 | ||
102 | void TeeclubCardGame::readConfig( Config& cfg ) | 110 | void TeeclubCardGame::readConfig( Config& cfg ) |
103 | { | 111 | { |
104 | cfg.setGroup("GameState"); | 112 | cfg.setGroup("GameState"); |
105 | 113 | ||
106 | // Create Cards, but don't shuffle or deal them yet | 114 | // Create Cards, but don't shuffle or deal them yet |
107 | createDeck(); | 115 | createDeck(); |
108 | 116 | ||
109 | // Move the cards to their piles (deal them to their previous places) | 117 | // Move the cards to their piles (deal them to their previous places) |
110 | beginDealing(); | 118 | beginDealing(); |
111 | 119 | ||
112 | highestZ = 1; | 120 | highestZ = 1; |
113 | 121 | ||
114 | for (int i = 0; i < 8; i++) { | 122 | for (int i = 0; i < 8; i++) { |
115 | QString pile; | 123 | QString pile; |
116 | pile.sprintf( "TeeclubDiscardPile%i", i ); | 124 | pile.sprintf( "TeeclubDiscardPile%i", i ); |
117 | readPile( cfg, discardPiles[i], pile, highestZ ); | 125 | readPile( cfg, discardPiles[i], pile, highestZ ); |
118 | } | 126 | } |
119 | 127 | ||
120 | for (int i = 0; i < 9; i++) { | 128 | for (int i = 0; i < 9; i++) { |
121 | workingPiles[i]->endPileResize(); | 129 | workingPiles[i]->endPileResize(); |
122 | QString pile; | 130 | QString pile; |
123 | pile.sprintf( "TeeclubWorkingPile%i", i ); | 131 | pile.sprintf( "TeeclubWorkingPile%i", i ); |
124 | readPile( cfg, workingPiles[i], pile, highestZ ); | 132 | readPile( cfg, workingPiles[i], pile, highestZ ); |
125 | workingPiles[i]->beginPileResize(); | 133 | workingPiles[i]->beginPileResize(); |
126 | } | 134 | } |
127 | 135 | ||
128 | readPile( cfg, faceDownDealingPile, "TeeclubFaceDownDealingPile", highestZ ); | 136 | readPile( cfg, faceDownDealingPile, "TeeclubFaceDownDealingPile", highestZ ); |
129 | 137 | ||
130 | highestZ++; | 138 | highestZ++; |
131 | 139 | ||
132 | endDealing(); | 140 | endDealing(); |
133 | resizePiles(); | 141 | resizePiles(); |
134 | } | 142 | } |
135 | 143 | ||
136 | 144 | ||
137 | void TeeclubCardGame::writeConfig( Config& cfg ) | 145 | void TeeclubCardGame::writeConfig( Config& cfg ) |
138 | { | 146 | { |
139 | cfg.setGroup("GameState"); | 147 | cfg.setGroup("GameState"); |
140 | for ( int i = 0; i < 8; i++ ) { | 148 | for ( int i = 0; i < 8; i++ ) { |
141 | QString pile; | 149 | QString pile; |
142 | pile.sprintf( "TeeclubDiscardPile%i", i ); | 150 | pile.sprintf( "TeeclubDiscardPile%i", i ); |
143 | discardPiles[i]->writeConfig( cfg, pile ); | 151 | discardPiles[i]->writeConfig( cfg, pile ); |
144 | } | 152 | } |
145 | for ( int i = 0; i < 9; i++ ) { | 153 | for ( int i = 0; i < 9; i++ ) { |
146 | QString pile; | 154 | QString pile; |
147 | pile.sprintf( "TeeclubWorkingPile%i", i ); | 155 | pile.sprintf( "TeeclubWorkingPile%i", i ); |
148 | workingPiles[i]->writeConfig( cfg, pile ); | 156 | workingPiles[i]->writeConfig( cfg, pile ); |
149 | } | 157 | } |
150 | faceDownDealingPile->writeConfig( cfg, "TeeclubFaceDownDealingPile" ); | 158 | faceDownDealingPile->writeConfig( cfg, "TeeclubFaceDownDealingPile" ); |
151 | } | 159 | } |
152 | 160 | ||
153 | 161 | ||
154 | bool TeeclubCardGame::mousePressCard( Card *card, QPoint p ) | 162 | bool TeeclubCardGame::mousePressCard( Card *card, QPoint p ) |
155 | { | 163 | { |
156 | Q_UNUSED(p); | 164 | Q_UNUSED(p); |
157 | 165 | ||
158 | CanvasCard *item = (CanvasCard *)card; | 166 | CanvasCard *item = (CanvasCard *)card; |
159 | if (item->isFacing() != TRUE) { | 167 | if (item->isFacing() != TRUE) { |
160 | // From facedown stack | 168 | // From facedown stack |
161 | if ((item->x() == 2) && ((int)item->y() == 10)) { // Deal 1 card | 169 | if ((item->x() == 2) && ((int)item->y() == 10)) { // Deal 1 card |
162 | // Move 8 cards, one to each workingPile | 170 | // Move 8 cards, one to each workingPile |
163 | beginDealing(); | 171 | beginDealing(); |
164 | CanvasCard *card = (CanvasCard *)faceDownDealingPile->cardOnTop(); | 172 | CanvasCard *card = (CanvasCard *)faceDownDealingPile->cardOnTop(); |
165 | card->setZ(highestZ); | 173 | card->setZ(highestZ); |
166 | highestZ++; | 174 | highestZ++; |
167 | faceDownDealingPile->removeCard(card); | 175 | faceDownDealingPile->removeCard(card); |
168 | workingPiles[0]->addCardToTop(card); | 176 | workingPiles[0]->addCardToTop(card); |
169 | card->setCardPile( workingPiles[0] ); | 177 | card->setCardPile( workingPiles[0] ); |
170 | card->setFace(FALSE); | 178 | card->setFace(FALSE); |
171 | QPoint p = workingPiles[0]->getCardPos(card); | 179 | QPoint p = workingPiles[0]->getCardPos(card); |
172 | card->flipTo( p.x(), p.y() ); | 180 | card->flipTo( p.x(), p.y() ); |
173 | endDealing(); | 181 | endDealing(); |
174 | } | 182 | } |
175 | moving = NULL; | 183 | moving = NULL; |
176 | moved = FALSE; | 184 | moved = FALSE; |
177 | 185 | ||
178 | return TRUE; | 186 | return TRUE; |
179 | } else if ( !card->getCardPile()->isAllowedToBeMoved(card) ) {// Don't allow unclean columns to be moved | 187 | } else if ( !card->getCardPile()->isAllowedToBeMoved(card) ) {// Don't allow unclean columns to be moved |
180 | moving = NULL; | 188 | moving = NULL; |
181 | return TRUE; | 189 | return TRUE; |
182 | } | 190 | } |
183 | 191 | ||
184 | return FALSE; | 192 | return FALSE; |
185 | } | 193 | } |
186 | 194 | ||
187 | 195 | ||
188 | 196 | ||
189 | void TeeclubCardGame::mousePress(QPoint p) | 197 | void TeeclubCardGame::mousePress(QPoint p) |
190 | { | 198 | { |
191 | Q_UNUSED(p); | 199 | Q_UNUSED(p); |
192 | } | 200 | } |
193 | 201 | ||
194 | 202 | ||
diff --git a/noncore/games/solitaire/teeclubcardgame.h b/noncore/games/solitaire/teeclubcardgame.h index 06d49f8..25cfaf9 100644 --- a/noncore/games/solitaire/teeclubcardgame.h +++ b/noncore/games/solitaire/teeclubcardgame.h | |||
@@ -1,217 +1,228 @@ | |||
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 | ** | ||
20 | ** created on base of patiencecardgame by cam (C.A.Mader) 2002 | ||
21 | ** Rules for this game: | ||
22 | ** use 2 decks = 104 cards | ||
23 | ** deal 9 rows with 5 open cards each | ||
24 | ** append one card to each other card which is one step higher | ||
25 | **move only columns of cards which are equal in suit | ||
26 | ** each card can be layed on a free place | ||
27 | ** deal 1 card at once on the first pile | ||
28 | ** | ||
29 | ** | ||
19 | **********************************************************************/ | 30 | **********************************************************************/ |
20 | #ifndef TEECLUB_CARD_GAME_H | 31 | #ifndef TEECLUB_CARD_GAME_H |
21 | #define TEECLUB_CARD_GAME_H | 32 | #define TEECLUB_CARD_GAME_H |
22 | 33 | ||
23 | 34 | ||
24 | #include "patiencecardgame.h" | 35 | #include "patiencecardgame.h" |
25 | 36 | ||
26 | 37 | ||
27 | class TeeclubFaceDownDeck : public PatienceFaceDownDeck | 38 | class TeeclubFaceDownDeck : public PatienceFaceDownDeck |
28 | { | 39 | { |
29 | public: | 40 | public: |
30 | TeeclubFaceDownDeck(int x, int y, QCanvas *canvas) : | 41 | TeeclubFaceDownDeck(int x, int y, QCanvas *canvas) : |
31 | PatienceFaceDownDeck(x, y, canvas) { } | 42 | PatienceFaceDownDeck(x, y, canvas) { } |
32 | 43 | ||
33 | }; | 44 | }; |
34 | 45 | ||
35 | 46 | ||
36 | class TeeclubDiscardPile : public CardPile, public CanvasRoundRect | 47 | class TeeclubDiscardPile : public CardPile, public CanvasRoundRect |
37 | { | 48 | { |
38 | public: | 49 | public: |
39 | TeeclubDiscardPile(int x, int y, QCanvas *canvas) | 50 | TeeclubDiscardPile(int x, int y, QCanvas *canvas) |
40 | : CardPile(x, y), CanvasRoundRect(x, y, canvas) { } | 51 | : CardPile(x, y), CanvasRoundRect(x, y, canvas) { } |
41 | virtual bool isAllowedOnTop(Card *card) { | 52 | virtual bool isAllowedOnTop(Card *card) { |
42 | if ( card->isFacing() && ( card->getCardPile()->cardInfront(card) == NULL ) && | 53 | if ( card->isFacing() && ( card->getCardPile()->cardInfront(card) == NULL ) && |
43 | ( ( ( cardOnTop() == NULL ) && ( card->getValue() == ace ) ) || | 54 | ( ( ( cardOnTop() == NULL ) && ( card->getValue() == ace ) ) || |
44 | ( ( cardOnTop() != NULL ) && | 55 | ( ( cardOnTop() != NULL ) && |
45 | ( (int)card->getValue() == (int)cardOnTop()->getValue() + 1 ) && | 56 | ( (int)card->getValue() == (int)cardOnTop()->getValue() + 1 ) && |
46 | ( card->getSuit() == cardOnTop()->getSuit() ) ) ) ) | 57 | ( card->getSuit() == cardOnTop()->getSuit() ) ) ) ) |
47 | return TRUE; | 58 | return TRUE; |
48 | return FALSE; | 59 | return FALSE; |
49 | } | 60 | } |
50 | virtual bool isAllowedToBeMoved(Card *card) { | 61 | virtual bool isAllowedToBeMoved(Card *card) { |
51 | if (card->isFacing()) return FALSE; | 62 | if (card->isFacing()) return FALSE; |
52 | return FALSE; // die Toten ruhn | 63 | return FALSE; // the deads are sleeping forever |
53 | } | 64 | } |
54 | }; | 65 | }; |
55 | 66 | ||
56 | 67 | ||
57 | class TeeclubWorkingPile : public PatienceWorkingPile | 68 | class TeeclubWorkingPile : public PatienceWorkingPile |
58 | { | 69 | { |
59 | public: | 70 | public: |
60 | TeeclubWorkingPile(int x, int y, QCanvas *canvas) : | 71 | TeeclubWorkingPile(int x, int y, QCanvas *canvas) : |
61 | PatienceWorkingPile(x, y, canvas) { } | 72 | PatienceWorkingPile(x, y, canvas) { } |
62 | 73 | ||
63 | virtual bool isAllowedOnTop(Card *card) { | 74 | virtual bool isAllowedOnTop(Card *card) { |
64 | if ( card->isFacing() && | 75 | if ( card->isFacing() && |
65 | // ( ( ( cardOnTop() == NULL ) && (card->getValue() == king) ) || // diese Zeile sorgt dafür dass nur Kings auf leere Plätze dürfen | 76 | // ( ( ( cardOnTop() == NULL ) && (card->getValue() == king) ) || // use this if only Kings are allowed on empty places |
66 | ( (cardOnTop() == NULL) || // auf einen Freiplatz darf alles! | 77 | ( (cardOnTop() == NULL) || // each card can use an empty place |
67 | ( (cardOnTop() != NULL) && | 78 | ( (cardOnTop() != NULL) && |
68 | ((int)card->getValue() + 1 == (int)cardOnTop()->getValue()) // bei teeclub sind die farben zum Anlegen egal | 79 | ((int)card->getValue() + 1 == (int)cardOnTop()->getValue()) // you can append every color on every color |
69 | ) ) ) | 80 | ) ) ) |
70 | return TRUE; | 81 | return TRUE; |
71 | return FALSE; | 82 | return FALSE; |
72 | } | 83 | } |
73 | 84 | ||
74 | virtual bool isAllowedToBeMoved(Card *card) { | 85 | virtual bool isAllowedToBeMoved(Card *card) { |
75 | if (!card->isFacing()) return FALSE; | 86 | if (!card->isFacing()) return FALSE; |
76 | 87 | ||
77 | int nextExpectedValue = (int)card->getValue(); | 88 | int nextExpectedValue = (int)card->getValue(); |
78 | eSuit nextExpectedSuit = card->getSuit(); | 89 | eSuit nextExpectedSuit = card->getSuit(); |
79 | 90 | ||
80 | while ((card != NULL)) { | 91 | while ((card != NULL)) { |
81 | if ( (int)card->getValue() != nextExpectedValue ) | 92 | if ( (int)card->getValue() != nextExpectedValue ) |
82 | return FALSE; | 93 | return FALSE; |
83 | if ( card->getSuit() != nextExpectedSuit ) | 94 | if ( card->getSuit() != nextExpectedSuit ) |
84 | return FALSE; | 95 | return FALSE; |
85 | nextExpectedValue--;; | 96 | nextExpectedValue--;; |
86 | card = cardInfront(card); | 97 | card = cardInfront(card); |
87 | } | 98 | } |
88 | return TRUE; | 99 | return TRUE; |
89 | } | 100 | } |
90 | 101 | ||
91 | virtual void cardRemoved(Card *card) { | 102 | virtual void cardRemoved(Card *card) { |
92 | Q_UNUSED(card); | 103 | Q_UNUSED(card); |
93 | 104 | ||
94 | Card *newTopCard = cardOnTop(); | 105 | Card *newTopCard = cardOnTop(); |
95 | 106 | ||
96 | if ( !newTopCard ) { | 107 | if ( !newTopCard ) { |
97 | top = QPoint( pileX, pileY ); | 108 | top = QPoint( pileX, pileY ); |
98 | setNextX( pileX ); | 109 | setNextX( pileX ); |
99 | setNextY( pileY ); | 110 | setNextY( pileY ); |
100 | setOffsetDown(13); | 111 | setOffsetDown(13); |
101 | return; | 112 | return; |
102 | } else { | 113 | } else { |
103 | top = getCardPos(NULL); | 114 | top = getCardPos(NULL); |
104 | if ( newTopCard->isFacing() == FALSE ) { | 115 | if ( newTopCard->isFacing() == FALSE ) { |
105 | int offsetDown = newTopCard->getCardPile()->getOffsetDown(); | 116 | int offsetDown = newTopCard->getCardPile()->getOffsetDown(); |
106 | // correct the position taking in to account the card is not | 117 | // correct the position taking in to account the card is not |
107 | // yet flipped, but will become flipped | 118 | // yet flipped, but will become flipped |
108 | top = QPoint( top.x(), top.y() - 3 ); // Keine seitliche Verschiebung! | 119 | top = QPoint( top.x(), top.y() - 3 ); // no moving to the side |
109 | newTopCard->flipTo( top.x(), top.y() ); | 120 | newTopCard->flipTo( top.x(), top.y() ); |
110 | top = QPoint( top.x(), top.y() + offsetDown ); | 121 | top = QPoint( top.x(), top.y() + offsetDown ); |
111 | } | 122 | } |
112 | setNextX( top.x() ); | 123 | setNextX( top.x() ); |
113 | setNextY( top.y() ); | 124 | setNextY( top.y() ); |
114 | } | 125 | } |
115 | 126 | ||
116 | if ((getCardPos(NULL).y() < 230) && (getOffsetDown()<13)) { | 127 | if ((getCardPos(NULL).y() < 230) && (getOffsetDown()<13)) { |
117 | // Resizen des Stapels | 128 | // resize the pile |
118 | beginDealing(); | 129 | beginDealing(); |
119 | setOffsetDown(getOffsetDown()+1); | 130 | setOffsetDown(getOffsetDown()+1); |
120 | Card *card = cardOnBottom(); | 131 | Card *card = cardOnBottom(); |
121 | int p=0; | 132 | int p=0; |
122 | while (card != NULL) { | 133 | while (card != NULL) { |
123 | card->setPos( 0, 0, p++ ); | 134 | card->setPos( 0, 0, p++ ); |
124 | card->move( getCardPos( card ) ); | 135 | card->move( getCardPos( card ) ); |
125 | card = cardInfront(card); | 136 | card = cardInfront(card); |
126 | } | 137 | } |
127 | endDealing(); | 138 | endDealing(); |
128 | } | 139 | } |
129 | } | 140 | } |
130 | 141 | ||
131 | virtual QPoint getCardPos(Card *c) { | 142 | virtual QPoint getCardPos(Card *c) { |
132 | int x = pileX, y = pileY; | 143 | int x = pileX, y = pileY; |
133 | Card *card = cardOnBottom(); | 144 | Card *card = cardOnBottom(); |
134 | while ((card != c) && (card != NULL)) { | 145 | while ((card != c) && (card != NULL)) { |
135 | if (card->isFacing()) { | 146 | if (card->isFacing()) { |
136 | int offsetDown = card->getCardPile()->getOffsetDown(); | 147 | int offsetDown = card->getCardPile()->getOffsetDown(); |
137 | y += offsetDown; | 148 | y += offsetDown; |
138 | } else { | 149 | } else { |
139 | x += 0; // Keine seitliche Verschiebung! | 150 | x += 0; // no moving to the side |
140 | y += 3; | 151 | y += 3; |
141 | } | 152 | } |
142 | card = cardInfront(card); | 153 | card = cardInfront(card); |
143 | } | 154 | } |
144 | return QPoint( x, y ); | 155 | return QPoint( x, y ); |
145 | } | 156 | } |
146 | 157 | ||
147 | virtual QPoint getHypertheticalNextCardPos(void) { | 158 | virtual QPoint getHypertheticalNextCardPos(void) { |
148 | return QPoint( getNextX(), getNextY() ); | 159 | return QPoint( getNextX(), getNextY() ); |
149 | } | 160 | } |
150 | 161 | ||
151 | virtual void cardAddedToTop(Card *c) { | 162 | virtual void cardAddedToTop(Card *c) { |
152 | Q_UNUSED(c); | 163 | Q_UNUSED(c); |
153 | setNextX( getCardPos(NULL).x() ); | 164 | setNextX( getCardPos(NULL).x() ); |
154 | setNextY( getCardPos(NULL).y() ); | 165 | setNextY( getCardPos(NULL).y() ); |
155 | 166 | ||
156 | while (isPileResize() && (getCardPos(NULL).y() > 230) && (getOffsetDown()>1)) { | 167 | while (isPileResize() && (getCardPos(NULL).y() > 230) && (getOffsetDown()>1)) { |
157 | // Resizen des Stapels | 168 | // resize the pile |
158 | beginDealing(); | 169 | beginDealing(); |
159 | setOffsetDown(getOffsetDown()-1); | 170 | setOffsetDown(getOffsetDown()-1); |
160 | Card *card = cardOnBottom(); | 171 | Card *card = cardOnBottom(); |
161 | int p=0; | 172 | int p=0; |
162 | while (card != NULL) { | 173 | while (card != NULL) { |
163 | card->setPos( 0, 0, p++ ); | 174 | card->setPos( 0, 0, p++ ); |
164 | card->move( getCardPos( card ) ); | 175 | card->move( getCardPos( card ) ); |
165 | card = cardInfront(card); | 176 | card = cardInfront(card); |
166 | } | 177 | } |
167 | endDealing(); | 178 | endDealing(); |
168 | } | 179 | } |
169 | 180 | ||
170 | } | 181 | } |
171 | 182 | ||
172 | 183 | ||
173 | 184 | ||
174 | 185 | ||
175 | private: | 186 | private: |
176 | QPoint top; | 187 | QPoint top; |
177 | 188 | ||
178 | }; | 189 | }; |
179 | 190 | ||
180 | 191 | ||
181 | class TeeclubCardGame : public CanvasCardGame | 192 | class TeeclubCardGame : public CanvasCardGame |
182 | { | 193 | { |
183 | public: | 194 | public: |
184 | TeeclubCardGame(QCanvas *c, bool snap, QWidget *parent = 0); | 195 | TeeclubCardGame(QCanvas *c, bool snap, QWidget *parent = 0); |
185 | // virtual ~TeeclubCardGame(); | 196 | // virtual ~TeeclubCardGame(); |
186 | virtual void deal(void); | 197 | virtual void deal(void); |
187 | virtual bool haveWeWon() { | 198 | virtual bool haveWeWon() { |
188 | return ( discardPiles[0]->kingOnTop() && | 199 | return ( discardPiles[0]->kingOnTop() && |
189 | discardPiles[1]->kingOnTop() && | 200 | discardPiles[1]->kingOnTop() && |
190 | discardPiles[2]->kingOnTop() && | 201 | discardPiles[2]->kingOnTop() && |
191 | discardPiles[3]->kingOnTop() && | 202 | discardPiles[3]->kingOnTop() && |
192 | discardPiles[4]->kingOnTop() && | 203 | discardPiles[4]->kingOnTop() && |
193 | discardPiles[5]->kingOnTop() && | 204 | discardPiles[5]->kingOnTop() && |
194 | discardPiles[6]->kingOnTop() && | 205 | discardPiles[6]->kingOnTop() && |
195 | discardPiles[7]->kingOnTop() );; | 206 | discardPiles[7]->kingOnTop() );; |
196 | } | 207 | } |
197 | virtual void mousePress(QPoint p); | 208 | virtual void mousePress(QPoint p); |
198 | virtual void mouseRelease(QPoint p) { Q_UNUSED(p); } | 209 | virtual void mouseRelease(QPoint p) { Q_UNUSED(p); } |
199 | // virtual void mouseMove(QPoint p); | 210 | // virtual void mouseMove(QPoint p); |
200 | virtual bool mousePressCard(Card *card, QPoint p); | 211 | virtual bool mousePressCard(Card *card, QPoint p); |
201 | virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); } | 212 | 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); } | 213 | // virtual void mouseMoveCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); } |
203 | bool canTurnOverDeck(void) { return (FALSE); } | 214 | bool canTurnOverDeck(void) { return (FALSE); } |
204 | void throughDeck(void) { } | 215 | void throughDeck(void) { } |
205 | bool snapOn; | 216 | bool snapOn; |
206 | void writeConfig( Config& cfg ); | 217 | void writeConfig( Config& cfg ); |
207 | void readConfig( Config& cfg ); | 218 | void readConfig( Config& cfg ); |
208 | void resizePiles(); | 219 | void resizePiles(); |
209 | private: | 220 | private: |
210 | TeeclubWorkingPile *workingPiles[9]; | 221 | TeeclubWorkingPile *workingPiles[9]; |
211 | TeeclubDiscardPile *discardPiles[8]; | 222 | TeeclubDiscardPile *discardPiles[8]; |
212 | TeeclubFaceDownDeck *faceDownDealingPile; | 223 | TeeclubFaceDownDeck *faceDownDealingPile; |
213 | }; | 224 | }; |
214 | 225 | ||
215 | 226 | ||
216 | #endif | 227 | #endif |
217 | 228 | ||