author | tille <tille> | 2002-06-28 14:56:10 (UTC) |
---|---|---|
committer | tille <tille> | 2002-06-28 14:56:10 (UTC) |
commit | ab413257c3a23f535e99f8f61468382c73bc4adb (patch) (unidiff) | |
tree | 63834da1738157e52b67550d4e71058c6710f1ff /noncore/games/solitaire/harpcardgame.h | |
parent | d4626cc76127b7022c8555ea11afbb289714c851 (diff) | |
download | opie-ab413257c3a23f535e99f8f61468382c73bc4adb.zip opie-ab413257c3a23f535e99f8f61468382c73bc4adb.tar.gz opie-ab413257c3a23f535e99f8f61468382c73bc4adb.tar.bz2 |
cmader <chris@mediakreativwerk.de> impl. 2 new games
Diffstat (limited to 'noncore/games/solitaire/harpcardgame.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/solitaire/harpcardgame.h | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/noncore/games/solitaire/harpcardgame.h b/noncore/games/solitaire/harpcardgame.h new file mode 100644 index 0000000..d1733fd --- a/dev/null +++ b/noncore/games/solitaire/harpcardgame.h | |||
@@ -0,0 +1,165 @@ | |||
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 HARP_CARD_GAME_H | ||
21 | #define HARP_CARD_GAME_H | ||
22 | |||
23 | |||
24 | #include "patiencecardgame.h" | ||
25 | |||
26 | |||
27 | class HarpFaceDownDeck : public PatienceFaceDownDeck | ||
28 | { | ||
29 | public: | ||
30 | HarpFaceDownDeck(int x, int y, QCanvas *canvas) : | ||
31 | PatienceFaceDownDeck(x, y, canvas) { } | ||
32 | |||
33 | }; | ||
34 | |||
35 | |||
36 | class HarpDiscardPile : public PatienceDiscardPile | ||
37 | { | ||
38 | public: | ||
39 | HarpDiscardPile(int x, int y, QCanvas *canvas) : | ||
40 | PatienceDiscardPile(x, y, canvas) { } | ||
41 | |||
42 | }; | ||
43 | |||
44 | |||
45 | class HarpWorkingPile : public PatienceWorkingPile | ||
46 | { | ||
47 | public: | ||
48 | HarpWorkingPile(int x, int y, QCanvas *canvas) : | ||
49 | PatienceWorkingPile(x, y, canvas) { } | ||
50 | |||
51 | virtual bool isAllowedOnTop(Card *card) { | ||
52 | if ( card->isFacing() && | ||
53 | // ( ( ( cardOnTop() == NULL ) && (card->getValue() == king) ) || // diese Zeile sorgt dafür dass nur Kings auf leere Plätze dürfen | ||
54 | ( (cardOnTop() == NULL) || // auf einen Freiplatz darf alles! | ||
55 | ( (cardOnTop() != NULL) && | ||
56 | ((int)card->getValue() + 1 == (int)cardOnTop()->getValue()) && | ||
57 | (card->isRed() != cardOnTop()->isRed()) ) ) ) | ||
58 | return TRUE; | ||
59 | return FALSE; | ||
60 | } | ||
61 | virtual bool isAllowedToBeMoved(Card *card) { | ||
62 | if (!card->isFacing()) return FALSE; | ||
63 | |||
64 | int nextExpectedValue = (int)card->getValue(); | ||
65 | bool nextExpectedColor = card->isRed(); | ||
66 | |||
67 | while ((card != NULL)) { | ||
68 | if ( (int)card->getValue() != nextExpectedValue ) | ||
69 | return FALSE; | ||
70 | if ( card->isRed() != nextExpectedColor ) | ||
71 | return FALSE; | ||
72 | nextExpectedValue--;; | ||
73 | nextExpectedColor = !nextExpectedColor; | ||
74 | card = cardInfront(card); | ||
75 | } | ||
76 | return TRUE; | ||
77 | } | ||
78 | |||
79 | virtual void cardRemoved(Card *card) { | ||
80 | Q_UNUSED(card); | ||
81 | |||
82 | Card *newTopCard = cardOnTop(); | ||
83 | |||
84 | if ( !newTopCard ) { | ||
85 | top = QPoint( pileX, pileY ); | ||
86 | setNextX( pileX ); | ||
87 | setNextY( pileY ); | ||
88 | return; | ||
89 | } else { | ||
90 | top = getCardPos(NULL); | ||
91 | if ( newTopCard->isFacing() == FALSE ) { | ||
92 | int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13; | ||
93 | // correct the position taking in to account the card is not | ||
94 | // yet flipped, but will become flipped | ||
95 | top = QPoint( top.x(), top.y() - 3 ); // Keine Verschiebung! | ||
96 | newTopCard->flipTo( top.x(), top.y() ); | ||
97 | top = QPoint( top.x(), top.y() + offsetDown ); | ||
98 | } | ||
99 | setNextX( top.x() ); | ||
100 | setNextY( top.y() ); | ||
101 | } | ||
102 | } | ||
103 | virtual QPoint getCardPos(Card *c) { | ||
104 | int x = pileX, y = pileY; | ||
105 | Card *card = cardOnBottom(); | ||
106 | while ((card != c) && (card != NULL)) { | ||
107 | if (card->isFacing()) { | ||
108 | int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13; | ||
109 | y += offsetDown; | ||
110 | } else { | ||
111 | x += 0; // Keine Verschiebung! | ||
112 | y += 3; | ||
113 | } | ||
114 | card = cardInfront(card); | ||
115 | } | ||
116 | return QPoint( x, y ); | ||
117 | } | ||
118 | |||
119 | virtual QPoint getHypertheticalNextCardPos(void) { | ||
120 | // return top; | ||
121 | return QPoint( getNextX(), getNextY() ); | ||
122 | } | ||
123 | |||
124 | private: | ||
125 | QPoint top; | ||
126 | |||
127 | }; | ||
128 | |||
129 | |||
130 | class HarpCardGame : public CanvasCardGame | ||
131 | { | ||
132 | public: | ||
133 | HarpCardGame(QCanvas *c, bool snap, QWidget *parent = 0); | ||
134 | // virtual ~HarpCardGame(); | ||
135 | virtual void deal(void); | ||
136 | virtual bool haveWeWon() { | ||
137 | return ( discardPiles[0]->kingOnTop() && | ||
138 | discardPiles[1]->kingOnTop() && | ||
139 | discardPiles[2]->kingOnTop() && | ||
140 | discardPiles[3]->kingOnTop() && | ||
141 | discardPiles[4]->kingOnTop() && | ||
142 | discardPiles[5]->kingOnTop() && | ||
143 | discardPiles[6]->kingOnTop() && | ||
144 | discardPiles[7]->kingOnTop() );; | ||
145 | } | ||
146 | virtual void mousePress(QPoint p); | ||
147 | virtual void mouseRelease(QPoint p) { Q_UNUSED(p); } | ||
148 | // virtual void mouseMove(QPoint p); | ||
149 | virtual bool mousePressCard(Card *card, QPoint p); | ||
150 | virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); } | ||
151 | // virtual void mouseMoveCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); } | ||
152 | bool canTurnOverDeck(void) { return (FALSE); } | ||
153 | void throughDeck(void) { } | ||
154 | bool snapOn; | ||
155 | void writeConfig( Config& cfg ); | ||
156 | void readConfig( Config& cfg ); | ||
157 | private: | ||
158 | HarpWorkingPile *workingPiles[8]; | ||
159 | HarpDiscardPile *discardPiles[8]; | ||
160 | HarpFaceDownDeck *faceDownDealingPile; | ||
161 | }; | ||
162 | |||
163 | |||
164 | #endif | ||
165 | |||