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
00031 #ifndef TEECLUB_CARD_GAME_H
00032 #define TEECLUB_CARD_GAME_H
00033
00034
00035 #include "patiencecardgame.h"
00036
00037
00038 class TeeclubFaceDownDeck : public PatienceFaceDownDeck
00039 {
00040 public:
00041 TeeclubFaceDownDeck(int x, int y, QCanvas *canvas) :
00042 PatienceFaceDownDeck(x, y, canvas) { }
00043
00044 };
00045
00046
00047 class TeeclubDiscardPile : public CardPile, public CanvasRoundRect
00048 {
00049 public:
00050 TeeclubDiscardPile(int x, int y, QCanvas *canvas)
00051 : CardPile(x, y), CanvasRoundRect(x, y, canvas) { }
00052 virtual bool isAllowedOnTop(Card *card) {
00053 if ( card->isFacing() && ( card->getCardPile()->cardInfront(card) == NULL ) &&
00054 ( ( ( cardOnTop() == NULL ) && ( card->getValue() == ace ) ) ||
00055 ( ( cardOnTop() != NULL ) &&
00056 ( (int)card->getValue() == (int)cardOnTop()->getValue() + 1 ) &&
00057 ( card->getSuit() == cardOnTop()->getSuit() ) ) ) )
00058 return TRUE;
00059 return FALSE;
00060 }
00061 virtual bool isAllowedToBeMoved(Card *card) {
00062 if (card->isFacing()) return FALSE;
00063 return FALSE;
00064 }
00065 };
00066
00067
00068 class TeeclubWorkingPile : public PatienceWorkingPile
00069 {
00070 public:
00071 TeeclubWorkingPile(int x, int y, QCanvas *canvas) :
00072 PatienceWorkingPile(x, y, canvas) { }
00073
00074 virtual bool isAllowedOnTop(Card *card) {
00075 if ( card->isFacing() &&
00076
00077 ( (cardOnTop() == NULL) ||
00078 ( (cardOnTop() != NULL) &&
00079 ((int)card->getValue() + 1 == (int)cardOnTop()->getValue())
00080 ) ) )
00081 return TRUE;
00082 return FALSE;
00083 }
00084
00085 virtual bool isAllowedToBeMoved(Card *card) {
00086 if (!card->isFacing()) return FALSE;
00087
00088 int nextExpectedValue = (int)card->getValue();
00089 eSuit nextExpectedSuit = card->getSuit();
00090
00091 while ((card != NULL)) {
00092 if ( (int)card->getValue() != nextExpectedValue )
00093 return FALSE;
00094 if ( card->getSuit() != nextExpectedSuit )
00095 return FALSE;
00096 nextExpectedValue--;;
00097 card = cardInfront(card);
00098 }
00099 return TRUE;
00100 }
00101
00102 virtual void cardRemoved(Card *card) {
00103 Q_UNUSED(card);
00104
00105 Card *newTopCard = cardOnTop();
00106
00107 if ( !newTopCard ) {
00108 top = QPoint( pileX, pileY );
00109 setNextX( pileX );
00110 setNextY( pileY );
00111 setOffsetDown(13);
00112 return;
00113 } else {
00114 top = getCardPos(NULL);
00115 if ( newTopCard->isFacing() == FALSE ) {
00116 int offsetDown = newTopCard->getCardPile()->getOffsetDown();
00117
00118
00119 top = QPoint( top.x(), top.y() - 3 );
00120 newTopCard->flipTo( top.x(), top.y() );
00121 top = QPoint( top.x(), top.y() + offsetDown );
00122 }
00123 setNextX( top.x() );
00124 setNextY( top.y() );
00125 }
00126
00127 if ((getCardPos(NULL).y() < 230) && (getOffsetDown()<13)) {
00128
00129 beginDealing();
00130 setOffsetDown(getOffsetDown()+1);
00131 Card *card = cardOnBottom();
00132 int p=0;
00133 while (card != NULL) {
00134 card->setPos( 0, 0, p++ );
00135 card->move( getCardPos( card ) );
00136 card = cardInfront(card);
00137 }
00138 endDealing();
00139 }
00140 }
00141
00142 virtual QPoint getCardPos(Card *c) {
00143 int x = pileX, y = pileY;
00144 Card *card = cardOnBottom();
00145 while ((card != c) && (card != NULL)) {
00146 if (card->isFacing()) {
00147 int offsetDown = card->getCardPile()->getOffsetDown();
00148 y += offsetDown;
00149 } else {
00150 x += 0;
00151 y += 3;
00152 }
00153 card = cardInfront(card);
00154 }
00155 return QPoint( x, y );
00156 }
00157
00158 virtual QPoint getHypertheticalNextCardPos(void) {
00159 return QPoint( getNextX(), getNextY() );
00160 }
00161
00162 virtual void cardAddedToTop(Card *c) {
00163 Q_UNUSED(c);
00164 setNextX( getCardPos(NULL).x() );
00165 setNextY( getCardPos(NULL).y() );
00166
00167 while (isPileResize() && (getCardPos(NULL).y() > 230) && (getOffsetDown()>1)) {
00168
00169 beginDealing();
00170 setOffsetDown(getOffsetDown()-1);
00171 Card *card = cardOnBottom();
00172 int p=0;
00173 while (card != NULL) {
00174 card->setPos( 0, 0, p++ );
00175 card->move( getCardPos( card ) );
00176 card = cardInfront(card);
00177 }
00178 endDealing();
00179 }
00180
00181 }
00182
00183
00184
00185
00186 private:
00187 QPoint top;
00188
00189 };
00190
00191
00192 class TeeclubCardGame : public CanvasCardGame
00193 {
00194 public:
00195 TeeclubCardGame(QCanvas *c, bool snap, QWidget *parent = 0);
00196
00197 virtual void deal(void);
00198 virtual bool haveWeWon() {
00199 return ( discardPiles[0]->kingOnTop() &&
00200 discardPiles[1]->kingOnTop() &&
00201 discardPiles[2]->kingOnTop() &&
00202 discardPiles[3]->kingOnTop() &&
00203 discardPiles[4]->kingOnTop() &&
00204 discardPiles[5]->kingOnTop() &&
00205 discardPiles[6]->kingOnTop() &&
00206 discardPiles[7]->kingOnTop() );;
00207 }
00208 virtual void mousePress(QPoint p);
00209 virtual void mouseRelease(QPoint p) { Q_UNUSED(p); }
00210
00211 virtual bool mousePressCard(Card *card, QPoint p);
00212 virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); }
00213
00214 bool canTurnOverDeck(void) { return (FALSE); }
00215 void throughDeck(void) { }
00216 bool snapOn;
00217 void writeConfig( Config& cfg );
00218 void readConfig( Config& cfg );
00219 void resizePiles();
00220 private:
00221 TeeclubWorkingPile *workingPiles[9];
00222 TeeclubDiscardPile *discardPiles[8];
00223 TeeclubFaceDownDeck *faceDownDealingPile;
00224 };
00225
00226
00227 #endif
00228