-rw-r--r-- | noncore/games/solitaire/canvascardgame.cpp | 4 | ||||
-rw-r--r-- | noncore/games/solitaire/canvascardwindow.cpp | 28 | ||||
-rw-r--r-- | noncore/games/solitaire/canvascardwindow.h | 1 | ||||
-rw-r--r-- | noncore/games/solitaire/cardgamelayout.cpp | 2 | ||||
-rw-r--r-- | noncore/games/solitaire/cardpile.cpp | 3 | ||||
-rw-r--r-- | noncore/games/solitaire/cardpile.h | 14 | ||||
-rwxr-xr-x | noncore/games/solitaire/solitaire.pro | 35 | ||||
-rw-r--r-- | noncore/games/solitaire/teeclubcardgame.cpp | 194 | ||||
-rw-r--r-- | noncore/games/solitaire/teeclubcardgame.h | 217 |
9 files changed, 476 insertions, 22 deletions
diff --git a/noncore/games/solitaire/canvascardgame.cpp b/noncore/games/solitaire/canvascardgame.cpp index 357e798..4404b04 100644 --- a/noncore/games/solitaire/canvascardgame.cpp +++ b/noncore/games/solitaire/canvascardgame.cpp @@ -377,4 +377,4 @@ void CanvasCardGame::readPile( Config& cfg, CardPile *pile, QString name, int& h card->setFace(facing); - pile->addCardToTop(card); - card->setCardPile(pile); + card->setCardPile(pile); // cam: setCardPile muss vor addCardToTop passieren + pile->addCardToTop(card); // weil sonst absturz wg cardAddedToTop QPoint p = pile->getCardPos( card ); diff --git a/noncore/games/solitaire/canvascardwindow.cpp b/noncore/games/solitaire/canvascardwindow.cpp index e1c021e..450b4db 100644 --- a/noncore/games/solitaire/canvascardwindow.cpp +++ b/noncore/games/solitaire/canvascardwindow.cpp @@ -25,2 +25,3 @@ #include "harpcardgame.h" +#include "teeclubcardgame.h" @@ -65,2 +66,3 @@ CanvasCardWindow::CanvasCardWindow(QWidget* parent, const char* name, WFlags f) file->insertItem(tr("Harp"), this, SLOT(initHarp()), CTRL+Key_F); + file->insertItem(tr("Teeclub"), this, SLOT(initTeeclub()), CTRL+Key_F); menu->insertItem(tr("&Game"), file); @@ -89,2 +91,3 @@ CanvasCardWindow::CanvasCardWindow(QWidget* parent, const char* name, WFlags f) file->insertItem(tr("Harp"), this, SLOT(initHarp())); + file->insertItem(tr("Teeclub"), this, SLOT(initTeeclub())); menu->insertItem(tr("Play"), file); @@ -131,3 +134,2 @@ CanvasCardWindow::CanvasCardWindow(QWidget* parent, const char* name, WFlags f) setCentralWidget(cardGame); - //cardGame->newGame(); // Until we know how to handle reading freecell config cardGame->readConfig( cfg ); @@ -139,3 +141,9 @@ CanvasCardWindow::CanvasCardWindow(QWidget* parent, const char* name, WFlags f) setCentralWidget(cardGame); - //cardGame->newGame(); // Until we know how to handle reading freecell config + cardGame->readConfig( cfg ); + setCardBacks(); + } else if ( gameType == 4 ) { + cardGame = new TeeclubCardGame( &canvas, snapOn, this ); + cardGame->setNumberToDraw(1); + setCaption(tr("Teeclub")); + setCentralWidget(cardGame); cardGame->readConfig( cfg ); @@ -236,2 +244,18 @@ void CanvasCardWindow::initHarp() +void CanvasCardWindow::initTeeclub() +{ + // Create New Game + if ( cardGame ) { + delete cardGame; + } + cardGame = new TeeclubCardGame( &canvas, snapOn, this ); + cardGame->setNumberToDraw(1); + gameType = 4; + setCaption(tr("Teeclub")); + setCentralWidget(cardGame); + cardGame->newGame(); + setCardBacks(); +} + + void CanvasCardWindow::snapToggle() diff --git a/noncore/games/solitaire/canvascardwindow.h b/noncore/games/solitaire/canvascardwindow.h index aa76730..eddb184 100644 --- a/noncore/games/solitaire/canvascardwindow.h +++ b/noncore/games/solitaire/canvascardwindow.h @@ -49,2 +49,3 @@ private slots: void initHarp(); + void initTeeclub(); diff --git a/noncore/games/solitaire/cardgamelayout.cpp b/noncore/games/solitaire/cardgamelayout.cpp index e21d08a..1ceee8d 100644 --- a/noncore/games/solitaire/cardgamelayout.cpp +++ b/noncore/games/solitaire/cardgamelayout.cpp @@ -20,3 +20,3 @@ #include "cardgamelayout.h" -#include "card.h" + diff --git a/noncore/games/solitaire/cardpile.cpp b/noncore/games/solitaire/cardpile.cpp index 3b15e93..aace2e2 100644 --- a/noncore/games/solitaire/cardpile.cpp +++ b/noncore/games/solitaire/cardpile.cpp @@ -29,3 +29,3 @@ -CardPile::CardPile(int x, int y) : pileX(x), pileY(y), dealing(FALSE) { +CardPile::CardPile(int x, int y) : pileX(x), pileY(y), dealing(FALSE), PileResize(FALSE) { pileWidth = 0; @@ -37,2 +37,3 @@ CardPile::CardPile(int x, int y) : pileX(x), pileY(y), dealing(FALSE) { pileRadius = (pileWidth > pileHeight) ? pileWidth : pileHeight; + pileOffsetDown = 13; } diff --git a/noncore/games/solitaire/cardpile.h b/noncore/games/solitaire/cardpile.h index c515bbc..1eb2499 100644 --- a/noncore/games/solitaire/cardpile.h +++ b/noncore/games/solitaire/cardpile.h @@ -53,2 +53,9 @@ public: int getHeight() { return pileHeight; } + int getOffsetDown() { return pileOffsetDown; } + int getAnzCardsInPile() { + int anz=0; + Card *card = cardOnBottom(); + while (card != NULL) { anz++; card = cardInfront(card); } + return anz; + } @@ -60,2 +67,3 @@ public: void setHeight(int height) { pileHeight = height; } + void setOffsetDown(int down) { pileOffsetDown = down; } @@ -64,2 +72,6 @@ public: bool isDealing() { return dealing; } + + void beginPileResize() { PileResize = TRUE; } + void endPileResize() { PileResize = FALSE; } + bool isPileResize() { return PileResize; } @@ -94,4 +106,6 @@ protected: int pileRadius; + int pileOffsetDown; private: bool dealing; + bool PileResize; }; diff --git a/noncore/games/solitaire/solitaire.pro b/noncore/games/solitaire/solitaire.pro index b2ba5aa..d08dab0 100755 --- a/noncore/games/solitaire/solitaire.pro +++ b/noncore/games/solitaire/solitaire.pro @@ -1,2 +1,3 @@ TEMPLATE = app + CONFIG += qt warn_on release @@ -4,7 +5,8 @@ DESTDIR = $(OPIEDIR)/bin -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 +HEADERS = canvascard.h canvasshapes.h cardgame.h cardgamelayout.h cardpile.h card.h carddeck.h canvascardgame.h freecellcardgame.h chicanecardgame.h harpcardgame.h teeclubcardgame.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 +SOURCES = canvascard.cpp canvasshapes.cpp cardgame.cpp cardgamelayout.cpp cardpile.cpp card.cpp carddeck.cpp canvascardgame.cpp freecellcardgame.cpp chicanecardgame.cpp harpcardgame.cpp teeclubcardgame.cpp patiencecardgame.cpp canvascardwindow.cpp main.cpp TARGET = patience + INCLUDEPATH += $(OPIEDIR)/include @@ -12,17 +14,18 @@ DEPENDPATH += $(OPIEDIR)/include LIBS += -lqpe + REQUIRES = patience -TRANSLATIONS = ../../../i18n/de/patience.ts \ - ../../../i18n/en/patience.ts \ - ../../../i18n/es/patience.ts \ - ../../../i18n/fr/patience.ts \ - ../../../i18n/hu/patience.ts \ - ../../../i18n/ja/patience.ts \ - ../../../i18n/ko/patience.ts \ - ../../../i18n/no/patience.ts \ - ../../../i18n/pl/patience.ts \ - ../../../i18n/pt/patience.ts \ - ../../../i18n/pt_BR/patience.ts \ - ../../../i18n/sl/patience.ts \ - ../../../i18n/zh_CN/patience.ts \ - ../../../i18n/zh_TW/patience.ts +TRANSLATIONS = ../i18n/de/patience.ts +TRANSLATIONS += ../i18n/es/patience.ts +TRANSLATIONS += ../i18n/pt/patience.ts +TRANSLATIONS += ../i18n/pt_BR/patience.ts +TRANSLATIONS += ../i18n/en/patience.ts +TRANSLATIONS += ../i18n/hu/patience.ts +TRANSLATIONS += ../i18n/ja/patience.ts +TRANSLATIONS += ../i18n/sl/patience.ts +TRANSLATIONS += ../i18n/ko/patience.ts +TRANSLATIONS += ../i18n/pl/patience.ts +TRANSLATIONS += ../i18n/no/patience.ts +TRANSLATIONS += ../i18n/fr/patience.ts +TRANSLATIONS += ../i18n/zh_CN/patience.ts +TRANSLATIONS += ../i18n/zh_TW/patience.ts diff --git a/noncore/games/solitaire/teeclubcardgame.cpp b/noncore/games/solitaire/teeclubcardgame.cpp new file mode 100644 index 0000000..e15da96 --- a/dev/null +++ b/noncore/games/solitaire/teeclubcardgame.cpp @@ -0,0 +1,194 @@ +/********************************************************************** +** 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 "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 + 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; + } + + return FALSE; +} + + + +void TeeclubCardGame::mousePress(QPoint p) +{ + Q_UNUSED(p); +} + + diff --git a/noncore/games/solitaire/teeclubcardgame.h b/noncore/games/solitaire/teeclubcardgame.h new file mode 100644 index 0000000..06d49f8 --- a/dev/null +++ b/noncore/games/solitaire/teeclubcardgame.h @@ -0,0 +1,217 @@ +/********************************************************************** +** 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 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 + } +}; + + +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) && + ((int)card->getValue() + 1 == (int)cardOnTop()->getValue()) // bei teeclub sind die farben zum Anlegen egal + ) ) ) + 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! + 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 + 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! + 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 + 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 + |