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

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

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