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

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

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