-rw-r--r-- | noncore/games/solitaire/canvascardgame.cpp | 4 | ||||
-rw-r--r-- | noncore/games/solitaire/chicanecardgame.cpp | 8 | ||||
-rw-r--r-- | noncore/games/solitaire/chicanecardgame.h | 17 | ||||
-rw-r--r-- | noncore/games/solitaire/harpcardgame.cpp | 10 | ||||
-rw-r--r-- | noncore/games/solitaire/harpcardgame.h | 18 | ||||
-rw-r--r-- | noncore/games/solitaire/teeclubcardgame.cpp | 12 | ||||
-rw-r--r-- | noncore/games/solitaire/teeclubcardgame.h | 27 |
7 files changed, 74 insertions, 22 deletions
diff --git a/noncore/games/solitaire/canvascardgame.cpp b/noncore/games/solitaire/canvascardgame.cpp index 4404b04..8e07cc8 100644 --- a/noncore/games/solitaire/canvascardgame.cpp +++ b/noncore/games/solitaire/canvascardgame.cpp @@ -282,106 +282,106 @@ void CanvasCardGame::contentsMouseMoveEvent(QMouseEvent *e) { int tx = (int)p.x() - cardXOff; int ty = (int)p.y() - cardYOff; if (snapOn == TRUE) { CardPile *pile = closestPile( tx, ty, 50 ); if ( pile && pile->isAllowedOnTop( moving ) ) { QPoint p = pile->getHypertheticalNextCardPos(); if ( alphaCardPile ) alphaCardPile->move( p.x(), p.y() ); return; } } if ( alphaCardPile ) alphaCardPile->move( tx, ty ); } } void CanvasCardGame::contentsMouseReleaseEvent(QMouseEvent *e) { QPoint p = e->pos(); Q_UNUSED(p); if ( moving ) { CanvasCard *item = moving; if ( item->animated() ) return; if ( alphaCardPile ) if ( moved ) { CardPile *pile = closestPile((int)alphaCardPile->x(), (int)alphaCardPile->y(), 30); if (pile && pile->isAllowedOnTop(item)) { CardPile *oldPile = item->getCardPile(); Card *c = NULL; if ( oldPile != pile) { while ( item ) { item->show(); if ( oldPile ) { c = oldPile->cardInfront(item); oldPile->removeCard(item); } pile->addCardToTop(item); item->setCardPile(pile); //item->move( pile->getCardPos(item) ); QPoint p = pile->getCardPos(item); item->setPos( p.x(), p.y(), highestZ ); highestZ++; if (item->getValue() == king && haveWeWon()) { alphaCardPile->hide(); gameWon(); moving = NULL; return; } if (oldPile) { item = (CanvasCard *)c; } else { item = NULL; } } alphaCardPile->hide(); moving = NULL; return; } } alphaCardPile->animatedMove(); } } moved = FALSE; } void CanvasCardGame::readPile( Config& cfg, CardPile *pile, QString name, int& highestZ ) { cfg.setGroup( name ); int numberOfCards = cfg.readNumEntry("NumberOfCards", 0); Card *card = NULL; for ( int i = 0; i < numberOfCards; i++ ) { QString cardStr; cardStr.sprintf( "%i", i ); int val = cfg.readNumEntry( "Card" + cardStr ); bool facing = cfg.readBoolEntry( "CardFacing" + cardStr ); card = cards[ val ]; card->setFace(facing); - card->setCardPile(pile); // cam: setCardPile muss vor addCardToTop passieren - pile->addCardToTop(card); // weil sonst absturz wg cardAddedToTop + card->setCardPile(pile); // cam: setCardPile has to happen bevor addCardToTop + pile->addCardToTop(card); // due to a empty pointer if you use cardAddedToTop QPoint p = pile->getCardPos( card ); card->setPos( p.x(), p.y(), highestZ ); card->showCard(); highestZ++; } } diff --git a/noncore/games/solitaire/chicanecardgame.cpp b/noncore/games/solitaire/chicanecardgame.cpp index a242419..6729a94 100644 --- a/noncore/games/solitaire/chicanecardgame.cpp +++ b/noncore/games/solitaire/chicanecardgame.cpp @@ -1,116 +1,122 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** ** -** Modified by C.A.Mader 2002 +** created on base of patiencecardgame by cam (C.A.Mader) 2002 +** Rules for this game: +** use 2 decks = 104 cards +** deal 8 rows with 3 hidden cards and one open card +** append red to black and vice versa +** each card can be layed on a free place +** deal 8 cards at once ** **********************************************************************/ #include <qgfx_qws.h> #include "chicanecardgame.h" extern int highestZ; ChicaneCardGame::ChicaneCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent, 2) // Use 2 Decks { highestZ = 0; for (int i = 0; i < 8; i++) { discardPiles[i] = new ChicaneDiscardPile( 27 + i * 26, 10, canvas() ); addCardPile(discardPiles[i]); } for (int i = 0; i < 8; i++) { workingPiles[i] = new ChicaneWorkingPile( 27 + i * 26, 50, canvas() ); addCardPile(workingPiles[i]); } faceDownDealingPile = new ChicaneFaceDownDeck( 2, 10, canvas() ); } void ChicaneCardGame::deal(void) { highestZ = 1; int t = 0; beginDealing(); for (int i = 0; i < 8; i++) { for (int k = 0; k < 4; k++, t++) { Card *card = cards[t]; workingPiles[i]->addCardToTop(card); card->setCardPile( workingPiles[i] ); card->setPos( 0, 0, highestZ ); card->setFace(k==3); card->move( workingPiles[i]->getCardPos( card ) ); card->showCard(); highestZ++; } } for ( ; t < getNumberOfCards(); 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++; } endDealing(); } void ChicaneCardGame::readConfig( Config& cfg ) { cfg.setGroup("GameState"); // Create Cards, but don't shuffle or deal them yet createDeck(); // Move the cards to their piles (deal them to their previous places) beginDealing(); highestZ = 1; for (int i = 0; i < 8; i++) { QString pile; pile.sprintf( "ChicaneDiscardPile%i", i ); readPile( cfg, discardPiles[i], pile, highestZ ); } for (int i = 0; i < 8; i++) { QString pile; pile.sprintf( "ChicaneWorkingPile%i", i ); readPile( cfg, workingPiles[i], pile, highestZ ); } readPile( cfg, faceDownDealingPile, "ChicaneFaceDownDealingPile", highestZ ); highestZ++; endDealing(); } void ChicaneCardGame::writeConfig( Config& cfg ) { cfg.setGroup("GameState"); for ( int i = 0; i < 8; i++ ) { QString pile; diff --git a/noncore/games/solitaire/chicanecardgame.h b/noncore/games/solitaire/chicanecardgame.h index 668f5f4..f6bd08e 100644 --- a/noncore/games/solitaire/chicanecardgame.h +++ b/noncore/games/solitaire/chicanecardgame.h @@ -1,165 +1,174 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** +** +** created on base of patiencecardgame by cam (C.A.Mader) 2002 +** Rules for this game: +** use 2 decks = 104 cards +** deal 8 rows with 3 hidden cards and one open card +** append red to black and vice versa +** each card can be layed on a free place +** deal 8 cards at once +** **********************************************************************/ #ifndef CHICANE_CARD_GAME_H #define CHICANE_CARD_GAME_H #include "patiencecardgame.h" class ChicaneFaceDownDeck : public PatienceFaceDownDeck { public: ChicaneFaceDownDeck(int x, int y, QCanvas *canvas) : PatienceFaceDownDeck(x, y, canvas) { } }; class ChicaneDiscardPile : public PatienceDiscardPile { public: ChicaneDiscardPile(int x, int y, QCanvas *canvas) : PatienceDiscardPile(x, y, canvas) { } }; class ChicaneWorkingPile : public PatienceWorkingPile { public: ChicaneWorkingPile(int x, int y, QCanvas *canvas) : PatienceWorkingPile(x, y, canvas) { } virtual bool isAllowedOnTop(Card *card) { if ( card->isFacing() && -// ( ( ( cardOnTop() == NULL ) && (card->getValue() == king) ) || // diese Zeile sorgt dafür dass nur Kings auf leere Plätze dürfen - ( (cardOnTop() == NULL) || // auf einen Freiplatz darf alles! +// ( ( ( cardOnTop() == NULL ) && (card->getValue() == king) ) || // only kings are allowed on empty places + ( (cardOnTop() == NULL) || // each card can use an empty place ( (cardOnTop() != NULL) && ((int)card->getValue() + 1 == (int)cardOnTop()->getValue()) && (card->isRed() != cardOnTop()->isRed()) ) ) ) return TRUE; return FALSE; } virtual bool isAllowedToBeMoved(Card *card) { if (!card->isFacing()) return FALSE; int nextExpectedValue = (int)card->getValue(); bool nextExpectedColor = card->isRed(); while ((card != NULL)) { if ( (int)card->getValue() != nextExpectedValue ) return FALSE; if ( card->isRed() != nextExpectedColor ) return FALSE; nextExpectedValue--;; nextExpectedColor = !nextExpectedColor; card = cardInfront(card); } return TRUE; } virtual void cardRemoved(Card *card) { Q_UNUSED(card); Card *newTopCard = cardOnTop(); if ( !newTopCard ) { top = QPoint( pileX, pileY ); setNextX( pileX ); setNextY( pileY ); return; } else { top = getCardPos(NULL); if ( newTopCard->isFacing() == FALSE ) { int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13; // correct the position taking in to account the card is not // yet flipped, but will become flipped - top = QPoint( top.x(), top.y() - 3 ); // Keine Verschiebung! + top = QPoint( top.x(), top.y() - 3 ); // no moving to the side newTopCard->flipTo( top.x(), top.y() ); top = QPoint( top.x(), top.y() + offsetDown ); } setNextX( top.x() ); setNextY( top.y() ); } } virtual QPoint getCardPos(Card *c) { int x = pileX, y = pileY; Card *card = cardOnBottom(); while ((card != c) && (card != NULL)) { if (card->isFacing()) { int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13; y += offsetDown; } else { - x += 0; // Keine Verschiebung! + x += 0; // no moving to the side y += 3; } card = cardInfront(card); } return QPoint( x, y ); } virtual QPoint getHypertheticalNextCardPos(void) { // return top; return QPoint( getNextX(), getNextY() ); } private: QPoint top; }; class ChicaneCardGame : public CanvasCardGame { public: ChicaneCardGame(QCanvas *c, bool snap, QWidget *parent = 0); // virtual ~ChicaneCardGame(); virtual void deal(void); virtual bool haveWeWon() { return ( discardPiles[0]->kingOnTop() && discardPiles[1]->kingOnTop() && discardPiles[2]->kingOnTop() && discardPiles[3]->kingOnTop() && discardPiles[4]->kingOnTop() && discardPiles[5]->kingOnTop() && discardPiles[6]->kingOnTop() && discardPiles[7]->kingOnTop() );; } virtual void mousePress(QPoint p); virtual void mouseRelease(QPoint p) { Q_UNUSED(p); } // virtual void mouseMove(QPoint p); virtual bool mousePressCard(Card *card, QPoint p); virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); } // virtual void mouseMoveCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); } bool canTurnOverDeck(void) { return (FALSE); } void throughDeck(void) { } bool snapOn; void writeConfig( Config& cfg ); void readConfig( Config& cfg ); private: ChicaneWorkingPile *workingPiles[8]; ChicaneDiscardPile *discardPiles[8]; ChicaneFaceDownDeck *faceDownDealingPile; }; #endif diff --git a/noncore/games/solitaire/harpcardgame.cpp b/noncore/games/solitaire/harpcardgame.cpp index 22715ec..0711622 100644 --- a/noncore/games/solitaire/harpcardgame.cpp +++ b/noncore/games/solitaire/harpcardgame.cpp @@ -1,116 +1,124 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** ** -** Modified by C.A.Mader 2002 +** created on base of patiencecardgame by cam (C.A.Mader) 2002 +** Rules for this game: +** use 2 decks = 104 cards +** deal 8 rows with one open card in the first place +** one hidden and one open in the second place and so on +** append red to black and vice versa +** each card can be layed on a free place +** deal 8 cards at once +** ** **********************************************************************/ #include <qgfx_qws.h> #include "harpcardgame.h" extern int highestZ; HarpCardGame::HarpCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent, 2) // Use 2 Decks { highestZ = 0; for (int i = 0; i < 8; i++) { discardPiles[i] = new HarpDiscardPile( 27 + i * 26, 10, canvas() ); addCardPile(discardPiles[i]); } for (int i = 0; i < 8; i++) { workingPiles[i] = new HarpWorkingPile( 27 + i * 26, 50, canvas() ); addCardPile(workingPiles[i]); } faceDownDealingPile = new HarpFaceDownDeck( 2, 10, canvas() ); } void HarpCardGame::deal(void) { highestZ = 1; int t = 0; beginDealing(); for (int i = 0; i < 8; i++) { for (int k = 0; k < i+1; k++, t++) { Card *card = cards[t]; workingPiles[i]->addCardToTop(card); card->setCardPile( workingPiles[i] ); card->setPos( 0, 0, highestZ ); card->setFace(k==i); card->move( workingPiles[i]->getCardPos( card ) ); card->showCard(); highestZ++; } } for ( ; t < getNumberOfCards(); 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++; } endDealing(); } void HarpCardGame::readConfig( Config& cfg ) { cfg.setGroup("GameState"); // Create Cards, but don't shuffle or deal them yet createDeck(); // Move the cards to their piles (deal them to their previous places) beginDealing(); highestZ = 1; for (int i = 0; i < 8; i++) { QString pile; pile.sprintf( "HarpDiscardPile%i", i ); readPile( cfg, discardPiles[i], pile, highestZ ); } for (int i = 0; i < 8; i++) { QString pile; pile.sprintf( "HarpWorkingPile%i", i ); readPile( cfg, workingPiles[i], pile, highestZ ); } readPile( cfg, faceDownDealingPile, "HarpFaceDownDealingPile", highestZ ); highestZ++; endDealing(); } void HarpCardGame::writeConfig( Config& cfg ) { cfg.setGroup("GameState"); for ( int i = 0; i < 8; i++ ) { QString pile; diff --git a/noncore/games/solitaire/harpcardgame.h b/noncore/games/solitaire/harpcardgame.h index d1733fd..18b95e3 100644 --- a/noncore/games/solitaire/harpcardgame.h +++ b/noncore/games/solitaire/harpcardgame.h @@ -1,165 +1,175 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** +** +** created on base of patiencecardgame by cam (C.A.Mader) 2002 +** Rules for this game: +** use 2 decks = 104 cards +** deal 8 rows with one open card in the first place +** one hidden and one open in the second place and so on +** append red to black and vice versa +** each card can be layed on a free place +** deal 8 cards at once +** **********************************************************************/ #ifndef HARP_CARD_GAME_H #define HARP_CARD_GAME_H #include "patiencecardgame.h" class HarpFaceDownDeck : public PatienceFaceDownDeck { public: HarpFaceDownDeck(int x, int y, QCanvas *canvas) : PatienceFaceDownDeck(x, y, canvas) { } }; class HarpDiscardPile : public PatienceDiscardPile { public: HarpDiscardPile(int x, int y, QCanvas *canvas) : PatienceDiscardPile(x, y, canvas) { } }; class HarpWorkingPile : public PatienceWorkingPile { public: HarpWorkingPile(int x, int y, QCanvas *canvas) : PatienceWorkingPile(x, y, canvas) { } virtual bool isAllowedOnTop(Card *card) { if ( card->isFacing() && -// ( ( ( cardOnTop() == NULL ) && (card->getValue() == king) ) || // diese Zeile sorgt dafür dass nur Kings auf leere Plätze dürfen - ( (cardOnTop() == NULL) || // auf einen Freiplatz darf alles! +// ( ( ( cardOnTop() == NULL ) && (card->getValue() == king) ) || // only kings are allowed on empty places + ( (cardOnTop() == NULL) || // aeach card can use an emply place ( (cardOnTop() != NULL) && ((int)card->getValue() + 1 == (int)cardOnTop()->getValue()) && (card->isRed() != cardOnTop()->isRed()) ) ) ) return TRUE; return FALSE; } virtual bool isAllowedToBeMoved(Card *card) { if (!card->isFacing()) return FALSE; int nextExpectedValue = (int)card->getValue(); bool nextExpectedColor = card->isRed(); while ((card != NULL)) { if ( (int)card->getValue() != nextExpectedValue ) return FALSE; if ( card->isRed() != nextExpectedColor ) return FALSE; nextExpectedValue--;; nextExpectedColor = !nextExpectedColor; card = cardInfront(card); } return TRUE; } virtual void cardRemoved(Card *card) { Q_UNUSED(card); Card *newTopCard = cardOnTop(); if ( !newTopCard ) { top = QPoint( pileX, pileY ); setNextX( pileX ); setNextY( pileY ); return; } else { top = getCardPos(NULL); if ( newTopCard->isFacing() == FALSE ) { int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13; // correct the position taking in to account the card is not // yet flipped, but will become flipped - top = QPoint( top.x(), top.y() - 3 ); // Keine Verschiebung! + top = QPoint( top.x(), top.y() - 3 ); // no moving to the side newTopCard->flipTo( top.x(), top.y() ); top = QPoint( top.x(), top.y() + offsetDown ); } setNextX( top.x() ); setNextY( top.y() ); } } virtual QPoint getCardPos(Card *c) { int x = pileX, y = pileY; Card *card = cardOnBottom(); while ((card != c) && (card != NULL)) { if (card->isFacing()) { int offsetDown = ( qt_screen->deviceWidth() < 200 ) ? 9 : 13; y += offsetDown; } else { - x += 0; // Keine Verschiebung! + x += 0; // no moving to the side y += 3; } card = cardInfront(card); } return QPoint( x, y ); } virtual QPoint getHypertheticalNextCardPos(void) { // return top; return QPoint( getNextX(), getNextY() ); } private: QPoint top; }; class HarpCardGame : public CanvasCardGame { public: HarpCardGame(QCanvas *c, bool snap, QWidget *parent = 0); // virtual ~HarpCardGame(); virtual void deal(void); virtual bool haveWeWon() { return ( discardPiles[0]->kingOnTop() && discardPiles[1]->kingOnTop() && discardPiles[2]->kingOnTop() && discardPiles[3]->kingOnTop() && discardPiles[4]->kingOnTop() && discardPiles[5]->kingOnTop() && discardPiles[6]->kingOnTop() && discardPiles[7]->kingOnTop() );; } virtual void mousePress(QPoint p); virtual void mouseRelease(QPoint p) { Q_UNUSED(p); } // virtual void mouseMove(QPoint p); virtual bool mousePressCard(Card *card, QPoint p); virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); } // virtual void mouseMoveCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); } bool canTurnOverDeck(void) { return (FALSE); } void throughDeck(void) { } bool snapOn; void writeConfig( Config& cfg ); void readConfig( Config& cfg ); private: HarpWorkingPile *workingPiles[8]; HarpDiscardPile *discardPiles[8]; HarpFaceDownDeck *faceDownDealingPile; }; #endif diff --git a/noncore/games/solitaire/teeclubcardgame.cpp b/noncore/games/solitaire/teeclubcardgame.cpp index e15da96..0941e0d 100644 --- a/noncore/games/solitaire/teeclubcardgame.cpp +++ b/noncore/games/solitaire/teeclubcardgame.cpp @@ -1,183 +1,191 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** ** -** Modified by C.A.Mader 2002 +** created on base of patiencecardgame by cam (C.A.Mader) 2002 +** Rules for this game: +** use 2 decks = 104 cards +** deal 9 rows with 5 open cards each +** append one card to each other card which is one step higher +** move only columns of cards which are equal in suit +** each card can be layed on a free place +** deal 1 card at once on the first pile +** ** **********************************************************************/ #include <qgfx_qws.h> #include "teeclubcardgame.h" extern int highestZ; TeeclubCardGame::TeeclubCardGame(QCanvas *c, bool snap, QWidget *parent) : CanvasCardGame(*c, snap, parent, 2) // Use 2 Decks { highestZ = 0; for (int i = 0; i < 8; i++) { discardPiles[i] = new TeeclubDiscardPile( 27 + i * 26, 10, canvas() ); addCardPile(discardPiles[i]); } for (int i = 0; i < 9; i++) { workingPiles[i] = new TeeclubWorkingPile( 2 + i * 26, 50, canvas() ); addCardPile(workingPiles[i]); } faceDownDealingPile = new TeeclubFaceDownDeck( 2, 10, canvas() ); } void TeeclubCardGame::deal(void) { highestZ = 1; int t = 0; beginDealing(); for (int i = 0; i < 9; i++) { workingPiles[i]->setOffsetDown(13); workingPiles[i]->beginPileResize(); for (int k = 0; k < 5; k++, t++) { Card *card = cards[t]; workingPiles[i]->addCardToTop(card); card->setCardPile( workingPiles[i] ); card->setPos( 0, 0, highestZ ); card->setFace(TRUE); card->move( workingPiles[i]->getCardPos( card ) ); card->showCard(); highestZ++; } } for ( ; t < getNumberOfCards(); 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++; } endDealing(); } void TeeclubCardGame::resizePiles() { beginDealing(); for (int i = 0; i < 9; i++) { while ((workingPiles[i]->getCardPos(NULL).y() > 230) && (workingPiles[i]->getOffsetDown()>1)) { - // Resizen des Stapels + // resize the pile workingPiles[i]->setOffsetDown(workingPiles[i]->getOffsetDown()-1); Card *card = workingPiles[i]->cardOnBottom(); int p=0; while (card != NULL) { card->setPos( 0, 0, p++ ); card->move( workingPiles[i]->getCardPos( card ) ); card = workingPiles[i]->cardInfront(card); } } } endDealing(); } void TeeclubCardGame::readConfig( Config& cfg ) { cfg.setGroup("GameState"); // Create Cards, but don't shuffle or deal them yet createDeck(); // Move the cards to their piles (deal them to their previous places) beginDealing(); highestZ = 1; for (int i = 0; i < 8; i++) { QString pile; pile.sprintf( "TeeclubDiscardPile%i", i ); readPile( cfg, discardPiles[i], pile, highestZ ); } for (int i = 0; i < 9; i++) { workingPiles[i]->endPileResize(); QString pile; pile.sprintf( "TeeclubWorkingPile%i", i ); readPile( cfg, workingPiles[i], pile, highestZ ); workingPiles[i]->beginPileResize(); } readPile( cfg, faceDownDealingPile, "TeeclubFaceDownDealingPile", highestZ ); highestZ++; endDealing(); resizePiles(); } void TeeclubCardGame::writeConfig( Config& cfg ) { cfg.setGroup("GameState"); for ( int i = 0; i < 8; i++ ) { QString pile; pile.sprintf( "TeeclubDiscardPile%i", i ); discardPiles[i]->writeConfig( cfg, pile ); } for ( int i = 0; i < 9; i++ ) { QString pile; pile.sprintf( "TeeclubWorkingPile%i", i ); workingPiles[i]->writeConfig( cfg, pile ); } faceDownDealingPile->writeConfig( cfg, "TeeclubFaceDownDealingPile" ); } bool TeeclubCardGame::mousePressCard( Card *card, QPoint p ) { Q_UNUSED(p); CanvasCard *item = (CanvasCard *)card; if (item->isFacing() != TRUE) { // From facedown stack if ((item->x() == 2) && ((int)item->y() == 10)) { // Deal 1 card // Move 8 cards, one to each workingPile beginDealing(); CanvasCard *card = (CanvasCard *)faceDownDealingPile->cardOnTop(); card->setZ(highestZ); highestZ++; faceDownDealingPile->removeCard(card); workingPiles[0]->addCardToTop(card); card->setCardPile( workingPiles[0] ); card->setFace(FALSE); QPoint p = workingPiles[0]->getCardPos(card); card->flipTo( p.x(), p.y() ); endDealing(); } moving = NULL; moved = FALSE; return TRUE; } else if ( !card->getCardPile()->isAllowedToBeMoved(card) ) { // Don't allow unclean columns to be moved moving = NULL; return TRUE; } diff --git a/noncore/games/solitaire/teeclubcardgame.h b/noncore/games/solitaire/teeclubcardgame.h index 06d49f8..25cfaf9 100644 --- a/noncore/games/solitaire/teeclubcardgame.h +++ b/noncore/games/solitaire/teeclubcardgame.h @@ -1,217 +1,228 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** +** +** created on base of patiencecardgame by cam (C.A.Mader) 2002 +** Rules for this game: +** use 2 decks = 104 cards +** deal 9 rows with 5 open cards each +** append one card to each other card which is one step higher +** move only columns of cards which are equal in suit +** each card can be layed on a free place +** deal 1 card at once on the first pile +** +** **********************************************************************/ #ifndef TEECLUB_CARD_GAME_H #define TEECLUB_CARD_GAME_H #include "patiencecardgame.h" class TeeclubFaceDownDeck : public PatienceFaceDownDeck { public: TeeclubFaceDownDeck(int x, int y, QCanvas *canvas) : PatienceFaceDownDeck(x, y, canvas) { } }; class TeeclubDiscardPile : public CardPile, public CanvasRoundRect { public: TeeclubDiscardPile(int x, int y, QCanvas *canvas) : CardPile(x, y), CanvasRoundRect(x, y, canvas) { } virtual bool isAllowedOnTop(Card *card) { if ( card->isFacing() && ( card->getCardPile()->cardInfront(card) == NULL ) && ( ( ( cardOnTop() == NULL ) && ( card->getValue() == ace ) ) || ( ( cardOnTop() != NULL ) && ( (int)card->getValue() == (int)cardOnTop()->getValue() + 1 ) && ( card->getSuit() == cardOnTop()->getSuit() ) ) ) ) return TRUE; return FALSE; } virtual bool isAllowedToBeMoved(Card *card) { if (card->isFacing()) return FALSE; - return FALSE; // die Toten ruhn + return FALSE; // the deads are sleeping forever } }; class TeeclubWorkingPile : public PatienceWorkingPile { public: TeeclubWorkingPile(int x, int y, QCanvas *canvas) : PatienceWorkingPile(x, y, canvas) { } virtual bool isAllowedOnTop(Card *card) { if ( card->isFacing() && -// ( ( ( cardOnTop() == NULL ) && (card->getValue() == king) ) || // diese Zeile sorgt dafür dass nur Kings auf leere Plätze dürfen - ( (cardOnTop() == NULL) || // auf einen Freiplatz darf alles! +// ( ( ( cardOnTop() == NULL ) && (card->getValue() == king) ) || // use this if only Kings are allowed on empty places + ( (cardOnTop() == NULL) || // each card can use an empty place ( (cardOnTop() != NULL) && - ((int)card->getValue() + 1 == (int)cardOnTop()->getValue()) // bei teeclub sind die farben zum Anlegen egal + ((int)card->getValue() + 1 == (int)cardOnTop()->getValue()) // you can append every color on every color ) ) ) return TRUE; return FALSE; } virtual bool isAllowedToBeMoved(Card *card) { if (!card->isFacing()) return FALSE; int nextExpectedValue = (int)card->getValue(); eSuit nextExpectedSuit = card->getSuit(); while ((card != NULL)) { if ( (int)card->getValue() != nextExpectedValue ) return FALSE; if ( card->getSuit() != nextExpectedSuit ) return FALSE; nextExpectedValue--;; card = cardInfront(card); } return TRUE; } virtual void cardRemoved(Card *card) { Q_UNUSED(card); Card *newTopCard = cardOnTop(); if ( !newTopCard ) { top = QPoint( pileX, pileY ); setNextX( pileX ); setNextY( pileY ); setOffsetDown(13); return; } else { top = getCardPos(NULL); if ( newTopCard->isFacing() == FALSE ) { int offsetDown = newTopCard->getCardPile()->getOffsetDown(); // correct the position taking in to account the card is not // yet flipped, but will become flipped - top = QPoint( top.x(), top.y() - 3 ); // Keine seitliche Verschiebung! + top = QPoint( top.x(), top.y() - 3 ); // no moving to the side newTopCard->flipTo( top.x(), top.y() ); top = QPoint( top.x(), top.y() + offsetDown ); } setNextX( top.x() ); setNextY( top.y() ); } if ((getCardPos(NULL).y() < 230) && (getOffsetDown()<13)) { - // Resizen des Stapels + // resize the pile beginDealing(); setOffsetDown(getOffsetDown()+1); Card *card = cardOnBottom(); int p=0; while (card != NULL) { card->setPos( 0, 0, p++ ); card->move( getCardPos( card ) ); card = cardInfront(card); } endDealing(); } } virtual QPoint getCardPos(Card *c) { int x = pileX, y = pileY; Card *card = cardOnBottom(); while ((card != c) && (card != NULL)) { if (card->isFacing()) { int offsetDown = card->getCardPile()->getOffsetDown(); y += offsetDown; } else { - x += 0; // Keine seitliche Verschiebung! + x += 0; // no moving to the side y += 3; } card = cardInfront(card); } return QPoint( x, y ); } virtual QPoint getHypertheticalNextCardPos(void) { return QPoint( getNextX(), getNextY() ); } virtual void cardAddedToTop(Card *c) { Q_UNUSED(c); setNextX( getCardPos(NULL).x() ); setNextY( getCardPos(NULL).y() ); while (isPileResize() && (getCardPos(NULL).y() > 230) && (getOffsetDown()>1)) { - // Resizen des Stapels + // resize the pile beginDealing(); setOffsetDown(getOffsetDown()-1); Card *card = cardOnBottom(); int p=0; while (card != NULL) { card->setPos( 0, 0, p++ ); card->move( getCardPos( card ) ); card = cardInfront(card); } endDealing(); } } private: QPoint top; }; class TeeclubCardGame : public CanvasCardGame { public: TeeclubCardGame(QCanvas *c, bool snap, QWidget *parent = 0); // virtual ~TeeclubCardGame(); virtual void deal(void); virtual bool haveWeWon() { return ( discardPiles[0]->kingOnTop() && discardPiles[1]->kingOnTop() && discardPiles[2]->kingOnTop() && discardPiles[3]->kingOnTop() && discardPiles[4]->kingOnTop() && discardPiles[5]->kingOnTop() && discardPiles[6]->kingOnTop() && discardPiles[7]->kingOnTop() );; } virtual void mousePress(QPoint p); virtual void mouseRelease(QPoint p) { Q_UNUSED(p); } // virtual void mouseMove(QPoint p); virtual bool mousePressCard(Card *card, QPoint p); virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); } // virtual void mouseMoveCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); } bool canTurnOverDeck(void) { return (FALSE); } void throughDeck(void) { } bool snapOn; void writeConfig( Config& cfg ); void readConfig( Config& cfg ); void resizePiles(); private: TeeclubWorkingPile *workingPiles[9]; TeeclubDiscardPile *discardPiles[8]; TeeclubFaceDownDeck *faceDownDealingPile; }; #endif |