author | tille <tille> | 2002-06-28 14:56:10 (UTC) |
---|---|---|
committer | tille <tille> | 2002-06-28 14:56:10 (UTC) |
commit | ab413257c3a23f535e99f8f61468382c73bc4adb (patch) (side-by-side diff) | |
tree | 63834da1738157e52b67550d4e71058c6710f1ff | |
parent | d4626cc76127b7022c8555ea11afbb289714c851 (diff) | |
download | opie-ab413257c3a23f535e99f8f61468382c73bc4adb.zip opie-ab413257c3a23f535e99f8f61468382c73bc4adb.tar.gz opie-ab413257c3a23f535e99f8f61468382c73bc4adb.tar.bz2 |
cmader <chris@mediakreativwerk.de> impl. 2 new games
-rw-r--r-- | noncore/games/solitaire/canvascardgame.cpp | 4 | ||||
-rw-r--r-- | noncore/games/solitaire/canvascardgame.h | 3 | ||||
-rw-r--r-- | noncore/games/solitaire/canvascardwindow.cpp | 53 | ||||
-rw-r--r-- | noncore/games/solitaire/canvascardwindow.h | 2 | ||||
-rw-r--r-- | noncore/games/solitaire/card.h | 4 | ||||
-rw-r--r-- | noncore/games/solitaire/carddeck.cpp | 22 | ||||
-rw-r--r-- | noncore/games/solitaire/carddeck.h | 4 | ||||
-rw-r--r-- | noncore/games/solitaire/cardgame.h | 2 | ||||
-rw-r--r-- | noncore/games/solitaire/cardpile.cpp | 2 | ||||
-rw-r--r-- | noncore/games/solitaire/chicanecardgame.cpp | 171 | ||||
-rw-r--r-- | noncore/games/solitaire/chicanecardgame.h | 165 | ||||
-rw-r--r-- | noncore/games/solitaire/harpcardgame.cpp | 171 | ||||
-rw-r--r-- | noncore/games/solitaire/harpcardgame.h | 165 | ||||
-rw-r--r-- | noncore/games/solitaire/patiencecardgame.cpp | 6 | ||||
-rwxr-xr-x | noncore/games/solitaire/solitaire.pro | 7 |
15 files changed, 764 insertions, 17 deletions
diff --git a/noncore/games/solitaire/canvascardgame.cpp b/noncore/games/solitaire/canvascardgame.cpp index ef35287..357e798 100644 --- a/noncore/games/solitaire/canvascardgame.cpp +++ b/noncore/games/solitaire/canvascardgame.cpp @@ -361,22 +361,24 @@ void CanvasCardGame::contentsMouseReleaseEvent(QMouseEvent *e) } 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 = cards[ val ]; card->setFace(facing); pile->addCardToTop(card); card->setCardPile(pile); QPoint p = pile->getCardPos( card ); card->setPos( p.x(), p.y(), highestZ ); card->showCard(); highestZ++; } diff --git a/noncore/games/solitaire/canvascardgame.h b/noncore/games/solitaire/canvascardgame.h index 4d32014..0dfb85e 100644 --- a/noncore/games/solitaire/canvascardgame.h +++ b/noncore/games/solitaire/canvascardgame.h @@ -36,18 +36,19 @@ class CanvasCardPile; class CanvasCardGame : public QCanvasView, public CardGame { public: - CanvasCardGame(QCanvas &c, bool snap, QWidget *parent = 0, const char *name = 0, WFlags f = 0) : + CanvasCardGame(QCanvas &c, bool snap, QWidget *parent = 0, int numOfDecks = 1, const char *name = 0, WFlags f = 0) : QCanvasView( &c, parent, name, f ), + CardGame(0,numOfDecks), moved(FALSE), moving(NULL), alphaCardPile( NULL ), cardXOff(0), cardYOff(0), snapOn(snap), numberToDraw(1) { } virtual ~CanvasCardGame(); diff --git a/noncore/games/solitaire/canvascardwindow.cpp b/noncore/games/solitaire/canvascardwindow.cpp index 4c365a5..e1c021e 100644 --- a/noncore/games/solitaire/canvascardwindow.cpp +++ b/noncore/games/solitaire/canvascardwindow.cpp @@ -16,16 +16,18 @@ ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "canvascardwindow.h" #include "patiencecardgame.h" #include "freecellcardgame.h" +#include "chicanecardgame.h" +#include "harpcardgame.h" #include <qpe/resource.h> #include <qmainwindow.h> #include <qpopupmenu.h> #include <qstyle.h> @@ -54,16 +56,18 @@ CanvasCardWindow::CanvasCardWindow(QWidget* parent, const char* name, WFlags f) #ifdef _PATIENCE_USE_ACCELS_ QPEMenuBar* menu = menuBar(); QPopupMenu* file = new QPopupMenu; file->insertItem(tr("Patience"), this, SLOT(initPatience()), CTRL+Key_F); file->insertItem(tr("Freecell"), this, SLOT(initFreecell()), CTRL+Key_F); + file->insertItem(tr("Chicane"), this, SLOT(initChicane()), CTRL+Key_F); + file->insertItem(tr("Harp"), this, SLOT(initHarp()), CTRL+Key_F); menu->insertItem(tr("&Game"), file); menu->insertSeparator(); settings = new QPopupMenu; settings->insertItem(tr("&Change Card Backs"), this, SLOT(changeCardBacks()), Key_F2); snap_id = settings->insertItem(tr("&Snap To Position"), this, SLOT(snapToggle()), Key_F3); settings->setCheckable(TRUE); @@ -76,16 +80,18 @@ CanvasCardWindow::CanvasCardWindow(QWidget* parent, const char* name, WFlags f) help->setItemChecked(dbf_id, TRUE); menu->insertItem(tr("&Help"),help); #else QMenuBar* menu = menuBar(); QPopupMenu* file = new QPopupMenu; file->insertItem(tr("Patience"), this, SLOT(initPatience())); file->insertItem(tr("Freecell"), this, SLOT(initFreecell())); + file->insertItem(tr("Chicane"), this, SLOT(initChicane())); + file->insertItem(tr("Harp"), this, SLOT(initHarp())); menu->insertItem(tr("Play"), file); menu->insertSeparator(); settings = new QPopupMenu; settings->setCheckable(TRUE); settings->insertItem(tr("Change Card Backs"), this, SLOT(changeCardBacks())); snap_id = settings->insertItem(tr("Snap To Position"), this, SLOT(snapToggle())); @@ -113,16 +119,32 @@ CanvasCardWindow::CanvasCardWindow(QWidget* parent, const char* name, WFlags f) setCardBacks(); } else if ( gameType == 1 ) { cardGame = new FreecellCardGame( &canvas, snapOn, this ); setCaption(tr("Freecell")); setCentralWidget(cardGame); //cardGame->newGame(); // Until we know how to handle reading freecell config cardGame->readConfig( cfg ); setCardBacks(); + } else if ( gameType == 2 ) { + cardGame = new ChicaneCardGame( &canvas, snapOn, this ); + cardGame->setNumberToDraw(1); + setCaption(tr("Chicane")); + setCentralWidget(cardGame); + //cardGame->newGame(); // Until we know how to handle reading freecell config + cardGame->readConfig( cfg ); + setCardBacks(); + } else if ( gameType == 3 ) { + cardGame = new HarpCardGame( &canvas, snapOn, this ); + cardGame->setNumberToDraw(1); + setCaption(tr("Harp")); + setCentralWidget(cardGame); + //cardGame->newGame(); // Until we know how to handle reading freecell config + cardGame->readConfig( cfg ); + setCardBacks(); } else { // Probably there isn't a config file or it is broken // Start a new game initPatience(); } updateDraw(); } @@ -176,16 +198,47 @@ void CanvasCardWindow::initFreecell() gameType = 1; setCaption(tr("Freecell")); setCentralWidget(cardGame); cardGame->newGame(); setCardBacks(); } +void CanvasCardWindow::initChicane() +{ + // Create New Game + if ( cardGame ) { + delete cardGame; + } + cardGame = new ChicaneCardGame( &canvas, snapOn, this ); + cardGame->setNumberToDraw(1); + gameType = 2; + setCaption(tr("Chicane")); + setCentralWidget(cardGame); + cardGame->newGame(); + setCardBacks(); +} + +void CanvasCardWindow::initHarp() +{ + // Create New Game + if ( cardGame ) { + delete cardGame; + } + cardGame = new HarpCardGame( &canvas, snapOn, this ); + cardGame->setNumberToDraw(1); + gameType = 3; + setCaption(tr("Harp")); + setCentralWidget(cardGame); + cardGame->newGame(); + setCardBacks(); +} + + void CanvasCardWindow::snapToggle() { snapOn = !snapOn; settings->setItemChecked(snap_id, snapOn); cardGame->toggleSnap(); } diff --git a/noncore/games/solitaire/canvascardwindow.h b/noncore/games/solitaire/canvascardwindow.h index b75d40a..aa76730 100644 --- a/noncore/games/solitaire/canvascardwindow.h +++ b/noncore/games/solitaire/canvascardwindow.h @@ -40,16 +40,18 @@ public slots: void setCardBacks(); void changeCardBacks(); void snapToggle(); void drawnToggle(); private slots: void initFreecell(); void initPatience(); + void initChicane(); + void initHarp(); protected: virtual void resizeEvent(QResizeEvent *e); void updateDraw(); private: QCanvas canvas; bool snapOn; diff --git a/noncore/games/solitaire/card.h b/noncore/games/solitaire/card.h index eb30d30..68ce425 100644 --- a/noncore/games/solitaire/card.h +++ b/noncore/games/solitaire/card.h @@ -52,16 +52,19 @@ public: CardPile *getCardPile() { return cardPile; } void setFace(bool f) { faceUp = f; /* flip(); */ } bool isFacing() { return faceUp; } bool isShowing() { return showing; } bool isRed() { return ((suit == diamonds) || (suit == hearts)); } + int getDeckNumber() { return deckNumber; } + void setDeckNumber(int n) { deckNumber=n; } + int getX(void) { return ix; } int getY(void) { return iy; } int getZ(void) { return iz; } void flip(void) { flipTo(getX(), getY()); } virtual void setPos(int x, int y, int z) { ix = x; iy = y; iz = z; } virtual void move(int x, int y) { ix = x; iy = y; } virtual void move(QPoint p) { ix = p.x(); iy = p.y(); } @@ -70,15 +73,16 @@ public: virtual void hideCard(void) { showing = FALSE; } protected: virtual void redraw(void) { } private: eValue val; eSuit suit; bool faceUp; bool showing; + int deckNumber; int ix, iy, iz; CardPile *cardPile; }; #endif diff --git a/noncore/games/solitaire/carddeck.cpp b/noncore/games/solitaire/carddeck.cpp index 87c043a..a2d0076 100644 --- a/noncore/games/solitaire/carddeck.cpp +++ b/noncore/games/solitaire/carddeck.cpp @@ -18,37 +18,41 @@ ** **********************************************************************/ #include <stdlib.h> #include <time.h> #include "card.h" #include "carddeck.h" -CardDeck::CardDeck(int jokers) : numberOfJokers(jokers), deckCreated(FALSE) +CardDeck::CardDeck(int jokers, int numOfDecks) : numberOfJokers(jokers), numberOfDecks(numOfDecks), deckCreated(FALSE) { cards = new (Card *)[getNumberOfCards()]; } CardDeck::~CardDeck() { for (int i = 0; i < getNumberOfCards(); i++) delete cards[i]; delete cards; } void CardDeck::createDeck() { if (!deckCreated) { - for (int i = 0; i < 52; i++) - cards[i] = newCard( (eValue)((i % 13) + 1), (eSuit)((i / 13) + 1), FALSE ); + for (int j = 0; j < getNumberOfDecks(); j++) { + for (int i = 0; i < 52; i++) { + cards[i+j*52] = newCard( (eValue)((i % 13) + 1), (eSuit)((i / 13) + 1), FALSE); + cards[i+j*52]->setDeckNumber(j); + } + } for (int i = 0; i < getNumberOfJokers(); i++) - cards[52 + i] = newCard( jokerVal, jokerSuit, FALSE ); + cards[52*getNumberOfDecks() + i] = newCard( jokerVal, jokerSuit, FALSE); deckCreated = TRUE; } } void CardDeck::shuffle() { srand(time(NULL)); @@ -58,24 +62,30 @@ void CardDeck::shuffle() cards[i] = cards[index]; cards[index] = tmpCard; } } int CardDeck::getNumberOfCards() { - return 52 + getNumberOfJokers(); + return 52*getNumberOfDecks() + getNumberOfJokers(); } +int CardDeck::getNumberOfDecks() +{ + return numberOfDecks; +} + + int CardDeck::getNumberOfJokers() { return numberOfJokers; } -Card *CardDeck::newCard( eValue v, eSuit s, bool f ) +Card *CardDeck::newCard( eValue v, eSuit s, bool f) { return new Card(v, s, f); } diff --git a/noncore/games/solitaire/carddeck.h b/noncore/games/solitaire/carddeck.h index 9ad35a9..026834f 100644 --- a/noncore/games/solitaire/carddeck.h +++ b/noncore/games/solitaire/carddeck.h @@ -22,28 +22,30 @@ class Card; class CardDeck { public: - CardDeck(int jokers = 0); + CardDeck(int jokers = 0, int numOfDecks = 1); virtual ~CardDeck(); void createDeck(); void shuffle(); int getNumberOfCards(); + int getNumberOfDecks(); int getNumberOfJokers(); virtual Card *newCard( eValue v, eSuit s, bool f ); virtual void deal() { } Card **cards; private: int numberOfJokers; + int numberOfDecks; bool deckCreated; }; #endif diff --git a/noncore/games/solitaire/cardgame.h b/noncore/games/solitaire/cardgame.h index dd7efab..2e37c7f 100644 --- a/noncore/games/solitaire/cardgame.h +++ b/noncore/games/solitaire/cardgame.h @@ -26,17 +26,17 @@ #include "cardpile.h" #include "carddeck.h" #include "cardgamelayout.h" class CardGame : public CardGameLayout, public CardDeck { public: - CardGame(int numOfJokers = 0) : CardGameLayout(), CardDeck(numOfJokers) { } + CardGame(int numOfJokers = 0, int numOfDecks = 1) : CardGameLayout(), CardDeck(numOfJokers,numOfDecks) { } virtual ~CardGame() { } virtual void newGame(); virtual void mousePress(QPoint p) { Q_UNUSED(p); } virtual void mouseRelease(QPoint p) { Q_UNUSED(p); } virtual void mouseMove(QPoint p) { Q_UNUSED(p); } private: }; diff --git a/noncore/games/solitaire/cardpile.cpp b/noncore/games/solitaire/cardpile.cpp index 0b738d2..3b15e93 100644 --- a/noncore/games/solitaire/cardpile.cpp +++ b/noncore/games/solitaire/cardpile.cpp @@ -97,17 +97,17 @@ bool CardPile::removeCard(Card *c) { void CardPile::writeConfig( Config& cfg, QString name ) { int numberOfCards = 0; cfg.setGroup( name ); Card *card = cardOnBottom(); while ( card ) { QString cardStr; cardStr.sprintf( "%i", numberOfCards ); - int val = (int)card->getValue() - 1 + ( (int)card->getSuit() - 1 ) * 13; + int val = (int)card->getValue()-1 + ((int)card->getSuit()-1)*13 + (int)card->getDeckNumber()*52; cfg.writeEntry( "Card" + cardStr, val ); cfg.writeEntry( "CardFacing" + cardStr, card->isFacing() ); card = cardInfront( card ); numberOfCards++; } cfg.writeEntry("NumberOfCards", numberOfCards); } diff --git a/noncore/games/solitaire/chicanecardgame.cpp b/noncore/games/solitaire/chicanecardgame.cpp new file mode 100644 index 0000000..a242419 --- a/dev/null +++ b/noncore/games/solitaire/chicanecardgame.cpp @@ -0,0 +1,171 @@ +/********************************************************************** +** 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 +** +**********************************************************************/ +#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; + pile.sprintf( "ChicaneDiscardPile%i", i ); + discardPiles[i]->writeConfig( cfg, pile ); + } + for ( int i = 0; i < 8; i++ ) { + QString pile; + pile.sprintf( "ChicaneWorkingPile%i", i ); + workingPiles[i]->writeConfig( cfg, pile ); + } + faceDownDealingPile->writeConfig( cfg, "ChicaneFaceDownDealingPile" ); +} + + +bool ChicaneCardGame::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 a row of 8 cards + // Move 8 cards, one to each workingPile + beginDealing(); + for (int i=0; i<8 && faceDownDealingPile->cardOnTop(); i++) { + CanvasCard *card = (CanvasCard *)faceDownDealingPile->cardOnTop(); + card->setZ(highestZ); + highestZ++; + faceDownDealingPile->removeCard(card); + workingPiles[i]->addCardToTop(card); + card->setCardPile( workingPiles[i] ); + card->setFace(FALSE); + QPoint p = workingPiles[i]->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; + } + + return FALSE; +} + + + +void ChicaneCardGame::mousePress(QPoint p) +{ + Q_UNUSED(p); +} + + diff --git a/noncore/games/solitaire/chicanecardgame.h b/noncore/games/solitaire/chicanecardgame.h new file mode 100644 index 0000000..668f5f4 --- a/dev/null +++ b/noncore/games/solitaire/chicanecardgame.h @@ -0,0 +1,165 @@ +/********************************************************************** +** 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. +** +**********************************************************************/ +#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) && + ((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! + 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! + 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 new file mode 100644 index 0000000..22715ec --- a/dev/null +++ b/noncore/games/solitaire/harpcardgame.cpp @@ -0,0 +1,171 @@ +/********************************************************************** +** 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 +** +**********************************************************************/ +#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; + pile.sprintf( "HarpDiscardPile%i", i ); + discardPiles[i]->writeConfig( cfg, pile ); + } + for ( int i = 0; i < 8; i++ ) { + QString pile; + pile.sprintf( "HarpWorkingPile%i", i ); + workingPiles[i]->writeConfig( cfg, pile ); + } + faceDownDealingPile->writeConfig( cfg, "HarpFaceDownDealingPile" ); +} + + +bool HarpCardGame::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 a row of 8 cards + // Move 8 cards, one to each workingPile + beginDealing(); + for (int i=0; i<8 && faceDownDealingPile->cardOnTop(); i++) { + CanvasCard *card = (CanvasCard *)faceDownDealingPile->cardOnTop(); + card->setZ(highestZ); + highestZ++; + faceDownDealingPile->removeCard(card); + workingPiles[i]->addCardToTop(card); + card->setCardPile( workingPiles[i] ); + card->setFace(FALSE); + QPoint p = workingPiles[i]->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; + } + + return FALSE; +} + + + +void HarpCardGame::mousePress(QPoint p) +{ + Q_UNUSED(p); +} + + diff --git a/noncore/games/solitaire/harpcardgame.h b/noncore/games/solitaire/harpcardgame.h new file mode 100644 index 0000000..d1733fd --- a/dev/null +++ b/noncore/games/solitaire/harpcardgame.h @@ -0,0 +1,165 @@ +/********************************************************************** +** 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. +** +**********************************************************************/ +#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) && + ((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! + 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! + 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/patiencecardgame.cpp b/noncore/games/solitaire/patiencecardgame.cpp index fc91b26..1b38072 100644 --- a/noncore/games/solitaire/patiencecardgame.cpp +++ b/noncore/games/solitaire/patiencecardgame.cpp @@ -189,20 +189,18 @@ bool PatienceCardGame::mousePressCard( Card *card, QPoint p ) 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 { - // fix from cmader by tille - return false; - } + } 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 ) { diff --git a/noncore/games/solitaire/solitaire.pro b/noncore/games/solitaire/solitaire.pro index 01d87ed..b2ba5aa 100755 --- a/noncore/games/solitaire/solitaire.pro +++ b/noncore/games/solitaire/solitaire.pro @@ -1,13 +1,16 @@ TEMPLATE = app CONFIG += qt warn_on release DESTDIR = $(OPIEDIR)/bin -HEADERS = canvascard.h canvasshapes.h cardgame.h cardgamelayout.h cardpile.h card.h carddeck.h canvascardgame.h freecellcardgame.h patiencecardgame.h canvascardwindow.h -SOURCES = canvascard.cpp canvasshapes.cpp cardgame.cpp cardgamelayout.cpp cardpile.cpp card.cpp carddeck.cpp canvascardgame.cpp freecellcardgame.cpp patiencecardgame.cpp canvascardwindow.cpp main.cpp + +HEADERS = canvascard.h canvasshapes.h cardgame.h cardgamelayout.h cardpile.h card.h carddeck.h canvascardgame.h freecellcardgame.h chicanecardgame.h harpcardgame.h patiencecardgame.h canvascardwindow.h + +SOURCES = canvascard.cpp canvasshapes.cpp cardgame.cpp cardgamelayout.cpp cardpile.cpp card.cpp carddeck.cpp canvascardgame.cpp freecellcardgame.cpp chicanecardgame.cpp harpcardgame.cpp patiencecardgame.cpp canvascardwindow.cpp main.cpp + TARGET = patience INCLUDEPATH += $(OPIEDIR)/include DEPENDPATH += $(OPIEDIR)/include LIBS += -lqpe REQUIRES = patience TRANSLATIONS = ../../../i18n/de/patience.ts \ ../../../i18n/en/patience.ts \ |