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