summaryrefslogtreecommitdiff
path: root/noncore/games/solitaire/freecellcardgame.h
Unidiff
Diffstat (limited to 'noncore/games/solitaire/freecellcardgame.h') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/solitaire/freecellcardgame.h152
1 files changed, 152 insertions, 0 deletions
diff --git a/noncore/games/solitaire/freecellcardgame.h b/noncore/games/solitaire/freecellcardgame.h
new file mode 100644
index 0000000..f1b09ab
--- a/dev/null
+++ b/noncore/games/solitaire/freecellcardgame.h
@@ -0,0 +1,152 @@
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 FREECELL_CARD_GAME_H
21#define FREECELL_CARD_GAME_H
22
23
24#include "patiencecardgame.h"
25
26
27extern int numberOfFreeCells;
28
29
30class FreecellDiscardPile : public PatienceDiscardPile
31{
32public:
33 FreecellDiscardPile(int x, int y, QCanvas *canvas) :
34 PatienceDiscardPile(x, y, canvas) { }
35
36};
37
38
39class FreecellWorkingPile : public PatienceWorkingPile
40{
41public:
42 FreecellWorkingPile(int x, int y, QCanvas *canvas) :
43 PatienceWorkingPile(x, y, canvas) { }
44
45 virtual bool isAllowedOnTop(Card *card) {
46 if ( cardOnBottom() == NULL ) {
47 int numberOfCardsBeingMoved = 0;
48 Card *tempCard = card;
49
50 while ((tempCard != NULL)) {
51 numberOfCardsBeingMoved++;
52 tempCard = cardInfront(tempCard);
53 }
54
55 if (numberOfCardsBeingMoved > numberOfFreeCells)
56 return FALSE;
57 }
58
59 if ( card->isFacing() &&
60 cardOnTop() == NULL )
61 return TRUE;
62 return PatienceWorkingPile::isAllowedOnTop( card );
63 }
64
65 virtual bool isAllowedToBeMoved(Card *card) {
66 int nextExpectedValue = (int)card->getValue();
67 bool nextExpectedColor = card->isRed();
68 int numberOfCardsBeingMoved = 0;
69
70 while ((card != NULL)) {
71 numberOfCardsBeingMoved++;
72 if ( (int)card->getValue() != nextExpectedValue )
73 return FALSE;
74 if ( card->isRed() != nextExpectedColor )
75 return FALSE;
76 nextExpectedValue--;;
77 nextExpectedColor = !nextExpectedColor;
78 card = cardInfront(card);
79 }
80
81 if (numberOfCardsBeingMoved <= (numberOfFreeCells + 1))
82 return TRUE;
83
84 return FALSE;
85 }
86 virtual void cardRemoved(Card *card) {
87 if ( !isDealing() && !cardOnTop() )
88 numberOfFreeCells++;
89 PatienceWorkingPile::cardRemoved( card );
90 }
91 virtual void cardAddedToTop(Card *card) {
92 if ( !isDealing() && cardOnBottom() == card )
93 numberOfFreeCells--;
94 PatienceWorkingPile::cardAddedToTop( card );
95 }
96};
97
98
99class FreecellFreecellPile : public CardPile, public CanvasRoundRect
100{
101public:
102 FreecellFreecellPile(int x, int y, QCanvas *canvas)
103 : CardPile(x, y), CanvasRoundRect(x, y, canvas) { }
104 virtual bool isAllowedOnTop(Card *card) {
105 if ( ( cardOnTop() == NULL ) && ( card->getCardPile()->cardInfront(card) == NULL ) )
106 return TRUE;
107 return FALSE;
108 }
109 virtual bool isAllowedToBeMoved(Card *card) {
110 Q_UNUSED(card);
111 return TRUE;
112 }
113 virtual void cardAddedToTop(Card *card) {
114 Q_UNUSED(card);
115 numberOfFreeCells--;
116 }
117 virtual void cardRemoved(Card *card) {
118 Q_UNUSED(card);
119 numberOfFreeCells++;
120 }
121};
122
123
124class FreecellCardGame : public CanvasCardGame
125{
126public:
127 FreecellCardGame(QCanvas *c, bool snap, QWidget *parent = 0);
128 virtual void deal(void);
129 virtual bool haveWeWon() {
130 return ( discardPiles[0]->kingOnTop() &&
131 discardPiles[1]->kingOnTop() &&
132 discardPiles[2]->kingOnTop() &&
133 discardPiles[3]->kingOnTop() );
134 }
135 virtual void mousePress(QPoint p) { Q_UNUSED(p); }
136 virtual void mouseRelease(QPoint p) { Q_UNUSED(p); }
137// virtual void mouseMove(QPoint p);
138 virtual bool mousePressCard(Card *card, QPoint p);
139 virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); }
140// virtual void mouseMoveCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); }
141 void readConfig( Config& cfg );
142 void writeConfig( Config& cfg );
143 bool snapOn;
144private:
145 FreecellFreecellPile *freecellPiles[8];
146 FreecellWorkingPile *workingPiles[8];
147 FreecellDiscardPile *discardPiles[4];
148};
149
150
151#endif
152