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

harpcardgame.cpp

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 **********************************************************************/
00031 #include "harpcardgame.h"
00032 
00033 
00034 extern int highestZ;
00035 
00036 
00037 HarpCardGame::HarpCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent, 2)        // Use 2 Decks
00038 {
00039     highestZ = 0;
00040 
00041     for (int i = 0; i < 8; i++) {
00042         discardPiles[i] = new HarpDiscardPile( 27 + i * 26, 10, canvas() );
00043         addCardPile(discardPiles[i]);
00044     }
00045     for (int i = 0; i < 8; i++) {
00046         workingPiles[i] = new HarpWorkingPile( 27 + i * 26, 50, canvas() );
00047         addCardPile(workingPiles[i]);
00048     }
00049     faceDownDealingPile = new HarpFaceDownDeck( 2, 10, canvas() );
00050 }
00051 
00052 
00053 void HarpCardGame::deal(void)
00054 {
00055     highestZ = 1;
00056     int t = 0;
00057 
00058     beginDealing();
00059 
00060     for (int i = 0; i < 8; i++) {
00061         for (int k = 0; k < i+1; k++, t++) {
00062             Card *card = cards[t];
00063             workingPiles[i]->addCardToTop(card);
00064             card->setCardPile( workingPiles[i] );
00065             card->setPos( 0, 0, highestZ );
00066             card->setFace(k==i);
00067             card->move( workingPiles[i]->getCardPos( card ) );
00068             card->showCard();
00069             highestZ++;
00070         }
00071     }
00072     
00073     for ( ; t < getNumberOfCards(); t++) {
00074         Card *card = cards[t];
00075         faceDownDealingPile->addCardToTop(card);
00076         card->setCardPile( faceDownDealingPile );
00077         QPoint p = faceDownDealingPile->getCardPos( card );
00078         card->setPos( p.x(), p.y(), highestZ );
00079         card->showCard();
00080         highestZ++;
00081     }
00082 
00083     endDealing();
00084 }
00085 
00086 
00087 void HarpCardGame::readConfig( Config& cfg )
00088 {
00089     cfg.setGroup("GameState");
00090 
00091     // Create Cards, but don't shuffle or deal them yet
00092     createDeck();
00093 
00094     // Move the cards to their piles (deal them to their previous places)
00095     beginDealing();
00096 
00097     highestZ = 1;
00098 
00099     for (int i = 0; i < 8; i++) {
00100         QString pile;
00101         pile.sprintf( "HarpDiscardPile%i", i );
00102         readPile( cfg, discardPiles[i], pile, highestZ );
00103     }
00104 
00105     for (int i = 0; i < 8; i++) {
00106         QString pile;
00107         pile.sprintf( "HarpWorkingPile%i", i );
00108         readPile( cfg, workingPiles[i], pile, highestZ );
00109     }
00110 
00111     readPile( cfg, faceDownDealingPile, "HarpFaceDownDealingPile", highestZ );
00112 
00113     highestZ++;
00114 
00115     endDealing();
00116 }
00117 
00118 
00119 void HarpCardGame::writeConfig( Config& cfg )
00120 {
00121     cfg.setGroup("GameState");
00122     for ( int i = 0; i < 8; i++ ) {
00123         QString pile;
00124         pile.sprintf( "HarpDiscardPile%i", i );
00125         discardPiles[i]->writeConfig( cfg, pile );
00126     }
00127     for ( int i = 0; i < 8; i++ ) {
00128         QString pile;
00129         pile.sprintf( "HarpWorkingPile%i", i );
00130         workingPiles[i]->writeConfig( cfg, pile );
00131     }
00132     faceDownDealingPile->writeConfig( cfg, "HarpFaceDownDealingPile" );
00133 }
00134 
00135 
00136 bool HarpCardGame::mousePressCard( Card *card, QPoint p )
00137 {
00138     Q_UNUSED(p);
00139 
00140     CanvasCard *item = (CanvasCard *)card;
00141     if (item->isFacing() != TRUE) {
00142         // From facedown stack
00143         if ((item->x() == 2) && ((int)item->y() == 10)) {               // Deal a row of 8 cards
00144             // Move 8 cards, one to each workingPile
00145             beginDealing();
00146             for (int i=0; i<8 && faceDownDealingPile->cardOnTop(); i++) {
00147                 CanvasCard *card =  (CanvasCard *)faceDownDealingPile->cardOnTop(); 
00148                 card->setZ(highestZ);
00149                 highestZ++;
00150                 faceDownDealingPile->removeCard(card);
00151                 workingPiles[i]->addCardToTop(card);
00152                 card->setCardPile( workingPiles[i] );
00153                 card->setFace(FALSE);
00154                 QPoint p = workingPiles[i]->getCardPos(card);
00155                 card->flipTo( p.x(), p.y() );
00156             }
00157             endDealing();
00158         }
00159         moving = NULL;
00160         moved = FALSE;
00161 
00162         return TRUE;
00163     } else if ( !card->getCardPile()->isAllowedToBeMoved(card) ) {      // Don't allow unclean columns to be moved
00164         moving = NULL;
00165         return TRUE;
00166     }
00167 
00168     return FALSE;
00169 }
00170 
00171 
00172 
00173 void HarpCardGame::mousePress(QPoint p)
00174 {
00175     Q_UNUSED(p);
00176 }
00177 
00178 

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