summaryrefslogtreecommitdiff
path: root/noncore/games/solitaire/harpcardgame.cpp
Unidiff
Diffstat (limited to 'noncore/games/solitaire/harpcardgame.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/solitaire/harpcardgame.cpp171
1 files changed, 171 insertions, 0 deletions
diff --git a/noncore/games/solitaire/harpcardgame.cpp b/noncore/games/solitaire/harpcardgame.cpp
new file mode 100644
index 0000000..22715ec
--- a/dev/null
+++ b/noncore/games/solitaire/harpcardgame.cpp
@@ -0,0 +1,171 @@
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 "harpcardgame.h"
25
26
27extern int highestZ;
28
29
30 HarpCardGame::HarpCardGame(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 HarpDiscardPile( 27 + i * 26, 10, canvas() );
36 addCardPile(discardPiles[i]);
37 }
38 for (int i = 0; i < 8; i++) {
39 workingPiles[i] = new HarpWorkingPile( 27 + i * 26, 50, canvas() );
40 addCardPile(workingPiles[i]);
41 }
42 faceDownDealingPile = new HarpFaceDownDeck( 2, 10, canvas() );
43}
44
45
46void HarpCardGame::deal(void)
47{
48 highestZ = 1;
49 int t = 0;
50
51 beginDealing();
52
53 for (int i = 0; i < 8; i++) {
54 for (int k = 0; k < i+1; k++, t++) {
55 Card *card = cards[t];
56 workingPiles[i]->addCardToTop(card);
57 card->setCardPile( workingPiles[i] );
58 card->setPos( 0, 0, highestZ );
59 card->setFace(k==i);
60 card->move( workingPiles[i]->getCardPos( card ) );
61 card->showCard();
62 highestZ++;
63 }
64 }
65
66 for ( ; t < getNumberOfCards(); t++) {
67 Card *card = cards[t];
68 faceDownDealingPile->addCardToTop(card);
69 card->setCardPile( faceDownDealingPile );
70 QPoint p = faceDownDealingPile->getCardPos( card );
71 card->setPos( p.x(), p.y(), highestZ );
72 card->showCard();
73 highestZ++;
74 }
75
76 endDealing();
77}
78
79
80void HarpCardGame::readConfig( Config& cfg )
81{
82 cfg.setGroup("GameState");
83
84 // Create Cards, but don't shuffle or deal them yet
85 createDeck();
86
87 // Move the cards to their piles (deal them to their previous places)
88 beginDealing();
89
90 highestZ = 1;
91
92 for (int i = 0; i < 8; i++) {
93 QString pile;
94 pile.sprintf( "HarpDiscardPile%i", i );
95 readPile( cfg, discardPiles[i], pile, highestZ );
96 }
97
98 for (int i = 0; i < 8; i++) {
99 QString pile;
100 pile.sprintf( "HarpWorkingPile%i", i );
101 readPile( cfg, workingPiles[i], pile, highestZ );
102 }
103
104 readPile( cfg, faceDownDealingPile, "HarpFaceDownDealingPile", highestZ );
105
106 highestZ++;
107
108 endDealing();
109}
110
111
112void HarpCardGame::writeConfig( Config& cfg )
113{
114 cfg.setGroup("GameState");
115 for ( int i = 0; i < 8; i++ ) {
116 QString pile;
117 pile.sprintf( "HarpDiscardPile%i", i );
118 discardPiles[i]->writeConfig( cfg, pile );
119 }
120 for ( int i = 0; i < 8; i++ ) {
121 QString pile;
122 pile.sprintf( "HarpWorkingPile%i", i );
123 workingPiles[i]->writeConfig( cfg, pile );
124 }
125 faceDownDealingPile->writeConfig( cfg, "HarpFaceDownDealingPile" );
126}
127
128
129bool HarpCardGame::mousePressCard( Card *card, QPoint p )
130{
131 Q_UNUSED(p);
132
133 CanvasCard *item = (CanvasCard *)card;
134 if (item->isFacing() != TRUE) {
135 // From facedown stack
136 if ((item->x() == 2) && ((int)item->y() == 10)) { // Deal a row of 8 cards
137 // Move 8 cards, one to each workingPile
138 beginDealing();
139 for (int i=0; i<8 && faceDownDealingPile->cardOnTop(); i++) {
140 CanvasCard *card = (CanvasCard *)faceDownDealingPile->cardOnTop();
141 card->setZ(highestZ);
142 highestZ++;
143 faceDownDealingPile->removeCard(card);
144 workingPiles[i]->addCardToTop(card);
145 card->setCardPile( workingPiles[i] );
146 card->setFace(FALSE);
147 QPoint p = workingPiles[i]->getCardPos(card);
148 card->flipTo( p.x(), p.y() );
149 }
150 endDealing();
151 }
152 moving = NULL;
153 moved = FALSE;
154
155 return TRUE;
156 } else if ( !card->getCardPile()->isAllowedToBeMoved(card) ) {// Don't allow unclean columns to be moved
157 moving = NULL;
158 return TRUE;
159 }
160
161 return FALSE;
162}
163
164
165
166void HarpCardGame::mousePress(QPoint p)
167{
168 Q_UNUSED(p);
169}
170
171