author | tille <tille> | 2002-07-10 13:05:07 (UTC) |
---|---|---|
committer | tille <tille> | 2002-07-10 13:05:07 (UTC) |
commit | 5d989e509abecf74aaa4eb88abf52a6821d19501 (patch) (side-by-side diff) | |
tree | 3e61348802a9ea05980e91e13344a45be509b7d1 | |
parent | 32954f729822e2d25f9e116400cbf2522a88ce42 (diff) | |
download | opie-5d989e509abecf74aaa4eb88abf52a6821d19501.zip opie-5d989e509abecf74aaa4eb88abf52a6821d19501.tar.gz opie-5d989e509abecf74aaa4eb88abf52a6821d19501.tar.bz2 |
cam implemented new game teeclub and pile resizing
-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 @@ -186,202 +186,202 @@ void CanvasCardGame::gameWon() { int y = 300 + rand() % 200; ((CanvasCard *)*it)->animatedMove( x, y, 50 ); } } } void CanvasCardGame::contentsMousePressEvent(QMouseEvent *e) { if ( moving ) return; QCanvasItemList l = canvas()->collisions( e->pos() ); for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) { if ( (*it)->rtti() == canvasCardId ) { moving = (CanvasCard *)*it; if ( moving->animated() ) return; cardXOff = (int)(e->pos().x() - moving->x()); cardYOff = (int)(e->pos().y() - moving->y()); if ( !mousePressCard( moving, e->pos() ) ) { CanvasCard *card = moving; if ( alphaCardPile ) delete alphaCardPile; alphaCardPile = new CanvasCardPile( this, canvas() ); alphaCardPile->move( card->x(), card->y() ); alphaCardPile->savePos(); alphaCardPile->show(); while (card) { alphaCardPile->addCard( card ); card->hide(); card = (CanvasCard *)card->getCardPile()->cardInfront(card); } alphaCardPile->setZ( INT_MAX ); moved = TRUE; } else { if ( alphaCardPile ) alphaCardPile->hide(); } return; } } mousePress( e->pos() ); } /* // // Should have some intelligent way to make double clicking on a // card send it to the most appropriate pile // void CanvasCardGame::contentsMouseDoubleClickEvent(QMouseEvent *e) { QCanvasItemList l = canvas()->collisions( e->pos() ); for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) { if ( (*it)->rtti() == canvasCardId ) { CanvasCard *card = (CanvasCard *)*it; if ( card->animated() ) return; if ( card->getCardPile()->isAllowedToBeMoved(card) ) { if (card->getCardPile()->cardInfront(card) == NULL) { CardPile *pile = first(); if (pile && pile->isAllowedOnTop(card)) { // move card to this pile return; } } } } } } */ void CanvasCardGame::contentsMouseMoveEvent(QMouseEvent *e) { QPoint p = e->pos(); if ( moving ) { moved = TRUE; if (moving->isFacing() != TRUE) return; 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); - 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 ); card->setPos( p.x(), p.y(), highestZ ); card->showCard(); highestZ++; } } 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 @@ -1,280 +1,304 @@ /********************************************************************** ** 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. ** **********************************************************************/ #include "canvascardwindow.h" #include "patiencecardgame.h" #include "freecellcardgame.h" #include "chicanecardgame.h" #include "harpcardgame.h" +#include "teeclubcardgame.h" #include <qpe/resource.h> #include <qmainwindow.h> #include <qpopupmenu.h> #include <qstyle.h> CanvasCardWindow::CanvasCardWindow(QWidget* parent, const char* name, WFlags f) : QMainWindow(parent, name, f), canvas(230, 260), snapOn(TRUE), cardBack(4), gameType(0), cardGame(NULL) { setIcon( Resource::loadPixmap( "cards" ) ); // Create Playing Area for Games if ( QPixmap::defaultDepth() < 12 ) { // canvas.setBackgroundColor(QColor(0x51, 0x74, 0x6B)); // canvas.setBackgroundColor(QColor(0x20, 0xb0, 0x50)); canvas.setBackgroundColor(QColor(0x08, 0x98, 0x2D)); } else { QPixmap bg; bg.convertFromImage( Resource::loadImage( "table_pattern" ), ThresholdDither ); canvas.setBackgroundPixmap(bg); } #if defined( QT_QWS_CASSIOPEIA ) canvas.setAdvancePeriod(70); #else canvas.setAdvancePeriod(30); #endif #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); + file->insertItem(tr("Teeclub"), this, SLOT(initTeeclub()), 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); menu->insertItem(tr("&Settings"),settings); menu->insertSeparator(); QPopupMenu* help = new QPopupMenu; help->insertItem(tr("&About"), this, SLOT(help()), Key_F1); 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())); + file->insertItem(tr("Teeclub"), this, SLOT(initTeeclub())); 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())); QString m; drawId = settings->insertItem(tr("Turn One Card"), this, SLOT(drawnToggle())); menu->insertItem(tr("Settings"),settings); #endif menu->show(); Config cfg( "Patience" ); cfg.setGroup( "GlobalSettings" ); snapOn = cfg.readBoolEntry( "SnapOn", TRUE); settings->setItemChecked(snap_id, snapOn); gameType = cfg.readNumEntry( "GameType", -1 ); drawThree = cfg.readBoolEntry( "DrawThree", TRUE); if ( gameType == 0 ) { cardGame = new PatienceCardGame( &canvas, snapOn, this ); cardGame->setNumberToDraw(drawThree ? 3 : 1); setCaption(tr("Patience")); setCentralWidget(cardGame); cardGame->readConfig( cfg ); 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 if ( gameType == 4 ) { + cardGame = new TeeclubCardGame( &canvas, snapOn, this ); + cardGame->setNumberToDraw(1); + setCaption(tr("Teeclub")); + setCentralWidget(cardGame); cardGame->readConfig( cfg ); setCardBacks(); } else { // Probably there isn't a config file or it is broken // Start a new game initPatience(); } updateDraw(); } CanvasCardWindow::~CanvasCardWindow() { if (cardGame) { Config cfg("Patience"); cfg.setGroup( "GlobalSettings" ); cfg.writeEntry( "GameType", gameType ); cfg.writeEntry( "SnapOn", snapOn ); cfg.writeEntry( "DrawThree", drawThree); cardGame->writeConfig( cfg ); delete cardGame; } } void CanvasCardWindow::resizeEvent(QResizeEvent *) { QSize s = centralWidget()->size(); int fw = style().defaultFrameWidth(); canvas.resize( s.width() - fw - 2, s.height() - fw - 2); } void CanvasCardWindow::initPatience() { // Create New Game if ( cardGame ) delete cardGame; cardGame = new PatienceCardGame( &canvas, snapOn, this ); cardGame->setNumberToDraw(drawThree ? 3 : 1); gameType = 0; setCaption(tr("Patience")); setCentralWidget(cardGame); cardGame->newGame(); setCardBacks(); updateDraw(); } void CanvasCardWindow::initFreecell() { // Create New Game if ( cardGame ) { delete cardGame; } cardGame = new FreecellCardGame( &canvas, snapOn, this ); 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::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() { snapOn = !snapOn; settings->setItemChecked(snap_id, snapOn); cardGame->toggleSnap(); } void CanvasCardWindow::drawnToggle() { cardGame->toggleCardsDrawn(); updateDraw(); } void CanvasCardWindow::updateDraw() { if(cardGame->cardsDrawn() == 3) settings->changeItem(drawId, tr("Turn One Card")); else settings->changeItem(drawId, tr("Turn Three Cards")); } void CanvasCardWindow::setCardBacks() { QCanvasItemList l = canvas.allItems(); for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) { if ( (*it)->rtti() == canvasCardId ) ((CanvasCard *)(*it))->setCardBack( cardBack ); } } void CanvasCardWindow::changeCardBacks() { cardBack++; if (cardBack == 5) cardBack = 0; setCardBacks(); } 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 @@ -1,72 +1,73 @@ /********************************************************************** ** 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 CANVAS_CARD_WINDOW_H #define CANVAS_CARD_WINDOW_H #include <qmainwindow.h> #include <qcanvas.h> class CanvasCardGame; class QPopupMenu; class CanvasCardWindow : public QMainWindow { Q_OBJECT public: CanvasCardWindow(QWidget* parent=0, const char* name=0, WFlags f=0); virtual ~CanvasCardWindow(); public slots: void setCardBacks(); void changeCardBacks(); void snapToggle(); void drawnToggle(); private slots: void initFreecell(); void initPatience(); void initChicane(); void initHarp(); + void initTeeclub(); protected: virtual void resizeEvent(QResizeEvent *e); void updateDraw(); private: QCanvas canvas; bool snapOn; bool drawThree; int drawId; int cardBack; int gameType; CanvasCardGame *cardGame; QPopupMenu* options; QPopupMenu* settings; int dbf_id; int snap_id; }; #endif 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 @@ -1,61 +1,61 @@ /********************************************************************** ** 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. ** **********************************************************************/ #include "cardgamelayout.h" -#include "card.h" + CardGameLayout::~CardGameLayout() { // Should I just do setAutoDelete( TRUE ); ? for (CardPile *p = first(); p != NULL; p = next()) delete p; } CardPile *CardGameLayout::closestPile(int x, int y, int maxDistance) { int closestDistance = maxDistance * maxDistance; CardPile *closestPile = NULL; for (CardPile *p = first(); p != NULL; p = next()) { int d = p->distanceFromNextPos(x, y); if (d < closestDistance) { closestDistance = d; closestPile = p; } } return closestPile; } void CardGameLayout::beginDealing() { for (CardPile *p = first(); p != NULL; p = next()) p->beginDealing(); } void CardGameLayout::endDealing() { for (CardPile *p = first(); p != NULL; p = next()) p->endDealing(); } 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 @@ -1,114 +1,115 @@ /********************************************************************** ** 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. ** **********************************************************************/ #include "cardpile.h" #include "card.h" #include <qpe/config.h> #include <qpoint.h> #include <qlist.h> -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; pileHeight = 0; pileNextX = pileX; pileNextY = pileY; pileCenterX = x + pileWidth / 2; pileCenterY = y + pileHeight / 2; pileRadius = (pileWidth > pileHeight) ? pileWidth : pileHeight; + pileOffsetDown = 13; } int CardPile::distanceFromPile(int x, int y) { return (pileCenterX-x)*(pileCenterX-x)+(pileCenterY-y)*(pileCenterY-y); } int CardPile::distanceFromNextPos(int x, int y) { return (pileNextX-x)*(pileNextX-x)+(pileNextY-y)*(pileNextY-y); } Card *CardPile::cardInfront(Card *c) { CardPile *p = c->getCardPile(); if (p) { p->at(p->find(c)); return p->next(); } else { return NULL; } } bool CardPile::kingOnTop() { Card *top = cardOnTop(); return top && top->getValue() == king; } bool CardPile::addCardToTop(Card *c) { if (dealing || isAllowedOnTop(c)) { append((const Card *)c); cardAddedToTop(c); return TRUE; } return FALSE; } bool CardPile::addCardToBottom(Card *c) { if (dealing || isAllowedOnBottom(c)) { prepend((const Card *)c); cardAddedToBottom(c); return TRUE; } return FALSE; } bool CardPile::removeCard(Card *c) { if (dealing || isAllowedToBeMoved(c)) { take(find(c)); cardRemoved(c); return TRUE; } return FALSE; } 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)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/cardpile.h b/noncore/games/solitaire/cardpile.h index c515bbc..1eb2499 100644 --- a/noncore/games/solitaire/cardpile.h +++ b/noncore/games/solitaire/cardpile.h @@ -1,101 +1,115 @@ /********************************************************************** ** 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 CARD_PILE_H #define CARD_PILE_H #include <qpoint.h> #include <qlist.h> enum ePileStackingType { pileCascades = 0, pileStacks, pileCascadesOrStacks }; enum ePileFaceingType { pileFaceUp = 0, pileFaceDown, pileFaceUpOrDown }; class Card; class Config; class CardPile : public QList<Card> { public: CardPile(int x, int y); virtual ~CardPile() { } int getX() { return pileX; } int getY() { return pileY; } int getNextX() { return pileNextX; } int getNextY() { return pileNextY; } int getWidth() { return pileWidth; } 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; + } void setX(int x) { pileX = x; } void setY(int y) { pileY = y; } void setNextX(int x) { pileNextX = x; } void setNextY(int y) { pileNextY = y; } void setWidth(int width) { pileWidth = width; } void setHeight(int height) { pileHeight = height; } + void setOffsetDown(int down) { pileOffsetDown = down; } void beginDealing() { dealing = TRUE; } void endDealing() { dealing = FALSE; } bool isDealing() { return dealing; } + void beginPileResize() { PileResize = TRUE; } + void endPileResize() { PileResize = FALSE; } + bool isPileResize() { return PileResize; } + int distanceFromPile(int x, int y); int distanceFromNextPos(int x, int y); Card *cardOnTop() { return getLast(); } Card *cardOnBottom() { return getFirst(); } Card *cardInfront(Card *c); bool kingOnTop(); bool addCardToTop(Card *c); bool addCardToBottom(Card *c); bool removeCard(Card *c); virtual void cardAddedToTop(Card *) { } virtual void cardAddedToBottom(Card *) { } virtual void cardRemoved(Card *) { } virtual bool isAllowedOnTop(Card *) { return FALSE; } virtual bool isAllowedOnBottom(Card *) { return FALSE; } virtual bool isAllowedToBeMoved(Card *) { return FALSE; } virtual QPoint getCardPos(Card *) { return QPoint(pileX, pileY); } virtual QPoint getHypertheticalNextCardPos() { return QPoint(pileX, pileY); } void writeConfig( Config& cfg, QString name ); protected: int pileX, pileY; int pileNextX, pileNextY; int pileWidth, pileHeight; int pileCenterX, pileCenterY; int pileRadius; + int pileOffsetDown; private: bool dealing; + bool PileResize; }; #endif 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,28 +1,31 @@ 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 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 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 + |