Diffstat (limited to 'noncore/games/solitaire/freecellcardgame.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/solitaire/freecellcardgame.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
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 | |||
@@ -69,6 +69,89 @@ void FreecellCardGame::deal(void) | |||
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 | ||
74 | bool 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 | ||
101 | void 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 | ||
73 | bool FreecellCardGame::mousePressCard( Card *c, QPoint p ) | 156 | bool FreecellCardGame::mousePressCard( Card *c, QPoint p ) |
74 | { | 157 | { |