Text based solitaire game for windows and linux

Configurare noua (How To)

Situatie

Solutie

Pasi de urmat

  1. /*=================main.cpp===========================*/
  2. #include <iostream>
  3. #include "Solitaire.h"
  4. using namespace std;
  5. void HandleMove(Solitaire& game);
  6. void HandleMoveToAnswer(Solitaire& game);
  7. void ClearScreen();
  8. int main(int argc, char** argv)
  9. {
  10. Solitaire game = Solitaire();
  11. game.PrintAllDetails();
  12. bool running = true;
  13. do{
  14. char option = ' ';
  15. cout<<endl<<endl;
  16. cout<<"1. move card between rows";
  17. cout<<"\n2. move to answers";
  18. cout<<"\n3. deal";
  19. cout<<"\n0. quit";
  20. cout<<"\nEnter option:";
  21. cin >> option;
  22. /* 48 - 55 ascii code is 0 - 7 */
  23. if(game.GameCompleted())
  24. {
  25. ClearScreen();
  26. cout<<"\n\n\n\t\t\t CONGRATULATIONS YOU WON!!!\n\n";
  27. cin.get();
  28. running = false;
  29. }
  30. else
  31. {
  32. switch((int)option)
  33. {
  34. case 48:
  35. running = false;
  36. break;
  37. case 49:
  38. HandleMove(game);
  39. break;
  40. case 50:
  41. HandleMoveToAnswer(game);
  42. break;
  43. case 51:
  44. game.Deal(3);
  45. break;
  46. default:
  47. cout<<"\ninvalid option";
  48. cin.ignore(80,'\n');
  49. break;
  50. }
  51. ClearScreen();
  52. game.PrintAllDetails();
  53. }
  54. }while(running);
  55. return 0;
  56. }
  57. void HandleMove(Solitaire& game)
  58. {
  59. char from = '0' ,to = '0';
  60. cout<<endl <<endl;
  61. cout<<"From (7 for deck):";
  62. cin >> from;
  63. cout<< "To: ";
  64. cin>> to;
  65. if( ((int)from >= 48 && (int)from <= 55) &&
  66. ((int)from >= 48 && (int)to <= 54) )
  67. {
  68. game.MakeMoveRowToRow((int)from - 48,(int)to - 48);
  69. }
  70. else
  71. {
  72. cout<<"invalid input";
  73. cin.get();
  74. cin.get();
  75. }
  76. }
  77. void HandleMoveToAnswer(Solitaire& game)
  78. {
  79. char from = 0;
  80. cout<<endl <<endl;
  81. cout<< "From (7 for deck): ";
  82. cin>> from;
  83. if((int)from >= 48 && (int)from <= 55)
  84. game.MakeSuitMove((int)from - 48);
  85. else
  86. {
  87. cout<<"invalid input";
  88. cin.get();
  89. cin.get();
  90. }
  91. }
  92. void ClearScreen()
  93. {
  94. #ifdef __linux__
  95. system("clear");
  96. #elif _WIN32
  97. system("cls");
  98. #endif
  99. }
  100. /*=============================================*/
  101. /*=================Card.h=======================*/
  102. #pragma once
  103. #include <iostream>
  104. #ifdef _WIN32
  105. #include<windows.h>
  106. const static int BLACK = 0;
  107. const static int BLUE = 9;
  108. const static int RED = 12;
  109. const static int WHITE = 15;
  110. #elif __linux__
  111. #include "stdlib.h"
  112. #endif
  113. class Card
  114. {
  115. public:
  116. Card(void);
  117. Card(char rank,char suit);
  118. ~Card(void);
  119. void Flip();
  120. bool GetIsFaceUp();
  121. int GetSolitaireValue();
  122. char GetCardSuit();
  123. char GetCardRank();
  124. friend std::ostream & operator<< (std::ostream & os, Card& c);
  125. /*
  126. Used to navigate up and
  127. down the cards in a row
  128. */
  129. Card* parent;
  130. Card* child;
  131. private:
  132. char rank;
  133. char suit;
  134. bool isFaceUp;
  135. };
  136. /*=============================================*/
  137. /*====================Card.cpp===================*/
  138. #include "Card.h"
  139. Card::Card(void)
  140. {
  141. }
  142. Card::Card(char r, char s)
  143. :rank(r)
  144. ,suit(s)
  145. ,isFaceUp(false)
  146. ,child(NULL)
  147. ,parent(NULL)
  148. {
  149. }
  150. Card::~Card(void)
  151. {
  152. }
  153. void Card::Flip()
  154. {
  155. isFaceUp = !isFaceUp;
  156. }
  157. bool Card::GetIsFaceUp()
  158. {
  159. return isFaceUp;
  160. }
  161. char Card::GetCardSuit()
  162. {
  163. return suit;
  164. }
  165. char Card::GetCardRank()
  166. {
  167. return rank;
  168. }
  169. int Card::GetSolitaireValue()
  170. {
  171. if(rank == 'A')
  172. return 1;
  173. else if(rank == 'T')
  174. return 10;
  175. else if(rank == 'J')
  176. return 11;
  177. else if(rank == 'Q')
  178. return 12;
  179. else if(rank == 'K')
  180. return 13;
  181. else
  182. {
  183. char c[] = {rank, '\0'};
  184. return atoi(c);
  185. }
  186. }
  187. std::ostream & operator<< (std::ostream & os, Card& c)
  188. {
  189. #ifdef _WIN32
  190. HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
  191. if(c.suit == 'c' || c.suit == 's')
  192. SetConsoleTextAttribute(handle, BLUE);
  193. else
  194. SetConsoleTextAttribute(handle,RED);
  195. os<< c.suit << c.rank;
  196. SetConsoleTextAttribute(handle,WHITE);
  197. #elif __linux__
  198. if(c.suit == 'c' || c.suit == 's')
  199. os<<"\033[22;34m";
  200. else
  201. os<<"\033[22;31m";
  202. os<< c.suit << c.rank;
  203. os<<"\033[22;30m";
  204. #endif
  205. return os;
  206. }
  207. /*=============================================*/
  208. /*====================Deck.h====================*/
  209. #pragma once
  210. #include "Card.h"
  211. #include <ctime>
  212. #include <iostream>
  213. #include "TableCard.h"
  214. const static int RANK_SIZE = 13;
  215. const static int SUIT_SIZE = 4;
  216. const static char RANKS[] = {'A','2','3','4','5','6','7','8','9','T','J','Q','K'};
  217. const static char SUITS[] = {'h','d','s','c'};
  218. class Deck
  219. {
  220. public:
  221. Deck(void);
  222. ~Deck(void);
  223. void Populate(void);
  224. void Shuffle(void);
  225. void PrintDeck(void);
  226. void PopulateVector(TableCard& aDeck);
  227. private:
  228. Card _deck[52];
  229. int currentIndex;
  230. };
  231. /*==============================================*/
  232. /*====================Deck.cpp====================*/
  233. #include "Deck.h"
  234. Deck::Deck(void)
  235. :currentIndex(0)
  236. {
  237. srand((unsigned)time(0));
  238. Populate();
  239. }
  240. Deck::~Deck(void)
  241. {
  242. }
  243. void Deck::Populate()
  244. {
  245. int index = 0;
  246. for(int i=0; i<SUIT_SIZE; i++)
  247. {
  248. for(int j=0; j<RANK_SIZE;j++)
  249. {
  250. _deck[index] = Card(RANKS[j],SUITS[i]);
  251. index++;
  252. }
  253. }
  254. }
  255. void Deck::Shuffle()
  256. {
  257. int max = SUIT_SIZE * RANK_SIZE;
  258. for(int i=0; i<max-1; i++)
  259. {
  260. int randNum = rand() % 52;
  261. std::swap(_deck[i],_deck[randNum]);
  262. }
  263. }
  264. void Deck::PrintDeck(void)
  265. {
  266. int max = SUIT_SIZE * RANK_SIZE;
  267. for(int i=0; i<max; i++)
  268. {
  269. if(i %13 == 0)
  270. std::cout<< '\n' <<'\n';
  271. std::cout<< _deck[i] << " " << _deck[i].GetBlackjackValue() << " ";
  272. }
  273. }
  274. void Deck::PopulateVector(TableCard& aDeck)
  275. {
  276. int max = SUIT_SIZE * RANK_SIZE;
  277. aDeck.Clear();
  278. for(int i=0; i<max; i++)
  279. aDeck.PushValueCopy(_deck[i]);
  280. }
  281. /*===============================================*/
  282. /*====================TableCard.h===================*/
  283. #pragma once
  284. #include "Card.h"
  285. #include <vector>
  286. class TableCard
  287. {
  288. public:
  289. TableCard(int maxSize);
  290. ~TableCard(void);
  291. Card& operator[](int index);
  292. bool Push(Card& card);
  293. bool PushValueCopy(Card card);
  294. int Size();
  295. bool empty();
  296. Card& top(void);
  297. bool RemoveAt(int index);
  298. bool Pop();
  299. void Clear();
  300. static void MoveBetween(TableCard& from, TableCard& to);
  301. private:
  302. int _maxSize;
  303. int _size;
  304. std::vector<Card*> _cards;
  305. };
  306. /*=============================================*/
  307. /*====================TableCard.cpp================*/
  308. #include "TableCard.h"
  309. TableCard::TableCard(int maxSize)
  310. :_size(0)
  311. ,_maxSize(maxSize)
  312. {
  313. _cards.resize(maxSize);
  314. }
  315. TableCard::~TableCard(void)
  316. {
  317. }
  318. bool TableCard::Push(Card& card)
  319. {
  320. if(_size < _maxSize)
  321. {
  322. _cards[_size] = &card;
  323. _size++;
  324. return true;
  325. }
  326. return false;
  327. }
  328. bool TableCard::PushValueCopy(Card card)
  329. {
  330. if(_size < _maxSize);
  331. {
  332. _cards[_size] = new Card(card);
  333. _size++;
  334. return true;
  335. }
  336. return false;
  337. }
  338. void TableCard::Clear()
  339. {
  340. for(int i=0; i<_size; i++)
  341. _cards[i] = NULL;
  342. _size = 0;
  343. }
  344. bool TableCard::empty()
  345. {
  346. if(_size == 0)
  347. return true;
  348. return false;
  349. }
  350. Card& TableCard::top(void)
  351. {
  352. if(_size > 0)
  353. return *_cards[_size-1];
  354. }
  355. bool TableCard::RemoveAt(int index)
  356. {
  357. if(index >= 0 && index < _maxSize)
  358. {
  359. _cards[index] = NULL;
  360. _size--;
  361. return true;
  362. }
  363. return false;
  364. }
  365. int TableCard::Size()
  366. {
  367. return _size;
  368. }
  369. bool TableCard::Pop()
  370. {
  371. if(_size > 0)
  372. {
  373. _cards[_size - 1] = NULL;
  374. _size--;
  375. return true;
  376. }
  377. return false;
  378. }
  379. Card& TableCard::operator[](int index)
  380. {
  381. if(index >= 0 && index <= _size)
  382. return *_cards[index];
  383. }
  384. void TableCard::MoveBetween(TableCard& from, TableCard& to)
  385. {
  386. to.Push(from.top());
  387. from.Pop();
  388. }
  389. /*=============================================*/
  390. /*====================Solitaire.h==================*/
  391. #pragma once
  392. #include <iostream>
  393. #include <vector>
  394. #include "Deck.h"
  395. #include "Card.h"
  396. #include "TableCard.h"
  397. const static int TABLE_SIZE = 7;
  398. class Solitaire
  399. {
  400. public:
  401. Solitaire(void);
  402. ~Solitaire(void);
  403. void PopulateTable(void);
  404. void Deal(int numToDeal=1);
  405. /* Functions for validating and moving cards */
  406. void MakeSuitMove(int from);
  407. void MakeMoveBetweenRows(int from, int to);
  408. void MakeMoveDeckToRow(int to);
  409. void MakeMoveRowToRow(int from, int to);
  410. bool ValidMove(int from, int to);
  411. bool ValidRowToRowMove(Card* fromCard, int to);
  412. bool ValidSuitMove(int from);
  413. /* Checks to see if all answer sections full */
  414. bool GameCompleted();
  415. /* Functions for printing card details */
  416. void PrintAllDetails(void);
  417. void PrintSuitDetails(void);
  418. void PrintDeckDetails(void);
  419. private:
  420. TableCard _deck;
  421. TableCard _discardedCards;
  422. std::vector<TableCard> _tableCards;
  423. //Destination of cards. When all filled player wins
  424. std::vector<TableCard> _suitCards;
  425. };
  426. /*==============================================*/
  427. /*====================Solitaire.cpp=================*/
  428. #include "Solitaire.h"
  429. using namespace std;
  430. Solitaire::Solitaire(void)
  431. :_deck(52)
  432. ,_discardedCards(52)
  433. {
  434. //Uses the deck class to populate solitaire deck
  435. //Shuffle the deck to randomize
  436. Deck deck = Deck();
  437. deck.Shuffle();
  438. deck.PopulateVector(_deck);
  439. for(int i=0; i<TABLE_SIZE; i++)
  440. {
  441. TableCard tableCard = TableCard(20);
  442. _tableCards.push_back(tableCard);
  443. }
  444. //_suitCards.resize(4);
  445. for(int i=0; i<4; i++)
  446. {
  447. TableCard suitCard = TableCard(13);
  448. _suitCards.push_back(suitCard);
  449. }
  450. PopulateTable();
  451. }
  452. Solitaire::~Solitaire(void)
  453. {
  454. }
  455. void Solitaire::PopulateTable(void)
  456. {
  457. for(int i=0; i<TABLE_SIZE; i++)
  458. {
  459. for(int j=0; j<TABLE_SIZE -i; j++)
  460. {
  461. if(j == (TABLE_SIZE - i) - 1)
  462. _deck.top().Flip();
  463. _tableCards[j].Push(_deck.top());
  464. _deck.Pop();
  465. }
  466. }
  467. }
  468. void Solitaire::Deal(int numToDeal)
  469. {
  470. int size = _deck.Size();
  471. for(int i=0; i<size; i++)
  472. {
  473. if(_deck.top().GetIsFaceUp())
  474. {
  475. _deck.top().Flip();
  476. _discardedCards.Push(_deck.top());
  477. _deck.Pop();
  478. }
  479. }
  480. if(_deck.empty())
  481. {
  482. for(int i=_discardedCards.Size()-1; i>=0; i--)
  483. _deck.Push(_discardedCards[i]);
  484. _discardedCards.Clear();
  485. }
  486. int index = 0;
  487. for(int i=0; i<numToDeal; i++)
  488. {
  489. index = _deck.Size() -i -1;
  490. if(index >= 0)
  491. {
  492. _deck[index].Flip();
  493. }
  494. else
  495. break;
  496. }
  497. }
  498. void Solitaire::PrintSuitDetails()
  499. {
  500. cout<<"=============================================\n";
  501. for(int j=0; j<_suitCards.size(); j++)
  502. {
  503. switch(j)
  504. {
  505. case 0:
  506. cout<< "h :";
  507. break;
  508. case 1:
  509. cout<< "d :";
  510. break;
  511. case 2:
  512. cout<< "s :";
  513. break;
  514. case 3:
  515. cout<< "c :";
  516. break;
  517. }
  518. for(int i=0; i<_suitCards[j].Size(); i++)
  519. {
  520. if(&_suitCards[j][i] != NULL)
  521. cout<<_suitCards[j][i] << " ";
  522. else
  523. break;
  524. }
  525. cout<< endl;
  526. }
  527. cout<<"=============================================\n";
  528. cout<<endl;
  529. }
  530. void Solitaire::PrintDeckDetails()
  531. {
  532. cout<<"--------------------------------------------\n";
  533. cout<<"|Deck: ";
  534. for(unsigned int i=0; i<_deck.Size(); i++)
  535. {
  536. if(_deck[i].GetIsFaceUp())
  537. cout<<_deck[i] << " ";
  538. }
  539. cout<<"\n--------------------------------------------\n";
  540. }
  541. void Solitaire::PrintAllDetails()
  542. {
  543. PrintDeckDetails();
  544. PrintSuitDetails();
  545. cout<< "| 6 | \t | 5 | \t | 4 | \t | 3 | \t | 2 | \t | 1 | \t | 0 |\n";
  546. cout<< "----- \t ----- \t ----- \t ----- \t ----- \t ----- \t -----\n";
  547. //Cannot be unsigned as number is always greater than or equal to 0 --
  548. int colMax = _tableCards.size();
  549. int rowMax = 0;
  550. for(int i=0; i<colMax; i++)
  551. {
  552. if(_tableCards[i].Size() > rowMax)
  553. {
  554. rowMax = _tableCards[i].Size();
  555. }
  556. }
  557. for(int i=0; i<rowMax; i++)
  558. {
  559. for(int j=colMax-1; j>=0; j--)
  560. {
  561. if(i >= _tableCards[j].Size())
  562. {
  563. cout<< " \t " ;
  564. continue;
  565. }
  566. if(_tableCards[j][i].GetIsFaceUp())
  567. cout << " " << _tableCards[j][i] << " \t ";
  568. else
  569. cout << " " <<(char)254 << " \t ";
  570. }
  571. cout<<endl;
  572. }
  573. cout<<endl<<endl;
  574. //SHOW DISCARDED CARDS
  575. /*cout<<"\nCards in the used pile: \n\n";
  576. for(unsigned int i=0; i<_discardedCards.Size(); i++)
  577. cout<<_discardedCards[i] << " ";
  578. cout<<endl<<endl;
  579. */
  580. //DISPLAYS CHILDREN AND PARENTS
  581. /*for(int i=0; i<_tableCards.size(); i++)
  582. {
  583. cout<< i << ": \n" ;
  584. for(int j= 0; j< _tableCards[i].Size(); j++)
  585. {
  586. if(_tableCards[i][j].child != NULL)
  587. {
  588. cout<< _tableCards[i][j] << "'s child is " << *_tableCards[i][j].child << endl;
  589. }
  590. if(_tableCards[i][j].parent != NULL)
  591. {
  592. cout<< _tableCards[i][j] << "'s parent is " << *_tableCards[i][j].parent << endl;
  593. }
  594. }
  595. }*/
  596. }
  597. bool Solitaire::ValidMove(int from, int to)
  598. {
  599. //start move and end move the same
  600. if(from == to && from != 7)
  601. return false;
  602. Card* toCard;
  603. Card* fromCard;
  604. if(from == 7)
  605. {
  606. if(!_deck.empty())
  607. {
  608. if(!_deck.top().GetIsFaceUp())
  609. {
  610. return false;
  611. }
  612. else
  613. {
  614. fromCard = &_deck.top();
  615. }
  616. }
  617. else
  618. {
  619. return false;
  620. }
  621. }
  622. else
  623. {
  624. //if no card in moving from row not valid
  625. if(!_tableCards[from].empty())
  626. fromCard = &_tableCards[from].top();
  627. else
  628. return false;
  629. }
  630. if(!_tableCards[to].empty())
  631. toCard = &_tableCards[to].top();
  632. //move king to empty space
  633. if(_tableCards[to].empty())
  634. {
  635. if(fromCard->GetCardRank() == 'K')
  636. return true;
  637. else
  638. return false;
  639. }
  640. else if(fromCard->GetSolitaireValue() == toCard->GetSolitaireValue()-1 )
  641. {
  642. int toColor = 0, fromColor = 0;
  643. if(toCard->GetCardSuit() == 'h' || toCard->GetCardSuit() == 'd')
  644. toColor = 0;
  645. else
  646. toColor = 1;
  647. if(fromCard->GetCardSuit() =='h' || fromCard->GetCardSuit() == 'd')
  648. fromColor = 0;
  649. else
  650. fromColor = 1;
  651. if(fromColor == toColor)
  652. return false;
  653. else
  654. return true;
  655. }
  656. return false;
  657. }
  658. bool Solitaire::ValidSuitMove(int from)
  659. {
  660. Card* fromCard;
  661. if(from == 7)
  662. {
  663. if(!_deck.empty())
  664. {
  665. if(!_deck.top().GetIsFaceUp())
  666. {
  667. return false;
  668. }
  669. else
  670. {
  671. fromCard = &_deck.top();
  672. }
  673. }
  674. else
  675. {
  676. return false;
  677. }
  678. }
  679. else
  680. {
  681. if(!_tableCards[from].empty())
  682. fromCard = &_tableCards[from].top();
  683. else
  684. return false;
  685. }
  686. char suit = fromCard->GetCardSuit();
  687. int moveIndex = 0;
  688. switch(suit)
  689. {
  690. case 'h':
  691. moveIndex = 0;
  692. break;
  693. case 'd':
  694. moveIndex = 1;
  695. break;
  696. case 's':
  697. moveIndex = 2;
  698. break;
  699. case 'c':
  700. moveIndex = 3;
  701. break;
  702. }
  703. if(fromCard->GetSolitaireValue() ==
  704. _suitCards[moveIndex].Size() + 1 )
  705. {
  706. if(!_suitCards[moveIndex].Size() == 0)
  707. {
  708. if(fromCard->parent != NULL)
  709. fromCard->parent->child = NULL;
  710. fromCard->parent = &_suitCards[moveIndex].top();
  711. _suitCards[moveIndex].top().child = fromCard;
  712. fromCard->child = NULL;
  713. }
  714. if(from != 7){
  715. TableCard::MoveBetween(_tableCards[from],_suitCards[moveIndex]);
  716. if(!_tableCards[from].empty())
  717. {
  718. if(!_tableCards[from].top().GetIsFaceUp())
  719. _tableCards[from].top().Flip();
  720. }
  721. }
  722. else
  723. {
  724. _suitCards[moveIndex].Push(_deck.top());
  725. _deck.Pop();
  726. }
  727. }
  728. return false;
  729. }
  730. void Solitaire::MakeSuitMove(int from)
  731. {
  732. /* validSuit move also makes move */
  733. ValidSuitMove(from) ;
  734. }
  735. void Solitaire::MakeMoveBetweenRows(int from, int to)
  736. {
  737. if(ValidMove(from,to))
  738. {
  739. if(!_tableCards[to].empty())
  740. _tableCards[to].top().child = &_tableCards[from].top();
  741. if(_tableCards[from].top().GetCardRank() != 'K')
  742. _tableCards[from].top().parent = &_tableCards[to].top();
  743. TableCard::MoveBetween(_tableCards[from], _tableCards[to]);
  744. if(!_tableCards[from].empty())
  745. if(!_tableCards[from].top().GetIsFaceUp())
  746. _tableCards[from].top().Flip();
  747. }
  748. }
  749. void Solitaire::MakeMoveDeckToRow(int to)
  750. {
  751. if(ValidMove(7 ,to))
  752. {
  753. if(!_tableCards[to].empty())
  754. _tableCards[to].top().child = &_deck.top();
  755. if(_deck.top().GetCardRank() != 'K')
  756. _deck.top().parent = & _tableCards[to].top();
  757. _tableCards[to].Push(_deck.top());
  758. _deck.Pop();
  759. }
  760. }
  761. void Solitaire::MakeMoveRowToRow(int from, int to)
  762. {
  763. if(from == 7)
  764. {
  765. MakeMoveDeckToRow(to);
  766. return;
  767. }
  768. else if(_tableCards[from].Size() == 0)
  769. return;
  770. Card* fromCard;
  771. fromCard = &_tableCards[from].top();
  772. if(fromCard->parent == NULL)
  773. MakeMoveBetweenRows(from,to);
  774. else
  775. {
  776. int pos = _tableCards[from].Size()-1;
  777. bool checkParent = true;
  778. bool found = false;
  779. while(checkParent && !found)
  780. {
  781. if(ValidRowToRowMove(fromCard,to))
  782. found = true;
  783. else if(fromCard->parent == NULL)
  784. checkParent = false;
  785. else
  786. {
  787. fromCard = fromCard->parent;
  788. pos--;
  789. }
  790. }
  791. if(found)
  792. {
  793. bool hasChildren = true;
  794. if(fromCard->parent != NULL)
  795. fromCard->parent->child = NULL;
  796. while(hasChildren)
  797. {
  798. if(!_tableCards[to].empty())
  799. {
  800. fromCard->parent = &_tableCards[to].top();
  801. _tableCards[to].top().child = fromCard;
  802. }
  803. _tableCards[to].Push(*fromCard);
  804. _tableCards[from].RemoveAt(pos);
  805. fromCard = fromCard->child;
  806. pos++;
  807. if(fromCard == NULL)
  808. hasChildren = false;
  809. }
  810. }
  811. if(!_tableCards[from].empty())
  812. if(!_tableCards[from].top().GetIsFaceUp())
  813. _tableCards[from].top().Flip();
  814. }
  815. }
  816. bool Solitaire::ValidRowToRowMove(Card* fromCard, int to)
  817. {
  818. Card* toCard;
  819. if(!_tableCards[to].empty())
  820. toCard = &_tableCards[to].top();
  821. //move king to empty space
  822. if(_tableCards[to].empty())
  823. {
  824. if(fromCard->GetCardRank() == 'K')
  825. return true;
  826. else
  827. return false;
  828. }
  829. else if(fromCard->GetSolitaireValue() == toCard->GetSolitaireValue()-1 )
  830. {
  831. int toColor = 0, fromColor = 0;
  832. if(toCard->GetCardSuit() == 'h' || toCard->GetCardSuit() == 'd')
  833. toColor = 0;
  834. else
  835. toColor = 1;
  836. if(fromCard->GetCardSuit() =='h' || fromCard->GetCardSuit() == 'd')
  837. fromColor = 0;
  838. else
  839. fromColor = 1;
  840. if(fromColor == toColor)
  841. return false;
  842. else
  843. return true;
  844. }
  845. return false;
  846. }
  847. bool Solitaire::GameCompleted()
  848. {
  849. for(int i=0; i<_suitCards.size(); i++)
  850. if(_suitCards[i].Size() < 13)
  851. return false;
  852. return true;
  853. }
  854. /*==============================================*/

Tip solutie

Permanent

Despre Autor

Leave A Comment?