Server IP : 172.16.15.8 / Your IP : 3.143.5.161 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 simple card game // // August 2008 // K Ames // 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 PlayWarGame (/* 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 PlayWarGame (deck); return 0; } //-------------------------------------------------------------------------- // PlayWarGame plays a modified version of War, making one pass through // the deck of cards. Each player places next card in hand on table. // Player whose card has highest face value gets 2 points. In case of // face value tie, suits are compared according to Bridge hierarchy. // After all cards are played, player with highest score wins. //-------------------------------------------------------------------------- // Accepts: the shuffled deck // Returns: nothing //-------------------------------------------------------------------------- void PlayWarGame (DeckType deck) { // local type definition for a card hand typedef CardType HandType[DECKSIZE/2]; // local variables HandType hand1, hand2; // Two hands of cards int hand1score, // score counters hand2score, i; // counter for progressing through hands // Deal two hands for (i = 0; i < DECKSIZE/2; i++) { hand1[i] = deck.DrawCard(); hand2[i] = deck.DrawCard(); } // Play the game // Output headings and initialize scores hand1score = 0; hand2score = 0; cout << "The Game of War\n\n"; cout << "Player 1\t\tPlayer 2\t\tWinner\n\n"; // Loop through the hands of cards for (i = 0; i < DECKSIZE/2; i++) { hand1[i].Print(); cout << " \t"; hand2[i].Print(); cout << " \t"; // let's see who has the "highest" card if (hand1[i].GreaterFace(hand2[i])) // player 1's face value higher { hand1score += 2; cout << "Player 1\n"; } else if (hand1[i].EqualFace(hand2[i])) // matching face values ... if (hand1[i].GreaterSuit(hand2[i])) // ... so check suit { hand1score += 2; // ... player 1's suit higher cout << "Player 1\n"; } else { hand2score += 2; // ... player 2's suit higher cout << "Player 2\n"; } else { hand2score += 2; // player 2's face value higher cout << "Player 2\n"; } } // Let's see who wins the game! cout << "\n----------------------------------------"; cout << "\nFinal Scores\n"; cout << "\nPlayer 1: " << hand1score; cout << "\nPlayer 2: " << hand2score; cout << "\n\nAnd The Winner is ... "; if (hand1score > hand2score) cout << "Player 1!\n"; else if (hand2score > hand1score) cout << "Player 2!\n"; else cout << "IT'S A TIE!\n"; cout << "----------------------------------------\n"; }