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

chicanecardgame.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 8 rows with 3 hidden cards and one open card
00024 **      append red to black and vice versa
00025 **      each card can be layed on a free place
00026 **      deal 8 cards at once
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 //           ( ( ( cardOnTop() == NULL ) && (card->getValue() == king) ) ||             // only kings are allowed on empty places
00063              ( (cardOnTop() == NULL) ||                                                 // each card can use an empty place
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                 // correct the position taking in to account the card is not
00103                 // yet flipped, but will become flipped
00104                 top = QPoint( top.x(), top.y() - 3 );           // no moving to the side
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;                                         // no moving to the side
00121                 y += 3;
00122             }
00123             card = cardInfront(card); 
00124         }
00125         return QPoint( x, y );
00126     }
00127 
00128     virtual QPoint getHypertheticalNextCardPos(void) {
00129 //        return top;
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 //    virtual ~ChicaneCardGame();
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 //    virtual void mouseMove(QPoint p);
00158     virtual bool mousePressCard(Card *card, QPoint p);
00159     virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); }
00160 //    virtual void mouseMoveCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); }
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 

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