Diffstat (limited to 'noncore/games/solitaire/freecellcardgame.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/solitaire/freecellcardgame.cpp | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/noncore/games/solitaire/freecellcardgame.cpp b/noncore/games/solitaire/freecellcardgame.cpp new file mode 100644 index 0000000..e82afd4 --- a/dev/null +++ b/noncore/games/solitaire/freecellcardgame.cpp | |||
@@ -0,0 +1,137 @@ | |||
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 | #include "freecellcardgame.h" | ||
21 | |||
22 | |||
23 | extern int highestZ; | ||
24 | int numberOfFreeCells = 4; | ||
25 | |||
26 | |||
27 | FreecellCardGame::FreecellCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent) | ||
28 | { | ||
29 | numberOfFreeCells = 4; | ||
30 | highestZ = 0; | ||
31 | |||
32 | for (int i = 0; i < 4; i++) { | ||
33 | freecellPiles[i] = new FreecellFreecellPile( 5 + i * 28, 10, canvas() ); | ||
34 | addCardPile(freecellPiles[i]); | ||
35 | } | ||
36 | for (int i = 0; i < 4; i++) { | ||
37 | discardPiles[i] = new FreecellDiscardPile( 125 + i * 28, 10, canvas() ); | ||
38 | addCardPile(discardPiles[i]); | ||
39 | } | ||
40 | for (int i = 0; i < 8; i++) { | ||
41 | workingPiles[i] = new FreecellWorkingPile( 10 + i * 28, 50, canvas() ); | ||
42 | addCardPile(workingPiles[i]); | ||
43 | } | ||
44 | } | ||
45 | |||
46 | |||
47 | void FreecellCardGame::deal(void) | ||
48 | { | ||
49 | highestZ = 1; | ||
50 | |||
51 | beginDealing(); | ||
52 | |||
53 | for (int i = 0; i < 52; i++) { | ||
54 | Card *card = cards[i]; | ||
55 | card->setFace( TRUE ); | ||
56 | card->setPos( 0, 0, highestZ ); | ||
57 | card->setCardPile( workingPiles[i%8] ); | ||
58 | workingPiles[i%8]->addCardToTop( card ); | ||
59 | card->move( workingPiles[i%8]->getCardPos( card ) ); | ||
60 | card->showCard(); | ||
61 | highestZ++; | ||
62 | } | ||
63 | |||
64 | endDealing(); | ||
65 | } | ||
66 | |||
67 | |||
68 | bool FreecellCardGame::mousePressCard( Card *c, QPoint p ) | ||
69 | { | ||
70 | Q_UNUSED(p); | ||
71 | |||
72 | if ( !c->getCardPile()->isAllowedToBeMoved(c) ) { | ||
73 | moving = NULL; | ||
74 | return TRUE; | ||
75 | } | ||
76 | |||
77 | return FALSE; | ||
78 | } | ||
79 | |||
80 | |||
81 | void FreecellCardGame::readConfig( Config& cfg ) | ||
82 | { | ||
83 | cfg.setGroup("GameState"); | ||
84 | |||
85 | // Create Cards, but don't shuffle or deal them yet | ||
86 | createDeck(); | ||
87 | |||
88 | // Move the cards to their piles (deal them to their previous places) | ||
89 | beginDealing(); | ||
90 | |||
91 | highestZ = 1; | ||
92 | |||
93 | for (int k = 0; k < 4; k++) { | ||
94 | QString pile; | ||
95 | pile.sprintf( "FreeCellPile%i", k ); | ||
96 | readPile( cfg, freecellPiles[k], pile, highestZ ); | ||
97 | } | ||
98 | |||
99 | for (int k = 0; k < 4; k++) { | ||
100 | QString pile; | ||
101 | pile.sprintf( "DiscardPile%i", k ); | ||
102 | readPile( cfg, discardPiles[k], pile, highestZ ); | ||
103 | } | ||
104 | |||
105 | for (int k = 0; k < 8; k++) { | ||
106 | QString pile; | ||
107 | pile.sprintf( "WorkingPile%i", k ); | ||
108 | readPile( cfg, workingPiles[k], pile, highestZ ); | ||
109 | } | ||
110 | |||
111 | highestZ++; | ||
112 | |||
113 | endDealing(); | ||
114 | } | ||
115 | |||
116 | |||
117 | void FreecellCardGame::writeConfig( Config& cfg ) | ||
118 | { | ||
119 | cfg.setGroup("GameState"); | ||
120 | for ( int i = 0; i < 4; i++ ) { | ||
121 | QString pile; | ||
122 | pile.sprintf( "FreeCellPile%i", i ); | ||
123 | freecellPiles[i]->writeConfig( cfg, pile ); | ||
124 | } | ||
125 | for ( int i = 0; i < 4; i++ ) { | ||
126 | QString pile; | ||
127 | pile.sprintf( "DiscardPile%i", i ); | ||
128 | discardPiles[i]->writeConfig( cfg, pile ); | ||
129 | } | ||
130 | for ( int i = 0; i < 8; i++ ) { | ||
131 | QString pile; | ||
132 | pile.sprintf( "WorkingPile%i", i ); | ||
133 | workingPiles[i]->writeConfig( cfg, pile ); | ||
134 | } | ||
135 | } | ||
136 | |||
137 | |||