Server IP : 172.16.15.8 / Your IP : 3.137.190.6 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 (0705) : /home/jwmccreary/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
// Pirate's Gold - a simulated form of solitaire // // September 2008 // Justin McCreary // Uses Card and Deck Classes #include <iostream> #include <iomanip> #include <cstdlib> // for random num generator #include <ctime> // for time to seed random num generator #include "cardclass.cpp" // Card, Deck types and classes using namespace std; // ----- Game Function Prototypes //--------------------------------------------------------------------------- void PlayPiratesGold (/* in */ DeckType deck); // ----- Main Function //--------------------------------------------------------------------------- int main() { DeckType deck; // A deck of cards for our game srand(time(0)); // "Turn on" the random number generator deck.Shuffle(); // Shuffle the deck PlayPiratesGold (deck); return 0; } //-------------------------------------------------------------------------- // PlayPiratesGold plays a modified version of Solitaire, called Pirate's Gold, in // which the deck is shuffled and eight cards are drawn from the deck and placed on the // "table" face up. The player then searches for two matching(face value) cards, at which // time two cards are drawn from the deck and placed on top of the matching cards. This process // is continued until either all of the cards have been used up, in which the game is won, or when // there are no longer any matching pairs, in which the game is lost. //-------------------------------------------------------------------------- // Accepts: the shuffled deck // Returns: Eight Cards //-------------------------------------------------------------------------- void PlayPiratesGold (DeckType deck) { // local type definition for a card hand typedef CardType HandType[7]; // local variables HandType hand; // One hand of cards int round, cardscore, i; // counter for progressing through rounds, as well as for counting the first eight cards bool complete; // Deal eight cards for (i = 0; i < 8; i++) { hand[i] = deck.DrawCard(); } complete = true; cardscore =0; cout << "Original Cards on Table\n-----------------------\n"; hand[0].Print(); cout << "\t"; hand[1].Print(); cout << "\t"; hand[2].Print(); cout << "\t"; hand[3].Print(); cout << "\n"; hand[4].Print(); cout << "\t"; hand[5].Print(); cout << "\t"; hand[6].Print(); cout << "\t"; hand[7].Print(); cout << "\n\n"; cout << "Table After Each Round of Game\n------------------------------\n"; cardscore = 8; for (i = 0; i < (DECKSIZE-8)/2; i++) { round = i+1; if (hand[0].EqualFace(hand[1])) // matching face values ... { cardscore = cardscore + 2; hand[0] = deck.DrawCard(); hand[1] = deck.DrawCard(); } else if (hand[0].EqualFace(hand[2])) { cardscore = cardscore + 2; hand[0] = deck.DrawCard(); hand[2] = deck.DrawCard(); } else if (hand[0].EqualFace(hand[3])) { cardscore = cardscore + 2; hand[0] = deck.DrawCard(); hand[3] = deck.DrawCard(); } else if (hand[0].EqualFace(hand[4])) { cardscore = cardscore + 2; hand[0] = deck.DrawCard(); hand[4] = deck.DrawCard(); } else if (hand[0].EqualFace(hand[5])) { cardscore = cardscore + 2; hand[0] = deck.DrawCard(); hand[5] = deck.DrawCard(); } else if (hand[0].EqualFace(hand[6])) { cardscore = cardscore + 2; hand[0] = deck.DrawCard(); hand[6] = deck.DrawCard(); } else if (hand[0].EqualFace(hand[7])) { cardscore = cardscore + 2; hand[0] = deck.DrawCard(); hand[7] = deck.DrawCard(); } else if (hand[1].EqualFace(hand[2])) { cardscore = cardscore + 2; hand[1] = deck.DrawCard(); hand[2] = deck.DrawCard(); } else if (hand[1].EqualFace(hand[3])) { cardscore = cardscore + 2; hand[1] = deck.DrawCard(); hand[3] = deck.DrawCard(); } else if (hand[1].EqualFace(hand[4])) { cardscore = cardscore + 2; hand[1] = deck.DrawCard(); hand[4] = deck.DrawCard(); } else if (hand[1].EqualFace(hand[5])) { cardscore = cardscore + 2; hand[1] = deck.DrawCard(); hand[5] = deck.DrawCard(); } else if (hand[1].EqualFace(hand[6])) { cardscore = cardscore + 2; hand[1] = deck.DrawCard(); hand[6] = deck.DrawCard(); } else if (hand[1].EqualFace(hand[7])) { cardscore = cardscore + 2; hand[1] = deck.DrawCard(); hand[7] = deck.DrawCard(); } else if (hand[2].EqualFace(hand[3])) { cardscore = cardscore + 2; hand[2] = deck.DrawCard(); hand[3] = deck.DrawCard(); } else if (hand[2].EqualFace(hand[4])) { cardscore = cardscore + 2; hand[2] = deck.DrawCard(); hand[4] = deck.DrawCard(); } else if (hand[2].EqualFace(hand[5])) { cardscore = cardscore + 2; hand[2] = deck.DrawCard(); hand[5] = deck.DrawCard(); } else if (hand[2].EqualFace(hand[6])) { cardscore = cardscore + 2; hand[2] = deck.DrawCard(); hand[6] = deck.DrawCard(); } else if (hand[2].EqualFace(hand[7])) { cardscore = cardscore + 2; hand[2] = deck.DrawCard(); hand[7] = deck.DrawCard(); } else if (hand[3].EqualFace(hand[4])) { cardscore = cardscore + 2; hand[3] = deck.DrawCard(); hand[4] = deck.DrawCard(); } else if (hand[3].EqualFace(hand[5])) { cardscore = cardscore + 2; hand[3] = deck.DrawCard(); hand[5] = deck.DrawCard(); } else if (hand[3].EqualFace(hand[6])) { cardscore = cardscore + 2; hand[3] = deck.DrawCard(); hand[6] = deck.DrawCard(); } else if (hand[3].EqualFace(hand[7])) { cardscore = cardscore + 2; hand[3] = deck.DrawCard(); hand[7] = deck.DrawCard(); } else if (hand[4].EqualFace(hand[5])) { cardscore = cardscore + 2; hand[4] = deck.DrawCard(); hand[5] = deck.DrawCard(); } else if (hand[4].EqualFace(hand[6])) { cardscore = cardscore + 2; hand[4] = deck.DrawCard(); hand[6] = deck.DrawCard(); } else if (hand[4].EqualFace(hand[7])) { cardscore = cardscore + 2; hand[4] = deck.DrawCard(); hand[7] = deck.DrawCard(); } else if (hand[5].EqualFace(hand[6])) { cardscore = cardscore + 2; hand[5] = deck.DrawCard(); hand[6] = deck.DrawCard(); } else if (hand[5].EqualFace(hand[7])) { cardscore = cardscore + 2; hand[5] = deck.DrawCard(); hand[7] = deck.DrawCard(); } else if (hand[6].EqualFace(hand[7])) { cardscore = cardscore + 2; hand[6] = deck.DrawCard(); hand[7] = deck.DrawCard(); } else { i = 22; complete=false; } if (complete==true) { cout << "\nRound " << round << "\n\n"; hand[0].Print(); cout << "\t"; hand[1].Print(); cout << "\t"; hand[2].Print(); cout << "\t"; hand[3].Print(); cout << "\n"; hand[4].Print(); cout << "\t"; hand[5].Print(); cout << "\t"; hand[6].Print(); cout << "\t"; hand[7].Print(); cout << "\n\n"; } else { cout << " "; } } if(cardscore==52) { cout << "\nCongratulations! You won!\n"; } else { cout << "\nSorry You lose!\n"; } }