Diffstat (limited to 'noncore/games/solitaire/patiencecardgame.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/solitaire/patiencecardgame.h | 206 |
1 files changed, 206 insertions, 0 deletions
diff --git a/noncore/games/solitaire/patiencecardgame.h b/noncore/games/solitaire/patiencecardgame.h new file mode 100644 index 0000000..c4f6c48 --- a/dev/null +++ b/noncore/games/solitaire/patiencecardgame.h | |||
@@ -0,0 +1,206 @@ | |||
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 PATIENCE_CARD_GAME_H | ||
21 | #define PATIENCE_CARD_GAME_H | ||
22 | |||
23 | |||
24 | #include <qpopupmenu.h> | ||
25 | #include <qmainwindow.h> | ||
26 | #include <qintdict.h> | ||
27 | #include <qcanvas.h> | ||
28 | // #include "canvascardshapes.h" | ||
29 | // #include "canvascard.h" | ||
30 | #include "canvascardgame.h" | ||
31 | |||
32 | |||
33 | class PatienceFaceDownDeck : public CardPile, public CanvasRoundRect | ||
34 | { | ||
35 | public: | ||
36 | PatienceFaceDownDeck(int x, int y, QCanvas *canvas) | ||
37 | : CardPile(x, y), CanvasRoundRect(x, y, canvas) { } | ||
38 | virtual bool isAllowedOnTop(Card *card) { | ||
39 | Q_UNUSED(card); | ||
40 | // Need to check it is from the faceUpDealingPile | ||
41 | return TRUE; | ||
42 | } | ||
43 | virtual bool isAllowedToBeMoved(Card *card) { | ||
44 | Q_UNUSED(card); | ||
45 | //if ( ( !card->isFacing() ) && ( card == cardOnTop() ) ) | ||
46 | if ( card == cardOnTop() ) | ||
47 | return TRUE; | ||
48 | return FALSE; | ||
49 | } | ||
50 | }; | ||
51 | |||
52 | |||
53 | class PatienceFaceUpDeck : public CardPile, public CanvasRoundRect | ||
54 | { | ||
55 | public: | ||
56 | PatienceFaceUpDeck(int x, int y, QCanvas *canvas) | ||
57 | : CardPile(x, y), CanvasRoundRect(x, y, canvas) { } | ||
58 | virtual bool isAllowedOnTop(Card *card) { | ||
59 | Q_UNUSED(card); | ||
60 | // Need to check it is from the faceDownDealingPile | ||
61 | return TRUE; | ||
62 | } | ||
63 | virtual bool isAllowedToBeMoved(Card *card) { | ||
64 | Q_UNUSED(card); | ||
65 | //if ( ( card->isFacing() ) && ( card == cardOnTop() ) ) | ||
66 | if ( card == cardOnTop() ) | ||
67 | return TRUE; | ||
68 | return FALSE; | ||
69 | } | ||
70 | }; | ||
71 | |||
72 | |||
73 | class PatienceDiscardPile : public CardPile, public CanvasRoundRect | ||
74 | { | ||
75 | public: | ||
76 | PatienceDiscardPile(int x, int y, QCanvas *canvas) | ||
77 | : CardPile(x, y), CanvasRoundRect(x, y, canvas) { } | ||
78 | virtual bool isAllowedOnTop(Card *card) { | ||
79 | if ( card->isFacing() && ( card->getCardPile()->cardInfront(card) == NULL ) && | ||
80 | ( ( ( cardOnTop() == NULL ) && ( card->getValue() == ace ) ) || | ||
81 | ( ( cardOnTop() != NULL ) && | ||
82 | ( (int)card->getValue() == (int)cardOnTop()->getValue() + 1 ) && | ||
83 | ( card->getSuit() == cardOnTop()->getSuit() ) ) ) ) | ||
84 | return TRUE; | ||
85 | return FALSE; | ||
86 | } | ||
87 | virtual bool isAllowedToBeMoved(Card *card) { | ||
88 | if ( card->isFacing() && ( card == cardOnTop() ) ) | ||
89 | return TRUE; | ||
90 | return FALSE; | ||
91 | } | ||
92 | }; | ||
93 | |||
94 | |||
95 | class PatienceWorkingPile : public CardPile, public CanvasRoundRect | ||
96 | { | ||
97 | public: | ||
98 | PatienceWorkingPile(int x, int y, QCanvas *canvas) | ||
99 | : CardPile(x, y), CanvasRoundRect(x, y, canvas), top(x, y) { } | ||
100 | virtual bool isAllowedOnTop(Card *card) { | ||
101 | if ( card->isFacing() && | ||
102 | ( ( ( cardOnTop() == NULL ) && (card->getValue() == king) ) || | ||
103 | ( ( cardOnTop() != NULL ) && | ||
104 | ( (int)card->getValue() + 1 == (int)cardOnTop()->getValue() ) && | ||
105 | ( card->isRed() != cardOnTop()->isRed() ) ) ) ) | ||
106 | return TRUE; | ||
107 | return FALSE; | ||
108 | } | ||
109 | virtual bool isAllowedToBeMoved(Card *card) { | ||
110 | if ( card->isFacing() ) | ||
111 | return TRUE; | ||
112 | return FALSE; | ||
113 | } | ||
114 | virtual void cardAddedToTop(Card *card) { | ||
115 | Q_UNUSED(card); | ||
116 | top = getCardPos(NULL); | ||
117 | setNextX( top.x() ); | ||
118 | setNextY( top.y() ); | ||
119 | } | ||
120 | virtual void cardRemoved(Card *card) { | ||
121 | Q_UNUSED(card); | ||
122 | |||
123 | Card *newTopCard = cardOnTop(); | ||
124 | |||
125 | if ( !newTopCard ) { | ||
126 | top = QPoint( pileX, pileY ); | ||
127 | setNextX( pileX ); | ||
128 | setNextY( pileY ); | ||
129 | return; | ||
130 | } else { | ||
131 | top = getCardPos(NULL); | ||
132 | if ( newTopCard->isFacing() == FALSE ) { | ||
133 | // correct the position taking in to account the card is not | ||
134 | // yet flipped, but will become flipped | ||
135 | top = QPoint( top.x() - 1, top.y() - 3 ); | ||
136 | newTopCard->flipTo( top.x(), top.y() ); | ||
137 | top = QPoint( top.x(), top.y() + 13 ); | ||
138 | } | ||
139 | setNextX( top.x() ); | ||
140 | setNextY( top.y() ); | ||
141 | } | ||
142 | } | ||
143 | virtual QPoint getCardPos(Card *c) { | ||
144 | int x = pileX, y = pileY; | ||
145 | Card *card = cardOnBottom(); | ||
146 | while ((card != c) && (card != NULL)) { | ||
147 | if (card->isFacing()) { | ||
148 | y += 13; | ||
149 | } else { | ||
150 | x += 1; | ||
151 | y += 3; | ||
152 | } | ||
153 | card = cardInfront(card); | ||
154 | } | ||
155 | return QPoint( x, y ); | ||
156 | } | ||
157 | virtual QPoint getHypertheticalNextCardPos(void) { | ||
158 | return top; | ||
159 | // return QPoint( getNextX(), getNextY() ); | ||
160 | } | ||
161 | private: | ||
162 | QPoint top; | ||
163 | |||
164 | }; | ||
165 | |||
166 | |||
167 | class PatienceCardGame : public CanvasCardGame | ||
168 | { | ||
169 | public: | ||
170 | PatienceCardGame(QCanvas *c, bool snap, QWidget *parent = 0); | ||
171 | virtual ~PatienceCardGame(); | ||
172 | virtual void deal(void); | ||
173 | virtual bool haveWeWon() { | ||
174 | return ( discardPiles[0]->kingOnTop() && | ||
175 | discardPiles[1]->kingOnTop() && | ||
176 | discardPiles[2]->kingOnTop() && | ||
177 | discardPiles[3]->kingOnTop() );; | ||
178 | } | ||
179 | virtual void mousePress(QPoint p); | ||
180 | virtual void mouseRelease(QPoint p) { Q_UNUSED(p); } | ||
181 | // virtual void mouseMove(QPoint p); | ||
182 | virtual bool mousePressCard(Card *card, QPoint p); | ||
183 | virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); } | ||
184 | // virtual void mouseMoveCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); } | ||
185 | bool canTurnOverDeck(void) { return (numberOfTimesThroughDeck != 3); } | ||
186 | void throughDeck(void) { | ||
187 | numberOfTimesThroughDeck++; | ||
188 | if (numberOfTimesThroughDeck == 3) | ||
189 | circleCross->setCross(); | ||
190 | } | ||
191 | bool snapOn; | ||
192 | virtual void writeConfig( Config& cfg ); | ||
193 | virtual void readConfig( Config& cfg ); | ||
194 | private: | ||
195 | CanvasCircleOrCross *circleCross; | ||
196 | CanvasRoundRect *rectangle; | ||
197 | PatienceWorkingPile *workingPiles[7]; | ||
198 | PatienceDiscardPile *discardPiles[4]; | ||
199 | PatienceFaceDownDeck *faceDownDealingPile; | ||
200 | PatienceFaceUpDeck *faceUpDealingPile; | ||
201 | int numberOfTimesThroughDeck; | ||
202 | }; | ||
203 | |||
204 | |||
205 | #endif | ||
206 | |||