Diffstat (limited to 'noncore/games/solitaire/teeclubcardgame.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/solitaire/teeclubcardgame.h | 217 |
1 files changed, 217 insertions, 0 deletions
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 | |||
27 | class TeeclubFaceDownDeck : public PatienceFaceDownDeck | ||
28 | { | ||
29 | public: | ||
30 | TeeclubFaceDownDeck(int x, int y, QCanvas *canvas) : | ||
31 | PatienceFaceDownDeck(x, y, canvas) { } | ||
32 | |||
33 | }; | ||
34 | |||
35 | |||
36 | class TeeclubDiscardPile : public CardPile, public CanvasRoundRect | ||
37 | { | ||
38 | public: | ||
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 | |||
57 | class TeeclubWorkingPile : public PatienceWorkingPile | ||
58 | { | ||
59 | public: | ||
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 | |||
175 | private: | ||
176 | QPoint top; | ||
177 | |||
178 | }; | ||
179 | |||
180 | |||
181 | class TeeclubCardGame : public CanvasCardGame | ||
182 | { | ||
183 | public: | ||
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(); | ||
209 | private: | ||
210 | TeeclubWorkingPile *workingPiles[9]; | ||
211 | TeeclubDiscardPile *discardPiles[8]; | ||
212 | TeeclubFaceDownDeck *faceDownDealingPile; | ||
213 | }; | ||
214 | |||
215 | |||
216 | #endif | ||
217 | |||