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 "harpcardgame.h"
00032
00033
00034 extern int highestZ;
00035
00036
00037 HarpCardGame::HarpCardGame(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 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
00092 createDeck();
00093
00094
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
00143 if ((item->x() == 2) && ((int)item->y() == 10)) {
00144
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) ) {
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