summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore 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.h5
4 files changed, 90 insertions, 2 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
@@ -329,5 +329,5 @@ void CanvasCardGame::contentsMouseReleaseEvent(QMouseEvent *e)
}
- pile->addCardToTop(item);
item->setCardPile(pile);
//item->move( pile->getCardPos(item) );
+ pile->addCardToTop(item);
QPoint p = pile->getCardPos(item);
@@ -335,2 +335,3 @@ void CanvasCardGame::contentsMouseReleaseEvent(QMouseEvent *e)
highestZ++;
+ checkUnusable(); // added for freecell to move card to discard pile
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
@@ -80,2 +80,3 @@ protected:
void contentsMouseMoveEvent(QMouseEvent *e);
+ virtual void checkUnusable() { } //added for freecell
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
@@ -71,2 +71,85 @@ void FreecellCardGame::deal(void)
+// checks if smaller card with different color, that could be put on top on the
+// card, is present in working or freecell pile
+bool FreecellCardGame::checkNeeded(Card *card)
+{
+ if (card->getValue() > 2){
+ int i;
+ Card *c;
+ for (i=0;i<4;i++){
+ c = freecellPiles[i]->cardOnBottom();
+ if (c != NULL){
+ if (card->isRed()!= c->isRed() && card->getValue()== c->getValue()+1){
+ return (false);
+ }
+ }
+ }
+ for (i=0;i<8;i++){
+ c=workingPiles[i]->cardOnBottom();
+ while (c!=NULL){
+ if (card->isRed() != c->isRed() && card->getValue() == c->getValue()+1) {
+ return (false);
+ }
+ c=workingPiles[i]->cardInfront(c);
+ }
+ }
+ }
+ return(true);
+}
+
+// added to move cards, on which no card can be moved, to discard pile
+void FreecellCardGame::checkUnusable()
+{
+ int i,j;
+// printf("void FreecellCardGame::checkUnusable()\n");
+ Card *top_one;
+ for (i=0;i < 8;i++)
+ {
+ top_one = workingPiles[i]->cardOnTop();
+ if (top_one != NULL)
+ {
+ j = 0;
+ while ((j < 4))
+ {
+ if (discardPiles[j]->isAllowedOnTop(top_one)){
+ if (checkNeeded(top_one)){
+ top_one->setCardPile(discardPiles[j]);
+ workingPiles[i]->removeCard(top_one);
+// printf("k %d f work%d to disk%d on %d\n ",top_one->getValue(),i+1,j+1,highestZ);
+ discardPiles[j]->addCardToTop(top_one);
+ top_one->setPos(discardPiles[j]->getX(),discardPiles[j]->getY(),highestZ);
+ highestZ++;
+ j = 4;
+ checkUnusable();
+ }
+ }
+ j++;
+ }
+ }
+ }
+ for (i=0;i<4;i++){
+ top_one = freecellPiles[i]->cardOnTop();
+ if (top_one != NULL)
+ {
+ j = 0;
+ while ((j < 4))
+ {
+ if (discardPiles[j]->isAllowedOnTop(top_one)){
+ if (checkNeeded(top_one)){
+ top_one->setCardPile(discardPiles[j]);
+ freecellPiles[i]->removeCard(top_one);
+// printf("k %d f work%d to disk%d on %d\n ",top_one->getValue(),i+1,j+1,highestZ);
+ discardPiles[j]->addCardToTop(top_one);
+ top_one->setPos(discardPiles[j]->getX(),discardPiles[j]->getY(),highestZ);
+ highestZ++;
+ j = 4;
+ checkUnusable();
+ }
+ }
+ j++;
+ }
+ }
+ }
+}
+
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
@@ -48,3 +48,3 @@ public:
Card *tempCard = card;
-
+
while ((tempCard != NULL)) {
@@ -64,2 +64,3 @@ public:
+
virtual bool isAllowedToBeMoved(Card *card) {
@@ -140,2 +141,3 @@ public:
// virtual void mouseMoveCard(Card *card, QPoint p) { Q_UNUSED(card); Q_UNUSED(p); }
+ virtual void checkUnusable();
void readConfig( Config& cfg );
@@ -144,2 +146,3 @@ public:
private:
+ bool checkNeeded(Card *card);
FreecellFreecellPile *freecellPiles[8];