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

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

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