summaryrefslogtreecommitdiff
authorharlekin <harlekin>2003-04-25 09:02:41 (UTC)
committer harlekin <harlekin>2003-04-25 09:02:41 (UTC)
commitbddc2d168776bf7674f9b938f8889051fb9fa7a8 (patch) (unidiff)
tree5b03d071f18e30e1b023c7bbd07c49346e1ef428
parent25ab69ab9964a8de1c05f9ff659a4b8a820eb201 (diff)
downloadopie-bddc2d168776bf7674f9b938f8889051fb9fa7a8.zip
opie-bddc2d168776bf7674f9b938f8889051fb9fa7a8.tar.gz
opie-bddc2d168776bf7674f9b938f8889051fb9fa7a8.tar.bz2
added patch for freecell mode by radofan, closes bug 736, i hope it helps
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/games/solitaire/canvascardgame.cpp3
-rw-r--r--noncore/games/solitaire/canvascardgame.h1
-rw-r--r--noncore/games/solitaire/freecellcardgame.cpp83
-rw-r--r--noncore/games/solitaire/freecellcardgame.h3
4 files changed, 89 insertions, 1 deletions
diff --git a/noncore/games/solitaire/canvascardgame.cpp b/noncore/games/solitaire/canvascardgame.cpp
index 8e07cc8..8250193 100644
--- a/noncore/games/solitaire/canvascardgame.cpp
+++ b/noncore/games/solitaire/canvascardgame.cpp
@@ -324,18 +324,19 @@ void CanvasCardGame::contentsMouseReleaseEvent(QMouseEvent *e)
324 while ( item ) { 324 while ( item ) {
325 item->show(); 325 item->show();
326 if ( oldPile ) { 326 if ( oldPile ) {
327 c = oldPile->cardInfront(item); 327 c = oldPile->cardInfront(item);
328 oldPile->removeCard(item); 328 oldPile->removeCard(item);
329 } 329 }
330 pile->addCardToTop(item);
331 item->setCardPile(pile); 330 item->setCardPile(pile);
332 //item->move( pile->getCardPos(item) ); 331 //item->move( pile->getCardPos(item) );
332 pile->addCardToTop(item);
333 QPoint p = pile->getCardPos(item); 333 QPoint p = pile->getCardPos(item);
334 item->setPos( p.x(), p.y(), highestZ ); 334 item->setPos( p.x(), p.y(), highestZ );
335 highestZ++; 335 highestZ++;
336 checkUnusable(); // added for freecell to move card to discard pile
336 337
337 if (item->getValue() == king && haveWeWon()) { 338 if (item->getValue() == king && haveWeWon()) {
338 alphaCardPile->hide(); 339 alphaCardPile->hide();
339 gameWon(); 340 gameWon();
340 moving = NULL; 341 moving = NULL;
341 return; 342 return;
diff --git a/noncore/games/solitaire/canvascardgame.h b/noncore/games/solitaire/canvascardgame.h
index 0dfb85e..d159de6 100644
--- a/noncore/games/solitaire/canvascardgame.h
+++ b/noncore/games/solitaire/canvascardgame.h
@@ -75,12 +75,13 @@ public:
75 void readPile( Config& cfg, CardPile *pile, QString name, int& highestZ ); 75 void readPile( Config& cfg, CardPile *pile, QString name, int& highestZ );
76 76
77protected: 77protected:
78 void contentsMousePressEvent(QMouseEvent *e); 78 void contentsMousePressEvent(QMouseEvent *e);
79 void contentsMouseReleaseEvent(QMouseEvent *e); 79 void contentsMouseReleaseEvent(QMouseEvent *e);
80 void contentsMouseMoveEvent(QMouseEvent *e); 80 void contentsMouseMoveEvent(QMouseEvent *e);
81 virtualvoid checkUnusable() { } //added for freecell
81 82
82protected: 83protected:
83 // Mouse event state variables 84 // Mouse event state variables
84 bool moved; 85 bool moved;
85 CanvasCard *moving; 86 CanvasCard *moving;
86 CanvasCardPile *alphaCardPile; 87 CanvasCardPile *alphaCardPile;
diff --git a/noncore/games/solitaire/freecellcardgame.cpp b/noncore/games/solitaire/freecellcardgame.cpp
index 98415aa..aeb32fc 100644
--- a/noncore/games/solitaire/freecellcardgame.cpp
+++ b/noncore/games/solitaire/freecellcardgame.cpp
@@ -66,12 +66,95 @@ void FreecellCardGame::deal(void)
66 highestZ++; 66 highestZ++;
67 } 67 }
68 68
69 endDealing(); 69 endDealing();
70} 70}
71 71
72 // checks if smaller card with different color, that could be put on top on the
73 // card, is present in working or freecell pile
74bool FreecellCardGame::checkNeeded(Card *card)
75{
76 if (card->getValue() > 2){
77 int i;
78 Card *c;
79 for (i=0;i<4;i++){
80 c = freecellPiles[i]->cardOnBottom();
81 if (c != NULL){
82 if (card->isRed()!= c->isRed() && card->getValue()== c->getValue()+1){
83 return (false);
84 }
85 }
86 }
87 for (i=0;i<8;i++){
88 c=workingPiles[i]->cardOnBottom();
89 while (c!=NULL){
90 if (card->isRed() != c->isRed()&& card->getValue() == c->getValue()+1) {
91 return (false);
92 }
93 c=workingPiles[i]->cardInfront(c);
94 }
95 }
96 }
97 return(true);
98}
99
100// added to move cards, on which no card can be moved, to discard pile
101void FreecellCardGame::checkUnusable()
102{
103 int i,j;
104 //printf("void FreecellCardGame::checkUnusable()\n");
105 Card *top_one;
106 for (i=0;i < 8;i++)
107 {
108 top_one = workingPiles[i]->cardOnTop();
109 if (top_one != NULL)
110 {
111 j = 0;
112 while ((j < 4))
113 {
114 if (discardPiles[j]->isAllowedOnTop(top_one)){
115 if (checkNeeded(top_one)){
116 top_one->setCardPile(discardPiles[j]);
117 workingPiles[i]->removeCard(top_one);
118 // printf("k %d f work%d to disk%d on %d\n ",top_one->getValue(),i+1,j+1,highestZ);
119 discardPiles[j]->addCardToTop(top_one);
120 top_one->setPos(discardPiles[j]->getX(),discardPiles[j]->getY(),highestZ);
121 highestZ++;
122 j = 4;
123 checkUnusable();
124 }
125 }
126 j++;
127 }
128 }
129 }
130 for (i=0;i<4;i++){
131 top_one = freecellPiles[i]->cardOnTop();
132 if (top_one != NULL)
133 {
134 j = 0;
135 while ((j < 4))
136 {
137 if (discardPiles[j]->isAllowedOnTop(top_one)){
138 if (checkNeeded(top_one)){
139 top_one->setCardPile(discardPiles[j]);
140 freecellPiles[i]->removeCard(top_one);
141 // printf("k %d f work%d to disk%d on %d\n ",top_one->getValue(),i+1,j+1,highestZ);
142 discardPiles[j]->addCardToTop(top_one);
143 top_one->setPos(discardPiles[j]->getX(),discardPiles[j]->getY(),highestZ);
144 highestZ++;
145 j = 4;
146 checkUnusable();
147 }
148 }
149 j++;
150 }
151 }
152 }
153}
154
72 155
73bool FreecellCardGame::mousePressCard( Card *c, QPoint p ) 156bool FreecellCardGame::mousePressCard( Card *c, QPoint p )
74{ 157{
75 Q_UNUSED(p); 158 Q_UNUSED(p);
76 159
77 if ( !c->getCardPile()->isAllowedToBeMoved(c) ) { 160 if ( !c->getCardPile()->isAllowedToBeMoved(c) ) {
diff --git a/noncore/games/solitaire/freecellcardgame.h b/noncore/games/solitaire/freecellcardgame.h
index f1b09ab..2df751b 100644
--- a/noncore/games/solitaire/freecellcardgame.h
+++ b/noncore/games/solitaire/freecellcardgame.h
@@ -59,12 +59,13 @@ public:
59 if ( card->isFacing() && 59 if ( card->isFacing() &&
60 cardOnTop() == NULL ) 60 cardOnTop() == NULL )
61 return TRUE; 61 return TRUE;
62 return PatienceWorkingPile::isAllowedOnTop( card ); 62 return PatienceWorkingPile::isAllowedOnTop( card );
63 } 63 }
64 64
65
65 virtual bool isAllowedToBeMoved(Card *card) { 66 virtual bool isAllowedToBeMoved(Card *card) {
66 int nextExpectedValue = (int)card->getValue(); 67 int nextExpectedValue = (int)card->getValue();
67 bool nextExpectedColor = card->isRed(); 68 bool nextExpectedColor = card->isRed();
68 int numberOfCardsBeingMoved = 0; 69 int numberOfCardsBeingMoved = 0;
69 70
70 while ((card != NULL)) { 71 while ((card != NULL)) {
@@ -135,16 +136,18 @@ public:
135 virtual void mousePress(QPoint p) { Q_UNUSED(p); } 136 virtual void mousePress(QPoint p) { Q_UNUSED(p); }
136 virtual void mouseRelease(QPoint p) { Q_UNUSED(p); } 137 virtual void mouseRelease(QPoint p) { Q_UNUSED(p); }
137// virtual void mouseMove(QPoint p); 138// virtual void mouseMove(QPoint p);
138 virtual bool mousePressCard(Card *card, QPoint p); 139 virtual bool mousePressCard(Card *card, QPoint p);
139 virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); } 140 virtual void mouseReleaseCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); }
140// virtual void mouseMoveCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); } 141// virtual void mouseMoveCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); }
142 virtual void checkUnusable();
141 void readConfig( Config& cfg ); 143 void readConfig( Config& cfg );
142 void writeConfig( Config& cfg ); 144 void writeConfig( Config& cfg );
143 bool snapOn; 145 bool snapOn;
144private: 146private:
147 bool checkNeeded(Card *card);
145 FreecellFreecellPile *freecellPiles[8]; 148 FreecellFreecellPile *freecellPiles[8];
146 FreecellWorkingPile *workingPiles[8]; 149 FreecellWorkingPile *workingPiles[8];
147 FreecellDiscardPile *discardPiles[4]; 150 FreecellDiscardPile *discardPiles[4];
148}; 151};
149 152
150 153