From c90c389a8a8d9d8661e9772ec4144c5cf2039f23 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegames@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kpat/gypsy.cpp | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 kpat/gypsy.cpp (limited to 'kpat/gypsy.cpp') diff --git a/kpat/gypsy.cpp b/kpat/gypsy.cpp new file mode 100644 index 00000000..db58f7cd --- /dev/null +++ b/kpat/gypsy.cpp @@ -0,0 +1,117 @@ +#include "gypsy.h" +#include +#include "deck.h" +#include "cardmaps.h" + +Gypsy::Gypsy( KMainWindow* parent, const char *name ) + : Dealer( parent, name ) +{ + const int dist_x = cardMap::CARDX() * 11 / 10 + 1; + const int dist_y = cardMap::CARDY() * 11 / 10 + 1; + + deck = Deck::new_deck(this, 2); + deck->move(10 + dist_x / 2 + 8*dist_x, 10 + 45 * cardMap::CARDY() / 10); + + connect(deck, SIGNAL(clicked(Card*)), SLOT(slotClicked(Card *))); + + for (int i=0; i<8; i++) { + target[i] = new Pile(i+1, this); + target[i]->move(10+dist_x*(8+(i/4)), 10 + (i%4)*dist_y); + target[i]->setAddType(Pile::KlondikeTarget); + } + + for (int i=0; i<8; i++) { + store[i] = new Pile(9+i, this); + store[i]->move(10+dist_x*i, 10); + store[i]->setAddType(Pile::GypsyStore); + store[i]->setRemoveType(Pile::FreecellStore); + } + + setActions(Dealer::Hint | Dealer::Demo); +} + +void Gypsy::restart() { + deck->collectAndShuffle(); + deal(); +} + +void Gypsy::dealRow(bool faceup) { + for (int round=0; round < 8; round++) + store[round]->add(deck->nextCard(), !faceup, true); +} + +void Gypsy::deal() { + dealRow(false); + dealRow(false); + dealRow(true); + takeState(); +} + +Card *Gypsy::demoNewCards() +{ + if (deck->isEmpty()) + return 0; + dealRow(true); + return store[0]->top(); +} + +bool Gypsy::isGameLost() const { + if(!deck->isEmpty()) + return false; + + for(int i=0; i < 8; i++){ + if(store[i]->isEmpty()) + return false; + + if(store[i]->top()->rank() == Card::Ace) + return false; + + for(int j=0; j <8; j++){ + if(!target[j]->isEmpty() && + (store[i]->top()->suit()==target[j]->top()->suit()) && + (store[i]->top()->rank()==(target[j]->top()->rank()+1))) + return false; + } + } + + for(int i=0; i < 8; i++) { + Card *cnext=store[i]->top(); + int indexi=store[i]->indexOf(cnext); + + Card *cardi= 0; + do{ + cardi=cnext; + if (indexi>0) + cnext=store[i]->at( --indexi ); + + for(int k=0; k <8; k++) { + if (i == k) + continue; + + if((cardi->rank()+1 == store[k]->top()->rank()) && + cardi->isRed() != store[k]->top()->isRed()){ + + // this test doesn't apply if indexi==0, but fails gracefully. + if(cnext->rank() == store[k]->top()->rank() && + cnext->suit() == store[k]->top()->suit()) + break; //nothing gained; keep looking. + + return false;// TODO: look deeper, move may not be helpful. + } + } + + } while((indexi>=0) && (cardi->rank()+1 == cnext->rank()) && + (cardi->isRed() != cnext->isRed())); + } + + return true; +} + +static class LocalDealerInfo7 : public DealerInfo +{ +public: + LocalDealerInfo7() : DealerInfo(I18N_NOOP("Gy&psy"), 7) {} + virtual Dealer *createGame(KMainWindow *parent) { return new Gypsy(parent); } +} gyfdi; + +#include "gypsy.moc" -- cgit v1.2.1