#include #include "CardT.h" #include using namespace std; struct PlayerT { string name; int score; CardT card; }; const int MAX_TURNS = 10; void TakeTurn(PlayerT & player1, PlayerT & player2); int main() { PlayerT player1, player2; int turn; srand(static_cast(time(nullptr))); player1.name = "Bob"; player1.score = 0; player1.card = RandomCard(); player2.name = "Alice"; player2.score = 0; player2.card = RandomCard(); for(turn = 0; turn < MAX_TURNS; ++turn) { TakeTurn(player1, player2); } cout << endl << endl; cout << "The game is over, the score is: " << endl; cout << "\t" << player1.name << ": " << player1.score << endl; cout << "\t" << player2.name << ": " << player2.score << endl; cout << endl; if (player1.score == player2.score) { cout << "This is a tie!" << endl; } else if (player1.score < player2.score) { cout << player2.name << " wins!" << endl; } else { cout << player1.name << " wins!" << endl; } return 0; } void DoWin(PlayerT & winner, PlayerT & loser) { ++winner.score; cout << winner.name << " wins, their score is now " << winner.score << endl; loser.card = RandomCard(); cout << loser.name << " gets a new card: " << CardTToString(loser.card) << endl; cout << endl; return ; } void TakeTurn(PlayerT & player1, PlayerT & player2){ cout << player1.name << " has a " << CardTToString(player1.card) << endl; cout << player2.name << " has a " << CardTToString(player2.card) << endl; cout << endl; switch (CompareCards(player1.card, player2.card)) { case ResultT::TIE: cout << "It is a tie" << endl; player1.card = RandomCard(); player2.card = RandomCard(); break; case ResultT::LOW: DoWin(player2, player1); break; case ResultT::HIGH: DoWin(player1, player2); break; default: cout << "Error in CompareCard function " << endl; } }