00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef PATIENCE_CARD_GAME_H
00021 #define PATIENCE_CARD_GAME_H
00022
00023
00024 #include <qpopupmenu.h>
00025 #include <qmainwindow.h>
00026 #include <qintdict.h>
00027 #include <qcanvas.h>
00028 #include <qgfx_qws.h>
00029
00030
00031 #include "canvascardgame.h"
00032
00033
00034 class PatienceFaceDownDeck : public CardPile, public CanvasRoundRect
00035 {
00036 public:
00037 PatienceFaceDownDeck(int x, int y, QCanvas *canvas)
00038 : CardPile(x, y), CanvasRoundRect(x, y, canvas) { }
00039 virtual bool isAllowedOnTop(Card *card) {
00040 Q_UNUSED(card);
00041
00042 return TRUE;
00043 }
00044 virtual bool isAllowedToBeMoved(Card *card) {
00045 Q_UNUSED(card);
00046
00047 if ( card == cardOnTop() )
00048 return TRUE;
00049 return FALSE;
00050 }
00051 };
00052
00053
00054 class PatienceFaceUpDeck : public CardPile, public CanvasRoundRect
00055 {
00056 public:
00057 PatienceFaceUpDeck(int x, int y, QCanvas *canvas)
00058 : CardPile(x, y), CanvasRoundRect(x, y, canvas) { }
00059 virtual bool isAllowedOnTop(Card *card) {
00060 Q_UNUSED(card);
00061
00062 return TRUE;
00063 }
00064 virtual bool isAllowedToBeMoved(Card *card) {
00065 Q_UNUSED(card);
00066
00067 if ( card == cardOnTop() )
00068 return TRUE;
00069 return FALSE;
00070 }
00071 };
00072
00073
00074 class PatienceDiscardPile : public CardPile, public CanvasRoundRect
00075 {
00076 public:
00077 PatienceDiscardPile(int x, int y, QCanvas *canvas)
00078 : CardPile(x, y), CanvasRoundRect(x, y, canvas) { }
00079 virtual bool isAllowedOnTop(Card *card) {
00080 if ( card->isFacing() && ( card->getCardPile()->cardInfront(card) == NULL ) &&
00081 ( ( ( cardOnTop() == NULL ) && ( card->getValue() == ace ) ) ||
00082 ( ( cardOnTop() != NULL ) &&
00083 ( (int)card->getValue() == (int)cardOnTop()->getValue() + 1 ) &&
00084 ( card->getSuit() == cardOnTop()->getSuit() ) ) ) )
00085 return TRUE;
00086 return FALSE;
00087 }
00088 virtual bool isAllowedToBeMoved(Card *card) {
00089 if ( card->isFacing() && ( card == cardOnTop() ) )
00090 return TRUE;
00091 return FALSE;
00092 }
00093 };
00094
00095
00096 class PatienceWorkingPile : public CardPile, public CanvasRoundRect
00097 {
00098 public:
00099 PatienceWorkingPile(int x, int y, QCanvas *canvas)
00100 : CardPile(x, y), CanvasRoundRect(x, y, canvas), top(x, y) { }
00101 virtual bool isAllowedOnTop(Card *card) {
00102 if ( card->isFacing() &&
00103 ( ( ( cardOnTop() == NULL ) && (card->getValue() == king) ) ||
00104 ( ( cardOnTop() != NULL ) &&
00105 ( (int)card->getValue() + 1 == (int)cardOnTop()->getValue() ) &&
00106 ( card->isRed() != cardOnTop()->isRed() ) ) ) )
00107 return TRUE;
00108 return FALSE;
00109 }
00110 virtual bool isAllowedToBeMoved(Card *card) {
00111 if ( card->isFacing() )
00112 return TRUE;
00113 return FALSE;
00114 }
00115 virtual void cardAddedToTop(Card *card) {
00116 Q_UNUSED(card);
00117 top = getCardPos(NULL);
00118 setNextX( top.x() );
00119 setNextY( top.y() );
00120 }
00121 virtual void cardRemoved(Card *card) {
00122 Q_UNUSED(card);
00123
00124 Card *newTopCard = cardOnTop();
00125
00126 if ( !newTopCard ) {
00127 top = QPoint( pileX, pileY );
00128 setNextX( pileX );
00129 setNextY( pileY );
00130 return;
00131 } else {
00132 top = getCardPos(NULL);
00133 if ( newTopCard->isFacing() == FALSE ) {
00134 int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13;
00135
00136
00137 top = QPoint( top.x() - 1, top.y() - 3 );
00138 newTopCard->flipTo( top.x(), top.y() );
00139 top = QPoint( top.x(), top.y() + offsetDown );
00140 }
00141 setNextX( top.x() );
00142 setNextY( top.y() );
00143 }
00144 }
00145 virtual QPoint getCardPos(Card *c) {
00146 int x = pileX, y = pileY;
00147 Card *card = cardOnBottom();
00148 while ((card != c) && (card != NULL)) {
00149 if (card->isFacing()) {
00150 int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13;
00151 y += offsetDown;
00152 } else {
00153 x += 1;
00154 y += 3;
00155 }
00156 card = cardInfront(card);
00157 }
00158 return QPoint( x, y );
00159 }
00160 virtual QPoint getHypertheticalNextCardPos(void) {
00161 return top;
00162
00163 }
00164 private:
00165 QPoint top;
00166
00167 };
00168
00169
00170 class PatienceCardGame : public CanvasCardGame
00171 {
00172 public:
00173 PatienceCardGame(QCanvas *c, bool snap, QWidget *parent = 0);
00174 virtual ~PatienceCardGame();
00175 virtual void deal(void);
00176 int deckTurns;
00177 virtual bool haveWeWon() {
00178 return ( discardPiles[0]->kingOnTop() &&
00179 discardPiles[1]->kingOnTop() &&
00180 discardPiles[2]->kingOnTop() &&
00181 discardPiles[3]->kingOnTop() );;
00182 }
00183 virtual void mousePress(QPoint p);
00184 virtual void mouseRelease(QPoint p) { Q_UNUSED(p); }
00185
00186 virtual bool mousePressCard(Card *card, QPoint p);
00187 virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); }
00188
00189 bool canTurnOverDeck();
00190 void throughDeck();
00191 bool snapOn;
00192 virtual void writeConfig( Config& cfg );
00193 virtual void readConfig( Config& cfg );
00194 private:
00195 CanvasCircleOrCross *circleCross;
00196 CanvasRoundRect *rectangle;
00197 PatienceWorkingPile *workingPiles[7];
00198 PatienceDiscardPile *discardPiles[4];
00199 PatienceFaceDownDeck *faceDownDealingPile;
00200 PatienceFaceUpDeck *faceUpDealingPile;
00201 int numberOfTimesThroughDeck;
00202 };
00203
00204
00205 #endif
00206