summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/solitaire/canvascardgame.cpp4
-rw-r--r--noncore/games/solitaire/canvascardwindow.cpp28
-rw-r--r--noncore/games/solitaire/canvascardwindow.h1
-rw-r--r--noncore/games/solitaire/cardgamelayout.cpp2
-rw-r--r--noncore/games/solitaire/cardpile.cpp3
-rw-r--r--noncore/games/solitaire/cardpile.h14
-rwxr-xr-xnoncore/games/solitaire/solitaire.pro35
-rw-r--r--noncore/games/solitaire/teeclubcardgame.cpp194
-rw-r--r--noncore/games/solitaire/teeclubcardgame.h217
9 files changed, 476 insertions, 22 deletions
diff --git a/noncore/games/solitaire/canvascardgame.cpp b/noncore/games/solitaire/canvascardgame.cpp
index 357e798..4404b04 100644
--- a/noncore/games/solitaire/canvascardgame.cpp
+++ b/noncore/games/solitaire/canvascardgame.cpp
@@ -122,266 +122,266 @@ 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
141void CanvasCardPile::animatedMove(int x2, int y2, int steps ) 141void 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
159void CanvasCardPile::draw( QPainter& p ) 159void 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
166CanvasCardGame::~CanvasCardGame() { 166CanvasCardGame::~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
175void CanvasCardGame::gameWon() { 175void 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
193void CanvasCardGame::contentsMousePressEvent(QMouseEvent *e) { 193void 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//
248void CanvasCardGame::contentsMouseDoubleClickEvent(QMouseEvent *e) { 248void 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
271void CanvasCardGame::contentsMouseMoveEvent(QMouseEvent *e) { 271void 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
302void CanvasCardGame::contentsMouseReleaseEvent(QMouseEvent *e) 302void 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
364void CanvasCardGame::readPile( Config& cfg, CardPile *pile, QString name, int& highestZ ) 364void CanvasCardGame::readPile( Config& cfg, CardPile *pile, QString name, int& highestZ )
365{ 365{
366 cfg.setGroup( name ); 366 cfg.setGroup( name );
367 int numberOfCards = cfg.readNumEntry("NumberOfCards", 0); 367 int numberOfCards = cfg.readNumEntry("NumberOfCards", 0);
368 Card *card = NULL; 368 Card *card = NULL;
369 369
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 pile->addCardToTop(card); 378 card->setCardPile(pile); // cam: setCardPile muss vor addCardToTop passieren
379 card->setCardPile(pile); 379 pile->addCardToTop(card); // weil sonst absturz wg cardAddedToTop
380 QPoint p = pile->getCardPos( card ); 380 QPoint p = pile->getCardPos( card );
381 card->setPos( p.x(), p.y(), highestZ ); 381 card->setPos( p.x(), p.y(), highestZ );
382 card->showCard(); 382 card->showCard();
383 highestZ++; 383 highestZ++;
384 } 384 }
385} 385}
386 386
387 387
diff --git a/noncore/games/solitaire/canvascardwindow.cpp b/noncore/games/solitaire/canvascardwindow.cpp
index e1c021e..450b4db 100644
--- a/noncore/games/solitaire/canvascardwindow.cpp
+++ b/noncore/games/solitaire/canvascardwindow.cpp
@@ -1,280 +1,304 @@
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 "canvascardwindow.h" 21#include "canvascardwindow.h"
22#include "patiencecardgame.h" 22#include "patiencecardgame.h"
23#include "freecellcardgame.h" 23#include "freecellcardgame.h"
24#include "chicanecardgame.h" 24#include "chicanecardgame.h"
25#include "harpcardgame.h" 25#include "harpcardgame.h"
26#include "teeclubcardgame.h"
26 27
27#include <qpe/resource.h> 28#include <qpe/resource.h>
28 29
29#include <qmainwindow.h> 30#include <qmainwindow.h>
30#include <qpopupmenu.h> 31#include <qpopupmenu.h>
31#include <qstyle.h> 32#include <qstyle.h>
32 33
33 34
34CanvasCardWindow::CanvasCardWindow(QWidget* parent, const char* name, WFlags f) : 35CanvasCardWindow::CanvasCardWindow(QWidget* parent, const char* name, WFlags f) :
35 QMainWindow(parent, name, f), canvas(230, 260), snapOn(TRUE), cardBack(4), gameType(0), 36 QMainWindow(parent, name, f), canvas(230, 260), snapOn(TRUE), cardBack(4), gameType(0),
36 cardGame(NULL) 37 cardGame(NULL)
37{ 38{
38 setIcon( Resource::loadPixmap( "cards" ) ); 39 setIcon( Resource::loadPixmap( "cards" ) );
39 40
40 // Create Playing Area for Games 41 // Create Playing Area for Games
41 if ( QPixmap::defaultDepth() < 12 ) { 42 if ( QPixmap::defaultDepth() < 12 ) {
42// canvas.setBackgroundColor(QColor(0x51, 0x74, 0x6B)); 43// canvas.setBackgroundColor(QColor(0x51, 0x74, 0x6B));
43 //canvas.setBackgroundColor(QColor(0x20, 0xb0, 0x50)); 44 //canvas.setBackgroundColor(QColor(0x20, 0xb0, 0x50));
44 canvas.setBackgroundColor(QColor(0x08, 0x98, 0x2D)); 45 canvas.setBackgroundColor(QColor(0x08, 0x98, 0x2D));
45 } else { 46 } else {
46 QPixmap bg; 47 QPixmap bg;
47 bg.convertFromImage( Resource::loadImage( "table_pattern" ), ThresholdDither ); 48 bg.convertFromImage( Resource::loadImage( "table_pattern" ), ThresholdDither );
48 canvas.setBackgroundPixmap(bg); 49 canvas.setBackgroundPixmap(bg);
49 } 50 }
50 51
51#if defined( QT_QWS_CASSIOPEIA ) 52#if defined( QT_QWS_CASSIOPEIA )
52 canvas.setAdvancePeriod(70); 53 canvas.setAdvancePeriod(70);
53#else 54#else
54 canvas.setAdvancePeriod(30); 55 canvas.setAdvancePeriod(30);
55#endif 56#endif
56 57
57 58
58#ifdef _PATIENCE_USE_ACCELS_ 59#ifdef _PATIENCE_USE_ACCELS_
59 QPEMenuBar* menu = menuBar(); 60 QPEMenuBar* menu = menuBar();
60 61
61 QPopupMenu* file = new QPopupMenu; 62 QPopupMenu* file = new QPopupMenu;
62 file->insertItem(tr("Patience"), this, SLOT(initPatience()), CTRL+Key_F); 63 file->insertItem(tr("Patience"), this, SLOT(initPatience()), CTRL+Key_F);
63 file->insertItem(tr("Freecell"), this, SLOT(initFreecell()), CTRL+Key_F); 64 file->insertItem(tr("Freecell"), this, SLOT(initFreecell()), CTRL+Key_F);
64 file->insertItem(tr("Chicane"), this, SLOT(initChicane()), CTRL+Key_F); 65 file->insertItem(tr("Chicane"), this, SLOT(initChicane()), CTRL+Key_F);
65 file->insertItem(tr("Harp"), this, SLOT(initHarp()), CTRL+Key_F); 66 file->insertItem(tr("Harp"), this, SLOT(initHarp()), CTRL+Key_F);
67 file->insertItem(tr("Teeclub"), this, SLOT(initTeeclub()), CTRL+Key_F);
66 menu->insertItem(tr("&Game"), file); 68 menu->insertItem(tr("&Game"), file);
67 69
68 menu->insertSeparator(); 70 menu->insertSeparator();
69 71
70 settings = new QPopupMenu; 72 settings = new QPopupMenu;
71 settings->insertItem(tr("&Change Card Backs"), this, SLOT(changeCardBacks()), Key_F2); 73 settings->insertItem(tr("&Change Card Backs"), this, SLOT(changeCardBacks()), Key_F2);
72 snap_id = settings->insertItem(tr("&Snap To Position"), this, SLOT(snapToggle()), Key_F3); 74 snap_id = settings->insertItem(tr("&Snap To Position"), this, SLOT(snapToggle()), Key_F3);
73 settings->setCheckable(TRUE); 75 settings->setCheckable(TRUE);
74 menu->insertItem(tr("&Settings"),settings); 76 menu->insertItem(tr("&Settings"),settings);
75 77
76 menu->insertSeparator(); 78 menu->insertSeparator();
77 79
78 QPopupMenu* help = new QPopupMenu; 80 QPopupMenu* help = new QPopupMenu;
79 help->insertItem(tr("&About"), this, SLOT(help()), Key_F1); 81 help->insertItem(tr("&About"), this, SLOT(help()), Key_F1);
80 help->setItemChecked(dbf_id, TRUE); 82 help->setItemChecked(dbf_id, TRUE);
81 menu->insertItem(tr("&Help"),help); 83 menu->insertItem(tr("&Help"),help);
82#else 84#else
83 QMenuBar* menu = menuBar(); 85 QMenuBar* menu = menuBar();
84 86
85 QPopupMenu* file = new QPopupMenu; 87 QPopupMenu* file = new QPopupMenu;
86 file->insertItem(tr("Patience"), this, SLOT(initPatience())); 88 file->insertItem(tr("Patience"), this, SLOT(initPatience()));
87 file->insertItem(tr("Freecell"), this, SLOT(initFreecell())); 89 file->insertItem(tr("Freecell"), this, SLOT(initFreecell()));
88 file->insertItem(tr("Chicane"), this, SLOT(initChicane())); 90 file->insertItem(tr("Chicane"), this, SLOT(initChicane()));
89 file->insertItem(tr("Harp"), this, SLOT(initHarp())); 91 file->insertItem(tr("Harp"), this, SLOT(initHarp()));
92 file->insertItem(tr("Teeclub"), this, SLOT(initTeeclub()));
90 menu->insertItem(tr("Play"), file); 93 menu->insertItem(tr("Play"), file);
91 94
92 menu->insertSeparator(); 95 menu->insertSeparator();
93 96
94 settings = new QPopupMenu; 97 settings = new QPopupMenu;
95 settings->setCheckable(TRUE); 98 settings->setCheckable(TRUE);
96 settings->insertItem(tr("Change Card Backs"), this, SLOT(changeCardBacks())); 99 settings->insertItem(tr("Change Card Backs"), this, SLOT(changeCardBacks()));
97 snap_id = settings->insertItem(tr("Snap To Position"), this, SLOT(snapToggle())); 100 snap_id = settings->insertItem(tr("Snap To Position"), this, SLOT(snapToggle()));
98 QString m; 101 QString m;
99 102
100 drawId = settings->insertItem(tr("Turn One Card"), this, SLOT(drawnToggle())); 103 drawId = settings->insertItem(tr("Turn One Card"), this, SLOT(drawnToggle()));
101 menu->insertItem(tr("Settings"),settings); 104 menu->insertItem(tr("Settings"),settings);
102 105
103#endif 106#endif
104 107
105 menu->show(); 108 menu->show();
106 109
107 Config cfg( "Patience" ); 110 Config cfg( "Patience" );
108 cfg.setGroup( "GlobalSettings" ); 111 cfg.setGroup( "GlobalSettings" );
109 snapOn = cfg.readBoolEntry( "SnapOn", TRUE); 112 snapOn = cfg.readBoolEntry( "SnapOn", TRUE);
110 settings->setItemChecked(snap_id, snapOn); 113 settings->setItemChecked(snap_id, snapOn);
111 gameType = cfg.readNumEntry( "GameType", -1 ); 114 gameType = cfg.readNumEntry( "GameType", -1 );
112 drawThree = cfg.readBoolEntry( "DrawThree", TRUE); 115 drawThree = cfg.readBoolEntry( "DrawThree", TRUE);
113 if ( gameType == 0 ) { 116 if ( gameType == 0 ) {
114 cardGame = new PatienceCardGame( &canvas, snapOn, this ); 117 cardGame = new PatienceCardGame( &canvas, snapOn, this );
115 cardGame->setNumberToDraw(drawThree ? 3 : 1); 118 cardGame->setNumberToDraw(drawThree ? 3 : 1);
116 setCaption(tr("Patience")); 119 setCaption(tr("Patience"));
117 setCentralWidget(cardGame); 120 setCentralWidget(cardGame);
118 cardGame->readConfig( cfg ); 121 cardGame->readConfig( cfg );
119 setCardBacks(); 122 setCardBacks();
120 } else if ( gameType == 1 ) { 123 } else if ( gameType == 1 ) {
121 cardGame = new FreecellCardGame( &canvas, snapOn, this ); 124 cardGame = new FreecellCardGame( &canvas, snapOn, this );
122 setCaption(tr("Freecell")); 125 setCaption(tr("Freecell"));
123 setCentralWidget(cardGame); 126 setCentralWidget(cardGame);
124 //cardGame->newGame(); // Until we know how to handle reading freecell config 127 //cardGame->newGame(); // Until we know how to handle reading freecell config
125 cardGame->readConfig( cfg ); 128 cardGame->readConfig( cfg );
126 setCardBacks(); 129 setCardBacks();
127 } else if ( gameType == 2 ) { 130 } else if ( gameType == 2 ) {
128 cardGame = new ChicaneCardGame( &canvas, snapOn, this ); 131 cardGame = new ChicaneCardGame( &canvas, snapOn, this );
129 cardGame->setNumberToDraw(1); 132 cardGame->setNumberToDraw(1);
130 setCaption(tr("Chicane")); 133 setCaption(tr("Chicane"));
131 setCentralWidget(cardGame); 134 setCentralWidget(cardGame);
132 //cardGame->newGame(); // Until we know how to handle reading freecell config
133 cardGame->readConfig( cfg ); 135 cardGame->readConfig( cfg );
134 setCardBacks(); 136 setCardBacks();
135 } else if ( gameType == 3 ) { 137 } else if ( gameType == 3 ) {
136 cardGame = new HarpCardGame( &canvas, snapOn, this ); 138 cardGame = new HarpCardGame( &canvas, snapOn, this );
137 cardGame->setNumberToDraw(1); 139 cardGame->setNumberToDraw(1);
138 setCaption(tr("Harp")); 140 setCaption(tr("Harp"));
139 setCentralWidget(cardGame); 141 setCentralWidget(cardGame);
140 //cardGame->newGame(); // Until we know how to handle reading freecell config 142 cardGame->readConfig( cfg );
143 setCardBacks();
144 } else if ( gameType == 4 ) {
145 cardGame = new TeeclubCardGame( &canvas, snapOn, this );
146 cardGame->setNumberToDraw(1);
147 setCaption(tr("Teeclub"));
148 setCentralWidget(cardGame);
141 cardGame->readConfig( cfg ); 149 cardGame->readConfig( cfg );
142 setCardBacks(); 150 setCardBacks();
143 } else { 151 } else {
144 // Probably there isn't a config file or it is broken 152 // Probably there isn't a config file or it is broken
145 // Start a new game 153 // Start a new game
146 initPatience(); 154 initPatience();
147 } 155 }
148 156
149 updateDraw(); 157 updateDraw();
150} 158}
151 159
152 160
153CanvasCardWindow::~CanvasCardWindow() 161CanvasCardWindow::~CanvasCardWindow()
154{ 162{
155 if (cardGame) { 163 if (cardGame) {
156 Config cfg("Patience"); 164 Config cfg("Patience");
157 cfg.setGroup( "GlobalSettings" ); 165 cfg.setGroup( "GlobalSettings" );
158 cfg.writeEntry( "GameType", gameType ); 166 cfg.writeEntry( "GameType", gameType );
159 cfg.writeEntry( "SnapOn", snapOn ); 167 cfg.writeEntry( "SnapOn", snapOn );
160 cfg.writeEntry( "DrawThree", drawThree); 168 cfg.writeEntry( "DrawThree", drawThree);
161 cardGame->writeConfig( cfg ); 169 cardGame->writeConfig( cfg );
162 delete cardGame; 170 delete cardGame;
163 } 171 }
164} 172}
165 173
166 174
167void CanvasCardWindow::resizeEvent(QResizeEvent *) 175void CanvasCardWindow::resizeEvent(QResizeEvent *)
168{ 176{
169 QSize s = centralWidget()->size(); 177 QSize s = centralWidget()->size();
170 int fw = style().defaultFrameWidth(); 178 int fw = style().defaultFrameWidth();
171 canvas.resize( s.width() - fw - 2, s.height() - fw - 2); 179 canvas.resize( s.width() - fw - 2, s.height() - fw - 2);
172} 180}
173 181
174 182
175void CanvasCardWindow::initPatience() 183void CanvasCardWindow::initPatience()
176{ 184{
177 // Create New Game 185 // Create New Game
178 if ( cardGame ) 186 if ( cardGame )
179 delete cardGame; 187 delete cardGame;
180 cardGame = new PatienceCardGame( &canvas, snapOn, this ); 188 cardGame = new PatienceCardGame( &canvas, snapOn, this );
181 cardGame->setNumberToDraw(drawThree ? 3 : 1); 189 cardGame->setNumberToDraw(drawThree ? 3 : 1);
182 gameType = 0; 190 gameType = 0;
183 setCaption(tr("Patience")); 191 setCaption(tr("Patience"));
184 setCentralWidget(cardGame); 192 setCentralWidget(cardGame);
185 cardGame->newGame(); 193 cardGame->newGame();
186 setCardBacks(); 194 setCardBacks();
187 updateDraw(); 195 updateDraw();
188} 196}
189 197
190 198
191void CanvasCardWindow::initFreecell() 199void CanvasCardWindow::initFreecell()
192{ 200{
193 // Create New Game 201 // Create New Game
194 if ( cardGame ) { 202 if ( cardGame ) {
195 delete cardGame; 203 delete cardGame;
196 } 204 }
197 cardGame = new FreecellCardGame( &canvas, snapOn, this ); 205 cardGame = new FreecellCardGame( &canvas, snapOn, this );
198 gameType = 1; 206 gameType = 1;
199 setCaption(tr("Freecell")); 207 setCaption(tr("Freecell"));
200 setCentralWidget(cardGame); 208 setCentralWidget(cardGame);
201 cardGame->newGame(); 209 cardGame->newGame();
202 setCardBacks(); 210 setCardBacks();
203} 211}
204 212
205 213
206void CanvasCardWindow::initChicane() 214void CanvasCardWindow::initChicane()
207{ 215{
208 // Create New Game 216 // Create New Game
209 if ( cardGame ) { 217 if ( cardGame ) {
210 delete cardGame; 218 delete cardGame;
211 } 219 }
212 cardGame = new ChicaneCardGame( &canvas, snapOn, this ); 220 cardGame = new ChicaneCardGame( &canvas, snapOn, this );
213 cardGame->setNumberToDraw(1); 221 cardGame->setNumberToDraw(1);
214 gameType = 2; 222 gameType = 2;
215 setCaption(tr("Chicane")); 223 setCaption(tr("Chicane"));
216 setCentralWidget(cardGame); 224 setCentralWidget(cardGame);
217 cardGame->newGame(); 225 cardGame->newGame();
218 setCardBacks(); 226 setCardBacks();
219} 227}
220 228
221void CanvasCardWindow::initHarp() 229void CanvasCardWindow::initHarp()
222{ 230{
223 // Create New Game 231 // Create New Game
224 if ( cardGame ) { 232 if ( cardGame ) {
225 delete cardGame; 233 delete cardGame;
226 } 234 }
227 cardGame = new HarpCardGame( &canvas, snapOn, this ); 235 cardGame = new HarpCardGame( &canvas, snapOn, this );
228 cardGame->setNumberToDraw(1); 236 cardGame->setNumberToDraw(1);
229 gameType = 3; 237 gameType = 3;
230 setCaption(tr("Harp")); 238 setCaption(tr("Harp"));
231 setCentralWidget(cardGame); 239 setCentralWidget(cardGame);
232 cardGame->newGame(); 240 cardGame->newGame();
233 setCardBacks(); 241 setCardBacks();
234} 242}
235 243
236 244
245void CanvasCardWindow::initTeeclub()
246{
247 // Create New Game
248 if ( cardGame ) {
249 delete cardGame;
250 }
251 cardGame = new TeeclubCardGame( &canvas, snapOn, this );
252 cardGame->setNumberToDraw(1);
253 gameType = 4;
254 setCaption(tr("Teeclub"));
255 setCentralWidget(cardGame);
256 cardGame->newGame();
257 setCardBacks();
258}
259
260
237void CanvasCardWindow::snapToggle() 261void CanvasCardWindow::snapToggle()
238{ 262{
239 snapOn = !snapOn; 263 snapOn = !snapOn;
240 settings->setItemChecked(snap_id, snapOn); 264 settings->setItemChecked(snap_id, snapOn);
241 cardGame->toggleSnap(); 265 cardGame->toggleSnap();
242} 266}
243 267
244 268
245void CanvasCardWindow::drawnToggle() 269void CanvasCardWindow::drawnToggle()
246{ 270{
247 cardGame->toggleCardsDrawn(); 271 cardGame->toggleCardsDrawn();
248 updateDraw(); 272 updateDraw();
249} 273}
250 274
251void CanvasCardWindow::updateDraw() { 275void CanvasCardWindow::updateDraw() {
252 if(cardGame->cardsDrawn() == 3) 276 if(cardGame->cardsDrawn() == 3)
253 settings->changeItem(drawId, tr("Turn One Card")); 277 settings->changeItem(drawId, tr("Turn One Card"));
254 else 278 else
255 settings->changeItem(drawId, tr("Turn Three Cards")); 279 settings->changeItem(drawId, tr("Turn Three Cards"));
256} 280}
257 281
258 282
259void CanvasCardWindow::setCardBacks() 283void CanvasCardWindow::setCardBacks()
260{ 284{
261 QCanvasItemList l = canvas.allItems(); 285 QCanvasItemList l = canvas.allItems();
262 286
263 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) { 287 for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
264 if ( (*it)->rtti() == canvasCardId ) 288 if ( (*it)->rtti() == canvasCardId )
265 ((CanvasCard *)(*it))->setCardBack( cardBack ); 289 ((CanvasCard *)(*it))->setCardBack( cardBack );
266 } 290 }
267} 291}
268 292
269 293
270void CanvasCardWindow::changeCardBacks() 294void CanvasCardWindow::changeCardBacks()
271{ 295{
272 cardBack++; 296 cardBack++;
273 297
274 if (cardBack == 5) 298 if (cardBack == 5)
275 cardBack = 0; 299 cardBack = 0;
276 300
277 setCardBacks(); 301 setCardBacks();
278} 302}
279 303
280 304
diff --git a/noncore/games/solitaire/canvascardwindow.h b/noncore/games/solitaire/canvascardwindow.h
index aa76730..eddb184 100644
--- a/noncore/games/solitaire/canvascardwindow.h
+++ b/noncore/games/solitaire/canvascardwindow.h
@@ -1,72 +1,73 @@
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#ifndef CANVAS_CARD_WINDOW_H 20#ifndef CANVAS_CARD_WINDOW_H
21#define CANVAS_CARD_WINDOW_H 21#define CANVAS_CARD_WINDOW_H
22 22
23 23
24#include <qmainwindow.h> 24#include <qmainwindow.h>
25#include <qcanvas.h> 25#include <qcanvas.h>
26 26
27 27
28class CanvasCardGame; 28class CanvasCardGame;
29class QPopupMenu; 29class QPopupMenu;
30 30
31 31
32class CanvasCardWindow : public QMainWindow { 32class CanvasCardWindow : public QMainWindow {
33 Q_OBJECT 33 Q_OBJECT
34 34
35public: 35public:
36 CanvasCardWindow(QWidget* parent=0, const char* name=0, WFlags f=0); 36 CanvasCardWindow(QWidget* parent=0, const char* name=0, WFlags f=0);
37 virtual ~CanvasCardWindow(); 37 virtual ~CanvasCardWindow();
38 38
39public slots: 39public slots:
40 void setCardBacks(); 40 void setCardBacks();
41 void changeCardBacks(); 41 void changeCardBacks();
42 void snapToggle(); 42 void snapToggle();
43 void drawnToggle(); 43 void drawnToggle();
44 44
45private slots: 45private slots:
46 void initFreecell(); 46 void initFreecell();
47 void initPatience(); 47 void initPatience();
48 void initChicane(); 48 void initChicane();
49 void initHarp(); 49 void initHarp();
50 void initTeeclub();
50 51
51protected: 52protected:
52 virtual void resizeEvent(QResizeEvent *e); 53 virtual void resizeEvent(QResizeEvent *e);
53 54
54 void updateDraw(); 55 void updateDraw();
55private: 56private:
56 QCanvas canvas; 57 QCanvas canvas;
57 bool snapOn; 58 bool snapOn;
58 bool drawThree; 59 bool drawThree;
59 int drawId; 60 int drawId;
60 int cardBack; 61 int cardBack;
61 int gameType; 62 int gameType;
62 CanvasCardGame *cardGame; 63 CanvasCardGame *cardGame;
63 64
64 QPopupMenu* options; 65 QPopupMenu* options;
65 QPopupMenu* settings; 66 QPopupMenu* settings;
66 int dbf_id; 67 int dbf_id;
67 int snap_id; 68 int snap_id;
68}; 69};
69 70
70 71
71#endif 72#endif
72 73
diff --git a/noncore/games/solitaire/cardgamelayout.cpp b/noncore/games/solitaire/cardgamelayout.cpp
index e21d08a..1ceee8d 100644
--- a/noncore/games/solitaire/cardgamelayout.cpp
+++ b/noncore/games/solitaire/cardgamelayout.cpp
@@ -1,61 +1,61 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include "cardgamelayout.h" 20#include "cardgamelayout.h"
21#include "card.h" 21
22 22
23CardGameLayout::~CardGameLayout() 23CardGameLayout::~CardGameLayout()
24{ 24{
25 // Should I just do setAutoDelete( TRUE ); ? 25 // Should I just do setAutoDelete( TRUE ); ?
26 for (CardPile *p = first(); p != NULL; p = next()) 26 for (CardPile *p = first(); p != NULL; p = next())
27 delete p; 27 delete p;
28} 28}
29 29
30 30
31CardPile *CardGameLayout::closestPile(int x, int y, int maxDistance) 31CardPile *CardGameLayout::closestPile(int x, int y, int maxDistance)
32{ 32{
33 int closestDistance = maxDistance * maxDistance; 33 int closestDistance = maxDistance * maxDistance;
34 CardPile *closestPile = NULL; 34 CardPile *closestPile = NULL;
35 35
36 for (CardPile *p = first(); p != NULL; p = next()) { 36 for (CardPile *p = first(); p != NULL; p = next()) {
37 int d = p->distanceFromNextPos(x, y); 37 int d = p->distanceFromNextPos(x, y);
38 if (d < closestDistance) { 38 if (d < closestDistance) {
39 closestDistance = d; 39 closestDistance = d;
40 closestPile = p; 40 closestPile = p;
41 } 41 }
42 } 42 }
43 43
44 return closestPile; 44 return closestPile;
45} 45}
46 46
47 47
48void CardGameLayout::beginDealing() 48void CardGameLayout::beginDealing()
49{ 49{
50 for (CardPile *p = first(); p != NULL; p = next()) 50 for (CardPile *p = first(); p != NULL; p = next())
51 p->beginDealing(); 51 p->beginDealing();
52} 52}
53 53
54 54
55void CardGameLayout::endDealing() 55void CardGameLayout::endDealing()
56{ 56{
57 for (CardPile *p = first(); p != NULL; p = next()) 57 for (CardPile *p = first(); p != NULL; p = next())
58 p->endDealing(); 58 p->endDealing();
59} 59}
60 60
61 61
diff --git a/noncore/games/solitaire/cardpile.cpp b/noncore/games/solitaire/cardpile.cpp
index 3b15e93..aace2e2 100644
--- a/noncore/games/solitaire/cardpile.cpp
+++ b/noncore/games/solitaire/cardpile.cpp
@@ -1,114 +1,115 @@
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 "cardpile.h" 21#include "cardpile.h"
22#include "card.h" 22#include "card.h"
23 23
24#include <qpe/config.h> 24#include <qpe/config.h>
25#include <qpoint.h> 25#include <qpoint.h>
26 26
27#include <qlist.h> 27#include <qlist.h>
28 28
29 29
30CardPile::CardPile(int x, int y) : pileX(x), pileY(y), dealing(FALSE) { 30CardPile::CardPile(int x, int y) : pileX(x), pileY(y), dealing(FALSE), PileResize(FALSE) {
31 pileWidth = 0; 31 pileWidth = 0;
32 pileHeight = 0; 32 pileHeight = 0;
33 pileNextX = pileX; 33 pileNextX = pileX;
34 pileNextY = pileY; 34 pileNextY = pileY;
35 pileCenterX = x + pileWidth / 2; 35 pileCenterX = x + pileWidth / 2;
36 pileCenterY = y + pileHeight / 2; 36 pileCenterY = y + pileHeight / 2;
37 pileRadius = (pileWidth > pileHeight) ? pileWidth : pileHeight; 37 pileRadius = (pileWidth > pileHeight) ? pileWidth : pileHeight;
38 pileOffsetDown = 13;
38} 39}
39 40
40 41
41int CardPile::distanceFromPile(int x, int y) { 42int CardPile::distanceFromPile(int x, int y) {
42 return (pileCenterX-x)*(pileCenterX-x)+(pileCenterY-y)*(pileCenterY-y); 43 return (pileCenterX-x)*(pileCenterX-x)+(pileCenterY-y)*(pileCenterY-y);
43} 44}
44 45
45 46
46int CardPile::distanceFromNextPos(int x, int y) { 47int CardPile::distanceFromNextPos(int x, int y) {
47 return (pileNextX-x)*(pileNextX-x)+(pileNextY-y)*(pileNextY-y); 48 return (pileNextX-x)*(pileNextX-x)+(pileNextY-y)*(pileNextY-y);
48} 49}
49 50
50 51
51Card *CardPile::cardInfront(Card *c) { 52Card *CardPile::cardInfront(Card *c) {
52 CardPile *p = c->getCardPile(); 53 CardPile *p = c->getCardPile();
53 if (p) { 54 if (p) {
54 p->at(p->find(c)); 55 p->at(p->find(c));
55 return p->next(); 56 return p->next();
56 } else { 57 } else {
57 return NULL; 58 return NULL;
58 } 59 }
59} 60}
60 61
61 62
62bool CardPile::kingOnTop() { 63bool CardPile::kingOnTop() {
63 Card *top = cardOnTop(); 64 Card *top = cardOnTop();
64 return top && top->getValue() == king; 65 return top && top->getValue() == king;
65} 66}
66 67
67 68
68bool CardPile::addCardToTop(Card *c) { 69bool CardPile::addCardToTop(Card *c) {
69 if (dealing || isAllowedOnTop(c)) { 70 if (dealing || isAllowedOnTop(c)) {
70 append((const Card *)c); 71 append((const Card *)c);
71 cardAddedToTop(c); 72 cardAddedToTop(c);
72 return TRUE; 73 return TRUE;
73 } 74 }
74 return FALSE; 75 return FALSE;
75} 76}
76 77
77 78
78bool CardPile::addCardToBottom(Card *c) { 79bool CardPile::addCardToBottom(Card *c) {
79 if (dealing || isAllowedOnBottom(c)) { 80 if (dealing || isAllowedOnBottom(c)) {
80 prepend((const Card *)c); 81 prepend((const Card *)c);
81 cardAddedToBottom(c); 82 cardAddedToBottom(c);
82 return TRUE; 83 return TRUE;
83 } 84 }
84 return FALSE; 85 return FALSE;
85} 86}
86 87
87 88
88bool CardPile::removeCard(Card *c) { 89bool CardPile::removeCard(Card *c) {
89 if (dealing || isAllowedToBeMoved(c)) { 90 if (dealing || isAllowedToBeMoved(c)) {
90 take(find(c)); 91 take(find(c));
91 cardRemoved(c); 92 cardRemoved(c);
92 return TRUE; 93 return TRUE;
93 } 94 }
94 return FALSE; 95 return FALSE;
95} 96}
96 97
97 98
98void CardPile::writeConfig( Config& cfg, QString name ) { 99void CardPile::writeConfig( Config& cfg, QString name ) {
99 int numberOfCards = 0; 100 int numberOfCards = 0;
100 cfg.setGroup( name ); 101 cfg.setGroup( name );
101 Card *card = cardOnBottom(); 102 Card *card = cardOnBottom();
102 while ( card ) { 103 while ( card ) {
103 QString cardStr; 104 QString cardStr;
104 cardStr.sprintf( "%i", numberOfCards ); 105 cardStr.sprintf( "%i", numberOfCards );
105 int val = (int)card->getValue()-1 + ((int)card->getSuit()-1)*13 + (int)card->getDeckNumber()*52; 106 int val = (int)card->getValue()-1 + ((int)card->getSuit()-1)*13 + (int)card->getDeckNumber()*52;
106 cfg.writeEntry( "Card" + cardStr, val ); 107 cfg.writeEntry( "Card" + cardStr, val );
107 cfg.writeEntry( "CardFacing" + cardStr, card->isFacing() ); 108 cfg.writeEntry( "CardFacing" + cardStr, card->isFacing() );
108 card = cardInfront( card ); 109 card = cardInfront( card );
109 numberOfCards++; 110 numberOfCards++;
110 } 111 }
111 cfg.writeEntry("NumberOfCards", numberOfCards); 112 cfg.writeEntry("NumberOfCards", numberOfCards);
112} 113}
113 114
114 115
diff --git a/noncore/games/solitaire/cardpile.h b/noncore/games/solitaire/cardpile.h
index c515bbc..1eb2499 100644
--- a/noncore/games/solitaire/cardpile.h
+++ b/noncore/games/solitaire/cardpile.h
@@ -1,101 +1,115 @@
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#ifndef CARD_PILE_H 20#ifndef CARD_PILE_H
21#define CARD_PILE_H 21#define CARD_PILE_H
22 22
23 23
24#include <qpoint.h> 24#include <qpoint.h>
25#include <qlist.h> 25#include <qlist.h>
26 26
27 27
28enum ePileStackingType { 28enum ePileStackingType {
29 pileCascades = 0, pileStacks, pileCascadesOrStacks 29 pileCascades = 0, pileStacks, pileCascadesOrStacks
30}; 30};
31 31
32 32
33enum ePileFaceingType { 33enum ePileFaceingType {
34 pileFaceUp = 0, pileFaceDown, pileFaceUpOrDown 34 pileFaceUp = 0, pileFaceDown, pileFaceUpOrDown
35}; 35};
36 36
37 37
38class Card; 38class Card;
39class Config; 39class Config;
40 40
41 41
42class CardPile : public QList<Card> 42class CardPile : public QList<Card>
43{ 43{
44public: 44public:
45 CardPile(int x, int y); 45 CardPile(int x, int y);
46 virtual ~CardPile() { } 46 virtual ~CardPile() { }
47 47
48 int getX() { return pileX; } 48 int getX() { return pileX; }
49 int getY() { return pileY; } 49 int getY() { return pileY; }
50 int getNextX() { return pileNextX; } 50 int getNextX() { return pileNextX; }
51 int getNextY() { return pileNextY; } 51 int getNextY() { return pileNextY; }
52 int getWidth() { return pileWidth; } 52 int getWidth() { return pileWidth; }
53 int getHeight() { return pileHeight; } 53 int getHeight() { return pileHeight; }
54 int getOffsetDown() { return pileOffsetDown; }
55 int getAnzCardsInPile() {
56 int anz=0;
57 Card *card = cardOnBottom();
58 while (card != NULL) { anz++; card = cardInfront(card); }
59 return anz;
60 }
54 61
55 void setX(int x) { pileX = x; } 62 void setX(int x) { pileX = x; }
56 void setY(int y) { pileY = y; } 63 void setY(int y) { pileY = y; }
57 void setNextX(int x) { pileNextX = x; } 64 void setNextX(int x) { pileNextX = x; }
58 void setNextY(int y) { pileNextY = y; } 65 void setNextY(int y) { pileNextY = y; }
59 void setWidth(int width) { pileWidth = width; } 66 void setWidth(int width) { pileWidth = width; }
60 void setHeight(int height) { pileHeight = height; } 67 void setHeight(int height) { pileHeight = height; }
68 void setOffsetDown(int down) { pileOffsetDown = down; }
61 69
62 void beginDealing() { dealing = TRUE; } 70 void beginDealing() { dealing = TRUE; }
63 void endDealing() { dealing = FALSE; } 71 void endDealing() { dealing = FALSE; }
64 bool isDealing() { return dealing; } 72 bool isDealing() { return dealing; }
73
74 void beginPileResize() { PileResize = TRUE; }
75 void endPileResize() { PileResize = FALSE; }
76 bool isPileResize() { return PileResize; }
65 77
66 int distanceFromPile(int x, int y); 78 int distanceFromPile(int x, int y);
67 int distanceFromNextPos(int x, int y); 79 int distanceFromNextPos(int x, int y);
68 80
69 Card *cardOnTop() { return getLast(); } 81 Card *cardOnTop() { return getLast(); }
70 Card *cardOnBottom() { return getFirst(); } 82 Card *cardOnBottom() { return getFirst(); }
71 Card *cardInfront(Card *c); 83 Card *cardInfront(Card *c);
72 bool kingOnTop(); 84 bool kingOnTop();
73 85
74 bool addCardToTop(Card *c); 86 bool addCardToTop(Card *c);
75 bool addCardToBottom(Card *c); 87 bool addCardToBottom(Card *c);
76 bool removeCard(Card *c); 88 bool removeCard(Card *c);
77 89
78 virtual void cardAddedToTop(Card *) { } 90 virtual void cardAddedToTop(Card *) { }
79 virtual void cardAddedToBottom(Card *) { } 91 virtual void cardAddedToBottom(Card *) { }
80 virtual void cardRemoved(Card *) { } 92 virtual void cardRemoved(Card *) { }
81 virtual bool isAllowedOnTop(Card *) { return FALSE; } 93 virtual bool isAllowedOnTop(Card *) { return FALSE; }
82 virtual bool isAllowedOnBottom(Card *) { return FALSE; } 94 virtual bool isAllowedOnBottom(Card *) { return FALSE; }
83 virtual bool isAllowedToBeMoved(Card *) { return FALSE; } 95 virtual bool isAllowedToBeMoved(Card *) { return FALSE; }
84 virtual QPoint getCardPos(Card *) { return QPoint(pileX, pileY); } 96 virtual QPoint getCardPos(Card *) { return QPoint(pileX, pileY); }
85 virtual QPoint getHypertheticalNextCardPos() { return QPoint(pileX, pileY); } 97 virtual QPoint getHypertheticalNextCardPos() { return QPoint(pileX, pileY); }
86 98
87 void writeConfig( Config& cfg, QString name ); 99 void writeConfig( Config& cfg, QString name );
88 100
89protected: 101protected:
90 int pileX, pileY; 102 int pileX, pileY;
91 int pileNextX, pileNextY; 103 int pileNextX, pileNextY;
92 int pileWidth, pileHeight; 104 int pileWidth, pileHeight;
93 int pileCenterX, pileCenterY; 105 int pileCenterX, pileCenterY;
94 int pileRadius; 106 int pileRadius;
107 int pileOffsetDown;
95private: 108private:
96 bool dealing; 109 bool dealing;
110 bool PileResize;
97}; 111};
98 112
99 113
100#endif 114#endif
101 115
diff --git a/noncore/games/solitaire/solitaire.pro b/noncore/games/solitaire/solitaire.pro
index b2ba5aa..d08dab0 100755
--- a/noncore/games/solitaire/solitaire.pro
+++ b/noncore/games/solitaire/solitaire.pro
@@ -1,28 +1,31 @@
1 TEMPLATE= app 1 TEMPLATE= app
2
2 CONFIG += qt warn_on release 3 CONFIG += qt warn_on release
3 DESTDIR = $(OPIEDIR)/bin 4 DESTDIR = $(OPIEDIR)/bin
4 5
5 HEADERS = canvascard.h canvasshapes.h cardgame.h cardgamelayout.h cardpile.h card.h carddeck.h canvascardgame.h freecellcardgame.h chicanecardgame.h harpcardgame.h patiencecardgame.h canvascardwindow.h 6 HEADERS = canvascard.h canvasshapes.h cardgame.h cardgamelayout.h cardpile.h card.h carddeck.h canvascardgame.h freecellcardgame.h chicanecardgame.h harpcardgame.h teeclubcardgame.h patiencecardgame.h canvascardwindow.h
6 7
7 SOURCES = canvascard.cpp canvasshapes.cpp cardgame.cpp cardgamelayout.cpp cardpile.cpp card.cpp carddeck.cpp canvascardgame.cpp freecellcardgame.cpp chicanecardgame.cpp harpcardgame.cpp patiencecardgame.cpp canvascardwindow.cpp main.cpp 8 SOURCES = canvascard.cpp canvasshapes.cpp cardgame.cpp cardgamelayout.cpp cardpile.cpp card.cpp carddeck.cpp canvascardgame.cpp freecellcardgame.cpp chicanecardgame.cpp harpcardgame.cpp teeclubcardgame.cpp patiencecardgame.cpp canvascardwindow.cpp main.cpp
8 9
9 TARGET = patience 10 TARGET = patience
11
10INCLUDEPATH += $(OPIEDIR)/include 12INCLUDEPATH += $(OPIEDIR)/include
11 DEPENDPATH+= $(OPIEDIR)/include 13 DEPENDPATH+= $(OPIEDIR)/include
12LIBS += -lqpe 14LIBS += -lqpe
15
13 REQUIRES= patience 16 REQUIRES= patience
14 17
15TRANSLATIONS = ../../../i18n/de/patience.ts \ 18TRANSLATIONS = ../i18n/de/patience.ts
16 ../../../i18n/en/patience.ts \ 19TRANSLATIONS += ../i18n/es/patience.ts
17 ../../../i18n/es/patience.ts \ 20TRANSLATIONS += ../i18n/pt/patience.ts
18 ../../../i18n/fr/patience.ts \ 21TRANSLATIONS += ../i18n/pt_BR/patience.ts
19 ../../../i18n/hu/patience.ts \ 22TRANSLATIONS += ../i18n/en/patience.ts
20 ../../../i18n/ja/patience.ts \ 23TRANSLATIONS += ../i18n/hu/patience.ts
21 ../../../i18n/ko/patience.ts \ 24TRANSLATIONS += ../i18n/ja/patience.ts
22 ../../../i18n/no/patience.ts \ 25TRANSLATIONS += ../i18n/sl/patience.ts
23 ../../../i18n/pl/patience.ts \ 26TRANSLATIONS += ../i18n/ko/patience.ts
24 ../../../i18n/pt/patience.ts \ 27TRANSLATIONS += ../i18n/pl/patience.ts
25 ../../../i18n/pt_BR/patience.ts \ 28TRANSLATIONS += ../i18n/no/patience.ts
26 ../../../i18n/sl/patience.ts \ 29TRANSLATIONS += ../i18n/fr/patience.ts
27 ../../../i18n/zh_CN/patience.ts \ 30TRANSLATIONS += ../i18n/zh_CN/patience.ts
28 ../../../i18n/zh_TW/patience.ts 31TRANSLATIONS += ../i18n/zh_TW/patience.ts
diff --git a/noncore/games/solitaire/teeclubcardgame.cpp b/noncore/games/solitaire/teeclubcardgame.cpp
new file mode 100644
index 0000000..e15da96
--- a/dev/null
+++ b/noncore/games/solitaire/teeclubcardgame.cpp
@@ -0,0 +1,194 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**
20** Modified by C.A.Mader 2002
21**
22**********************************************************************/
23#include <qgfx_qws.h>
24#include "teeclubcardgame.h"
25
26
27extern int highestZ;
28
29
30 TeeclubCardGame::TeeclubCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent, 2)// Use 2 Decks
31{
32 highestZ = 0;
33
34 for (int i = 0; i < 8; i++) {
35 discardPiles[i] = new TeeclubDiscardPile( 27 + i * 26, 10, canvas() );
36 addCardPile(discardPiles[i]);
37 }
38 for (int i = 0; i < 9; i++) {
39 workingPiles[i] = new TeeclubWorkingPile( 2 + i * 26, 50, canvas() );
40 addCardPile(workingPiles[i]);
41 }
42 faceDownDealingPile = new TeeclubFaceDownDeck( 2, 10, canvas() );
43}
44
45
46void TeeclubCardGame::deal(void)
47{
48 highestZ = 1;
49 int t = 0;
50
51 beginDealing();
52
53 for (int i = 0; i < 9; i++) {
54 workingPiles[i]->setOffsetDown(13);
55 workingPiles[i]->beginPileResize();
56 for (int k = 0; k < 5; k++, t++) {
57 Card *card = cards[t];
58 workingPiles[i]->addCardToTop(card);
59 card->setCardPile( workingPiles[i] );
60 card->setPos( 0, 0, highestZ );
61 card->setFace(TRUE);
62 card->move( workingPiles[i]->getCardPos( card ) );
63 card->showCard();
64 highestZ++;
65 }
66 }
67
68 for ( ; t < getNumberOfCards(); t++) {
69 Card *card = cards[t];
70 faceDownDealingPile->addCardToTop(card);
71 card->setCardPile( faceDownDealingPile );
72 QPoint p = faceDownDealingPile->getCardPos( card );
73 card->setPos( p.x(), p.y(), highestZ );
74 card->showCard();
75 highestZ++;
76 }
77
78 endDealing();
79}
80
81
82void TeeclubCardGame::resizePiles()
83{
84 beginDealing();
85 for (int i = 0; i < 9; i++) {
86 while ((workingPiles[i]->getCardPos(NULL).y() > 230) && (workingPiles[i]->getOffsetDown()>1)) {
87 // Resizen des Stapels
88 workingPiles[i]->setOffsetDown(workingPiles[i]->getOffsetDown()-1);
89 Card *card = workingPiles[i]->cardOnBottom();
90 int p=0;
91 while (card != NULL) {
92 card->setPos( 0, 0, p++ );
93 card->move( workingPiles[i]->getCardPos( card ) );
94 card = workingPiles[i]->cardInfront(card);
95 }
96 }
97 }
98 endDealing();
99}
100
101
102void TeeclubCardGame::readConfig( Config& cfg )
103{
104 cfg.setGroup("GameState");
105
106 // Create Cards, but don't shuffle or deal them yet
107 createDeck();
108
109 // Move the cards to their piles (deal them to their previous places)
110 beginDealing();
111
112 highestZ = 1;
113
114 for (int i = 0; i < 8; i++) {
115 QString pile;
116 pile.sprintf( "TeeclubDiscardPile%i", i );
117 readPile( cfg, discardPiles[i], pile, highestZ );
118 }
119
120 for (int i = 0; i < 9; i++) {
121 workingPiles[i]->endPileResize();
122 QString pile;
123 pile.sprintf( "TeeclubWorkingPile%i", i );
124 readPile( cfg, workingPiles[i], pile, highestZ );
125 workingPiles[i]->beginPileResize();
126 }
127
128 readPile( cfg, faceDownDealingPile, "TeeclubFaceDownDealingPile", highestZ );
129
130 highestZ++;
131
132 endDealing();
133 resizePiles();
134}
135
136
137void TeeclubCardGame::writeConfig( Config& cfg )
138{
139 cfg.setGroup("GameState");
140 for ( int i = 0; i < 8; i++ ) {
141 QString pile;
142 pile.sprintf( "TeeclubDiscardPile%i", i );
143 discardPiles[i]->writeConfig( cfg, pile );
144 }
145 for ( int i = 0; i < 9; i++ ) {
146 QString pile;
147 pile.sprintf( "TeeclubWorkingPile%i", i );
148 workingPiles[i]->writeConfig( cfg, pile );
149 }
150 faceDownDealingPile->writeConfig( cfg, "TeeclubFaceDownDealingPile" );
151}
152
153
154bool TeeclubCardGame::mousePressCard( Card *card, QPoint p )
155{
156 Q_UNUSED(p);
157
158 CanvasCard *item = (CanvasCard *)card;
159 if (item->isFacing() != TRUE) {
160 // From facedown stack
161 if ((item->x() == 2) && ((int)item->y() == 10)) { // Deal 1 card
162 // Move 8 cards, one to each workingPile
163 beginDealing();
164 CanvasCard *card = (CanvasCard *)faceDownDealingPile->cardOnTop();
165 card->setZ(highestZ);
166 highestZ++;
167 faceDownDealingPile->removeCard(card);
168 workingPiles[0]->addCardToTop(card);
169 card->setCardPile( workingPiles[0] );
170 card->setFace(FALSE);
171 QPoint p = workingPiles[0]->getCardPos(card);
172 card->flipTo( p.x(), p.y() );
173 endDealing();
174 }
175 moving = NULL;
176 moved = FALSE;
177
178 return TRUE;
179 } else if ( !card->getCardPile()->isAllowedToBeMoved(card) ) {// Don't allow unclean columns to be moved
180 moving = NULL;
181 return TRUE;
182 }
183
184 return FALSE;
185}
186
187
188
189void TeeclubCardGame::mousePress(QPoint p)
190{
191 Q_UNUSED(p);
192}
193
194
diff --git a/noncore/games/solitaire/teeclubcardgame.h b/noncore/games/solitaire/teeclubcardgame.h
new file mode 100644
index 0000000..06d49f8
--- a/dev/null
+++ b/noncore/games/solitaire/teeclubcardgame.h
@@ -0,0 +1,217 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef TEECLUB_CARD_GAME_H
21#define TEECLUB_CARD_GAME_H
22
23
24#include "patiencecardgame.h"
25
26
27class TeeclubFaceDownDeck : public PatienceFaceDownDeck
28{
29public:
30 TeeclubFaceDownDeck(int x, int y, QCanvas *canvas) :
31 PatienceFaceDownDeck(x, y, canvas) { }
32
33};
34
35
36class TeeclubDiscardPile : public CardPile, public CanvasRoundRect
37{
38public:
39 TeeclubDiscardPile(int x, int y, QCanvas *canvas)
40 : CardPile(x, y), CanvasRoundRect(x, y, canvas) { }
41 virtual bool isAllowedOnTop(Card *card) {
42 if ( card->isFacing() && ( card->getCardPile()->cardInfront(card) == NULL ) &&
43 ( ( ( cardOnTop() == NULL ) && ( card->getValue() == ace ) ) ||
44 ( ( cardOnTop() != NULL ) &&
45 ( (int)card->getValue() == (int)cardOnTop()->getValue() + 1 ) &&
46 ( card->getSuit() == cardOnTop()->getSuit() ) ) ) )
47 return TRUE;
48 return FALSE;
49 }
50 virtual bool isAllowedToBeMoved(Card *card) {
51 if (card->isFacing()) return FALSE;
52 return FALSE; // die Toten ruhn
53 }
54};
55
56
57class TeeclubWorkingPile : public PatienceWorkingPile
58{
59public:
60 TeeclubWorkingPile(int x, int y, QCanvas *canvas) :
61 PatienceWorkingPile(x, y, canvas) { }
62
63 virtual bool isAllowedOnTop(Card *card) {
64 if ( card->isFacing() &&
65 // ( ( ( cardOnTop() == NULL ) && (card->getValue() == king) ) || // diese Zeile sorgt dafür dass nur Kings auf leere Plätze dürfen
66 ( (cardOnTop() == NULL) || // auf einen Freiplatz darf alles!
67 ( (cardOnTop() != NULL) &&
68 ((int)card->getValue() + 1 == (int)cardOnTop()->getValue()) // bei teeclub sind die farben zum Anlegen egal
69 ) ) )
70 return TRUE;
71 return FALSE;
72 }
73
74 virtual bool isAllowedToBeMoved(Card *card) {
75 if (!card->isFacing()) return FALSE;
76
77 int nextExpectedValue = (int)card->getValue();
78 eSuit nextExpectedSuit = card->getSuit();
79
80 while ((card != NULL)) {
81 if ( (int)card->getValue() != nextExpectedValue )
82 return FALSE;
83 if ( card->getSuit() != nextExpectedSuit )
84 return FALSE;
85 nextExpectedValue--;;
86 card = cardInfront(card);
87 }
88 return TRUE;
89 }
90
91 virtual void cardRemoved(Card *card) {
92 Q_UNUSED(card);
93
94 Card *newTopCard = cardOnTop();
95
96 if ( !newTopCard ) {
97 top = QPoint( pileX, pileY );
98 setNextX( pileX );
99 setNextY( pileY );
100 setOffsetDown(13);
101 return;
102 } else {
103 top = getCardPos(NULL);
104 if ( newTopCard->isFacing() == FALSE ) {
105 int offsetDown = newTopCard->getCardPile()->getOffsetDown();
106 // correct the position taking in to account the card is not
107 // yet flipped, but will become flipped
108 top = QPoint( top.x(), top.y() - 3 ); // Keine seitliche Verschiebung!
109 newTopCard->flipTo( top.x(), top.y() );
110 top = QPoint( top.x(), top.y() + offsetDown );
111 }
112 setNextX( top.x() );
113 setNextY( top.y() );
114 }
115
116 if ((getCardPos(NULL).y() < 230) && (getOffsetDown()<13)) {
117 // Resizen des Stapels
118 beginDealing();
119 setOffsetDown(getOffsetDown()+1);
120 Card *card = cardOnBottom();
121 int p=0;
122 while (card != NULL) {
123 card->setPos( 0, 0, p++ );
124 card->move( getCardPos( card ) );
125 card = cardInfront(card);
126 }
127 endDealing();
128 }
129 }
130
131 virtual QPoint getCardPos(Card *c) {
132 int x = pileX, y = pileY;
133 Card *card = cardOnBottom();
134 while ((card != c) && (card != NULL)) {
135 if (card->isFacing()) {
136 int offsetDown = card->getCardPile()->getOffsetDown();
137 y += offsetDown;
138 } else {
139 x += 0; // Keine seitliche Verschiebung!
140 y += 3;
141 }
142 card = cardInfront(card);
143 }
144 return QPoint( x, y );
145 }
146
147 virtual QPoint getHypertheticalNextCardPos(void) {
148 return QPoint( getNextX(), getNextY() );
149 }
150
151 virtual void cardAddedToTop(Card *c) {
152 Q_UNUSED(c);
153 setNextX( getCardPos(NULL).x() );
154 setNextY( getCardPos(NULL).y() );
155
156 while (isPileResize() && (getCardPos(NULL).y() > 230) && (getOffsetDown()>1)) {
157 // Resizen des Stapels
158 beginDealing();
159 setOffsetDown(getOffsetDown()-1);
160 Card *card = cardOnBottom();
161 int p=0;
162 while (card != NULL) {
163 card->setPos( 0, 0, p++ );
164 card->move( getCardPos( card ) );
165 card = cardInfront(card);
166 }
167 endDealing();
168 }
169
170 }
171
172
173
174
175private:
176 QPoint top;
177
178};
179
180
181class TeeclubCardGame : public CanvasCardGame
182{
183public:
184 TeeclubCardGame(QCanvas *c, bool snap, QWidget *parent = 0);
185// virtual ~TeeclubCardGame();
186 virtual void deal(void);
187 virtual bool haveWeWon() {
188 return ( discardPiles[0]->kingOnTop() &&
189 discardPiles[1]->kingOnTop() &&
190 discardPiles[2]->kingOnTop() &&
191 discardPiles[3]->kingOnTop() &&
192 discardPiles[4]->kingOnTop() &&
193 discardPiles[5]->kingOnTop() &&
194 discardPiles[6]->kingOnTop() &&
195 discardPiles[7]->kingOnTop() );;
196 }
197 virtual void mousePress(QPoint p);
198 virtual void mouseRelease(QPoint p) { Q_UNUSED(p); }
199// virtual void mouseMove(QPoint p);
200 virtual bool mousePressCard(Card *card, QPoint p);
201 virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); }
202// virtual void mouseMoveCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); }
203 bool canTurnOverDeck(void) { return (FALSE); }
204 void throughDeck(void) { }
205 bool snapOn;
206 void writeConfig( Config& cfg );
207 void readConfig( Config& cfg );
208 void resizePiles();
209private:
210 TeeclubWorkingPile *workingPiles[9];
211 TeeclubDiscardPile *discardPiles[8];
212 TeeclubFaceDownDeck *faceDownDealingPile;
213};
214
215
216#endif
217