summaryrefslogtreecommitdiff
authorar <ar>2003-12-02 22:04:54 (UTC)
committer ar <ar>2003-12-02 22:04:54 (UTC)
commitcf060dacacf1889b50e6d07d1aa041c634bcb7d9 (patch) (side-by-side diff)
treee54423106c4fe51e515cb41e0c0dc934aebb5685
parentd5b6b246978ff34fb21b3306899c997528f8341c (diff)
downloadopie-cf060dacacf1889b50e6d07d1aa041c634bcb7d9.zip
opie-cf060dacacf1889b50e6d07d1aa041c634bcb7d9.tar.gz
opie-cf060dacacf1889b50e6d07d1aa041c634bcb7d9.tar.bz2
Close Bug 0000299
Redesign of Quellcode
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/solitaire/patiencecardgame.cpp294
1 files changed, 158 insertions, 136 deletions
diff --git a/noncore/games/solitaire/patiencecardgame.cpp b/noncore/games/solitaire/patiencecardgame.cpp
index 1b38072..96a599c 100644
--- a/noncore/games/solitaire/patiencecardgame.cpp
+++ b/noncore/games/solitaire/patiencecardgame.cpp
@@ -31,30 +31,37 @@ PatienceCardGame::PatienceCardGame(QCanvas *c, bool snap, QWidget *parent) : Can
- if ( qt_screen->deviceWidth() < 200 ) {
- circleCross = new CanvasCircleOrCross( 7, 16, canvas() );
- rectangle = new CanvasRoundRect( 30, 10, canvas() );
-
- for (int i = 0; i < 4; i++) {
- discardPiles[i] = new PatienceDiscardPile( 78 + i * 23, 10, canvas() );
- addCardPile(discardPiles[i]);
- }
- for (int i = 0; i < 7; i++) {
- workingPiles[i] = new PatienceWorkingPile( 5 + i * 23, 50, canvas() );
- addCardPile(workingPiles[i]);
- }
- faceDownDealingPile = new PatienceFaceDownDeck( 5, 10, canvas() );
- faceUpDealingPile = new PatienceFaceUpDeck( 30, 10, canvas() );
- } else {
- circleCross = new CanvasCircleOrCross( 7, 18, canvas() );
- rectangle = new CanvasRoundRect( 35, 10, canvas() );
-
- for (int i = 0; i < 4; i++) {
- discardPiles[i] = new PatienceDiscardPile( 110 + i * 30, 10, canvas() );
- addCardPile(discardPiles[i]);
- }
- for (int i = 0; i < 7; i++) {
- workingPiles[i] = new PatienceWorkingPile( 10 + i * 30, 50, canvas() );
- addCardPile(workingPiles[i]);
- }
- faceDownDealingPile = new PatienceFaceDownDeck( 5, 10, canvas() );
- faceUpDealingPile = new PatienceFaceUpDeck( 35, 10, canvas() );
+ if ( qt_screen->deviceWidth() < 200 )
+ {
+ circleCross = new CanvasCircleOrCross( 7, 16, canvas() );
+ rectangle = new CanvasRoundRect( 30, 10, canvas() );
+
+ for (int i = 0; i < 4; i++)
+ {
+ discardPiles[i] = new PatienceDiscardPile( 78 + i * 23, 10, canvas() );
+ addCardPile(discardPiles[i]);
+ }
+ for (int i = 0; i < 7; i++)
+ {
+ workingPiles[i] = new PatienceWorkingPile( 5 + i * 23, 50, canvas() );
+ addCardPile(workingPiles[i]);
+ }
+ faceDownDealingPile = new PatienceFaceDownDeck( 5, 10, canvas() );
+ faceUpDealingPile = new PatienceFaceUpDeck( 30, 10, canvas() );
+ }
+ else
+ {
+ circleCross = new CanvasCircleOrCross( 7, 18, canvas() );
+ rectangle = new CanvasRoundRect( 35, 10, canvas() );
+
+ for (int i = 0; i < 4; i++)
+ {
+ discardPiles[i] = new PatienceDiscardPile( 110 + i * 30, 10, canvas() );
+ addCardPile(discardPiles[i]);
+ }
+ for (int i = 0; i < 7; i++)
+ {
+ workingPiles[i] = new PatienceWorkingPile( 10 + i * 30, 50, canvas() );
+ addCardPile(workingPiles[i]);
+ }
+ faceDownDealingPile = new PatienceFaceDownDeck( 5, 10, canvas() );
+ faceUpDealingPile = new PatienceFaceUpDeck( 35, 10, canvas() );
}
@@ -79,23 +86,26 @@ void PatienceCardGame::deal(void)
- for (int i = 0; i < 7; i++) {
- cards[t]->setFace(TRUE);
- for (int k = i; k < 7; k++, t++) {
- Card *card = cards[t];
- workingPiles[k]->addCardToTop(card);
- card->setCardPile( workingPiles[k] );
- QPoint p = workingPiles[k]->getCardPos( card );
- card->setPos( p.x(), p.y(), highestZ );
- card->showCard();
- highestZ++;
- }
+ for (int i = 0; i < 7; i++)
+ {
+ cards[t]->setFace(TRUE);
+ for (int k = i; k < 7; k++, t++)
+ {
+ Card *card = cards[t];
+ workingPiles[k]->addCardToTop(card);
+ card->setCardPile( workingPiles[k] );
+ QPoint p = workingPiles[k]->getCardPos( card );
+ card->setPos( p.x(), p.y(), highestZ );
+ card->showCard();
+ highestZ++;
+ }
}
-
- for ( ; t < 52; t++) {
- Card *card = cards[t];
- faceDownDealingPile->addCardToTop(card);
- card->setCardPile( faceDownDealingPile );
- QPoint p = faceDownDealingPile->getCardPos( card );
- card->setPos( p.x(), p.y(), highestZ );
- card->showCard();
- highestZ++;
+
+ for ( ; t < 52; t++)
+ {
+ Card *card = cards[t];
+ faceDownDealingPile->addCardToTop(card);
+ card->setCardPile( faceDownDealingPile );
+ QPoint p = faceDownDealingPile->getCardPos( card );
+ card->setPos( p.x(), p.y(), highestZ );
+ card->showCard();
+ highestZ++;
}
@@ -111,6 +121,7 @@ void PatienceCardGame::readConfig( Config& cfg )
// Do we have a config file to read in?
- if ( !cfg.hasKey("numberOfTimesThroughDeck") ) {
- // if not, create a new game
- newGame();
- return;
+ if ( !cfg.hasKey("numberOfTimesThroughDeck") )
+ {
+ // if not, create a new game
+ newGame();
+ return;
}
@@ -122,3 +133,3 @@ void PatienceCardGame::readConfig( Config& cfg )
// How many times through the deck have we been
- numberOfTimesThroughDeck = cfg.readNumEntry("NumberOfTimesThroughDeck");
+ numberOfTimesThroughDeck = cfg.readNumEntry("numberOfTimesThroughDeck");
@@ -126,5 +137,5 @@ void PatienceCardGame::readConfig( Config& cfg )
if ( canTurnOverDeck() )
- circleCross->setCircle();
+ circleCross->setCircle();
else
- circleCross->setCross();
+ circleCross->setCross();
@@ -135,12 +146,14 @@ void PatienceCardGame::readConfig( Config& cfg )
- for (int k = 0; k < 7; k++) {
- QString pile;
- pile.sprintf( "WorkingPile%i", k );
- readPile( cfg, workingPiles[k], pile, highestZ );
+ for (int k = 0; k < 7; k++)
+ {
+ QString pile;
+ pile.sprintf( "WorkingPile%i", k );
+ readPile( cfg, workingPiles[k], pile, highestZ );
}
- for (int k = 0; k < 4; k++) {
- QString pile;
- pile.sprintf( "DiscardPile%i", k );
- readPile( cfg, discardPiles[k], pile, highestZ );
+ for (int k = 0; k < 4; k++)
+ {
+ QString pile;
+ pile.sprintf( "DiscardPile%i", k );
+ readPile( cfg, discardPiles[k], pile, highestZ );
}
@@ -161,11 +174,13 @@ void PatienceCardGame::writeConfig( Config& cfg )
- for ( int i = 0; i < 7; i++ ) {
- QString pile;
- pile.sprintf( "WorkingPile%i", i );
- workingPiles[i]->writeConfig( cfg, pile );
+ for ( int i = 0; i < 7; i++ )
+ {
+ QString pile;
+ pile.sprintf( "WorkingPile%i", i );
+ workingPiles[i]->writeConfig( cfg, pile );
}
- for ( int i = 0; i < 4; i++ ) {
- QString pile;
- pile.sprintf( "DiscardPile%i", i );
- discardPiles[i]->writeConfig( cfg, pile );
+ for ( int i = 0; i < 4; i++ )
+ {
+ QString pile;
+ pile.sprintf( "DiscardPile%i", i );
+ discardPiles[i]->writeConfig( cfg, pile );
}
@@ -181,47 +196,52 @@ bool PatienceCardGame::mousePressCard( Card *card, QPoint p )
CanvasCard *item = (CanvasCard *)card;
- if (item->isFacing() != TRUE) {
- // From facedown stack
- if ((item->x() == 5) && ((int)item->y() == 10)) {
- item->setZ(highestZ);
- highestZ++;
-
- // Added Code
- faceDownDealingPile->removeCard(item);
- faceUpDealingPile->addCardToTop(item);
- item->setCardPile( faceUpDealingPile );
-
- if ( qt_screen->deviceWidth() < 200 )
- item->flipTo( 30, (int)item->y() );
- else
- item->flipTo( 35, (int)item->y() );
- } else return FALSE; // <- was missing, caused facedown card to react
- // to clicking, which is wrong
- moving = NULL;
- moved = FALSE;
-
- // move two other cards if we flip three at a time
- int flipped = 1;
- QCanvasItemList l = canvas()->collisions( p );
- for (QCanvasItemList::Iterator it = l.begin(); (it != l.end()) && (flipped != cardsDrawn()); ++it) {
- if ( (*it)->rtti() == canvasCardId ) {
- CanvasCard *item = (CanvasCard *)*it;
- if (item->animated())
- continue;
- item->setZ(highestZ);
- highestZ++;
- flipped++;
-
- // Added Code
- faceDownDealingPile->removeCard(item);
- faceUpDealingPile->addCardToTop(item);
- item->setCardPile( faceUpDealingPile );
-
- if ( qt_screen->deviceWidth() < 200 )
- item->flipTo( 30, (int)item->y(), 8 * flipped );
- else
- item->flipTo( 35, (int)item->y(), 8 * flipped );
- }
- }
-
- return TRUE;
+ if (item->isFacing() != TRUE)
+ {
+ // From facedown stack
+ if ((item->x() == 5) && ((int)item->y() == 10))
+ {
+ item->setZ(highestZ);
+ highestZ++;
+
+ // Added Code
+ faceDownDealingPile->removeCard(item);
+ faceUpDealingPile->addCardToTop(item);
+ item->setCardPile( faceUpDealingPile );
+
+ if ( qt_screen->deviceWidth() < 200 )
+ item->flipTo( 30, (int)item->y() );
+ else
+ item->flipTo( 35, (int)item->y() );
+ }
+ else return FALSE; // <- was missing, caused facedown card to react
+ // to clicking, which is wrong
+ moving = NULL;
+ moved = FALSE;
+
+ // move two other cards if we flip three at a time
+ int flipped = 1;
+ QCanvasItemList l = canvas()->collisions( p );
+ for (QCanvasItemList::Iterator it = l.begin(); (it != l.end()) && (flipped != cardsDrawn()); ++it)
+ {
+ if ( (*it)->rtti() == canvasCardId )
+ {
+ CanvasCard *item = (CanvasCard *)*it;
+ if (item->animated())
+ continue;
+ item->setZ(highestZ);
+ highestZ++;
+ flipped++;
+
+ // Added Code
+ faceDownDealingPile->removeCard(item);
+ faceUpDealingPile->addCardToTop(item);
+ item->setCardPile( faceUpDealingPile );
+
+ if ( qt_screen->deviceWidth() < 200 )
+ item->flipTo( 30, (int)item->y(), 8 * flipped );
+ else
+ item->flipTo( 35, (int)item->y(), 8 * flipped );
+ }
+ }
+
+ return TRUE;
}
@@ -234,22 +254,24 @@ void PatienceCardGame::mousePress(QPoint p)
{
- if ( canTurnOverDeck() &&
- (p.x() > 5) && (p.x() < 28) &&
- (p.y() > 10) && (p.y() < 46) ) {
-
- beginDealing();
- Card *card = faceUpDealingPile->cardOnTop();
- while ( card ) {
- card->setPos( 5, 10, highestZ );
- card->setFace( FALSE );
- faceUpDealingPile->removeCard( card );
- faceDownDealingPile->addCardToTop( card );
- card->setCardPile( faceDownDealingPile );
- card = faceUpDealingPile->cardOnTop();
- highestZ++;
- }
- endDealing();
-
- throughDeck();
-
- moved = TRUE;
+ if ( canTurnOverDeck() &&
+ (p.x() > 5) && (p.x() < 28) &&
+ (p.y() > 10) && (p.y() < 46) )
+ {
+
+ beginDealing();
+ Card *card = faceUpDealingPile->cardOnTop();
+ while ( card )
+ {
+ card->setPos( 5, 10, highestZ );
+ card->setFace( FALSE );
+ faceUpDealingPile->removeCard( card );
+ faceDownDealingPile->addCardToTop( card );
+ card->setCardPile( faceDownDealingPile );
+ card = faceUpDealingPile->cardOnTop();
+ highestZ++;
+ }
+ endDealing();
+
+ throughDeck();
+
+ moved = TRUE;
}