00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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)
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
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
00114 createDeck();
00115
00116
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
00168 if ((item->x() == 2) && ((int)item->y() == 10)) {
00169
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) ) {
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