Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

teeclubcardgame.h

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **
00020 ** created on base of patiencecardgame by cam (C.A.Mader) 2002
00021 ** Rules for this game:
00022 **      use 2 decks = 104 cards
00023 **      deal 9 rows with 5 open cards each
00024 **      append one card to each other card which is one step higher
00025 **      move only columns of cards which are equal in suit
00026 **      each card can be layed on a free place
00027 **      deal 1 card at once on the first pile
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;                                                                   // the deads are sleeping forever
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 //           ( ( ( cardOnTop() == NULL ) && (card->getValue() == king) ) ||             // use this if only Kings are allowed on empty places
00077              ( (cardOnTop() == NULL) ||                                                 // each card can use an empty place 
00078                ( (cardOnTop() != NULL) &&
00079                  ((int)card->getValue() + 1 == (int)cardOnTop()->getValue())            // you can append every color on every color
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                 // correct the position taking in to account the card is not
00118                 // yet flipped, but will become flipped
00119                 top = QPoint( top.x(), top.y() - 3 );           // no moving to the side
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             // resize the pile
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;                                         // no moving to the side 
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             // resize the pile
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 //    virtual ~TeeclubCardGame();
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 //    virtual void mouseMove(QPoint p);
00211     virtual bool mousePressCard(Card *card, QPoint p);
00212     virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); }
00213 //    virtual void mouseMoveCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); }
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 

Generated on Sat Nov 5 16:17:27 2005 for OPIE by  doxygen 1.4.2