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