Server IP : 172.16.15.8 / Your IP : 13.59.112.169 Web Server : Apache System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64 User : apache ( 48) PHP Version : 7.2.24 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0755) : /home/cjabbott/cs311/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
// Pirate's Gold // // September 4, 2008 // Christie Abbott // // Uses card and deck classes to play a card game. #include <iostream> #include <iomanip> #include <cstdlib> #include <ctime> #include "cardclass.cpp" using namespace std; //------------------------------------------------------------------------------- void PlayGame(DeckType deck); //------------------------------------------------------------------------------- int main() { DeckType deck; srand(time(0)); deck.Shuffle(); PlayGame(deck); return 0; } //------------------------------------------------------------------------------- // PlayGame plays the game Pirate's Gold. The table has eight cards face up, and // any matching cards are replaced. If there are no matching cards then the game // is over. You win the game when there are no more cards in the deck. //------------------------------------------------------------------------------- void PlayGame(DeckType deck) { // is a constant because the number of cards on the table is always 8 const int NUMCARDS = 8; typedef CardType Table[NUMCARDS]; // local variables Table table; bool matchfound; int j, i, round = 1; cout << "Pirate's Gold\n"; cout << "Original Cards on Table\n"; cout << "------------------------\n"; // places cards on the table for(int i = 0; i < NUMCARDS; i++) { table[i] = deck.DrawCard(); if(i == 4) cout << "\n"; table[i].Print(); } matchfound = true; while(matchfound && !deck.IsEmpty()) // checks for matches and if the deck is not full { i = 0; matchfound = false; while(i < NUMCARDS && !matchfound) { j = i + 1; while(j < NUMCARDS && !matchfound) { if(table[i].EqualFace(table[j])) // checks for matching cards & replaces them { matchfound = true; table[i] = deck.DrawCard(); table[j] = deck.DrawCard(); cout << "\n\nRound " << round << "\n"; round ++; for(int k = 0; k < NUMCARDS; k++) { if(k == 4) cout << "\n"; table[k].Print(); } } else j++; } i++; } } // tells the player if they won or lost if(!matchfound) cout << "\nSorry, you lose!\n\n"; else if(deck.IsEmpty()) cout << "\nYou Win!\n\n"; }