#include #include #include #include "PlayerT.h" #include "LeftPlayerT.h" #include "RightPlayerT.h" #include "RandPlayerT.h" using namespace std; const int TYPES = 10; const vector NAMES {"Alpha", "Beta", "Gamma", "Delta", "Epsilon", "Zeta", "Eta", "Theta", "Iota", "Kappa", "Lambda", "Mu", "Nu", "Xi", "Omicron", "Pi", "Rho", "Sigma", "Tau", "Upsilon", "Phi", "Chi", "Psi", "Omega"}; typedef vector PlayerVecT; void MakePlayers(PlayerVecT & team, int count); void PrintPlayers(const PlayerVecT & team); void PlayGame(PlayerVecT & team, int rounds); string GetName(void); string MakeName( int nameCount); int main() { vector theTeam; srand(static_cast(time(nullptr))); MakePlayers(theTeam, 10); cout << "Before the game " << endl; PrintPlayers(theTeam); cout << endl << endl; PlayGame(theTeam, 2); cout << endl; cout << "After the game: " << endl; PrintPlayers(theTeam); for (auto x: theTeam) { delete x; } return 0; } void PlayGame(PlayerVecT & team, int rounds){ int round; int current; current = static_cast (rand() % team.size()); for(round = 1; round <= rounds; round++) { cout << "Round " << round << endl; team[current]->Catch(); cout <<"\t" << team[current]->GetName() << " catches the ball." << endl; cout << "\tThey toss " << team[current]->TossType(); current = team[current]->Toss(); cout << " to " << team[current]->GetName() << " at position " << current + 1 << endl; cout << endl; } } void MakePlayers(PlayerVecT & team, int count){ int i; PlayerT * player; bool lastWasRight{false}; string name; for(i = 0; i < count; i++) { name = MakeName(rand() % 3+1); switch (rand() % TYPES) { case 0: case 1: if (!lastWasRight) { player = new LeftPlayerT (name, team); lastWasRight = false; break; } [[fallthrough]]; case 2: case 3: player = new RightPlayerT (name, team); lastWasRight = true; break; default: lastWasRight = false; player = new RandPlayerT (name, team); } team.push_back(player); } } void PrintPlayers(const PlayerVecT & team){ for (auto x: team) { cout << "\t" << x->GetName () << " had the ball " << x->GetCount() << " times." << endl; } } string MakeName( int nameCount) { string name = GetName(); int i; for(i =1; i < nameCount; i++) { name += " " + GetName(); } return name; } string GetName() { return NAMES[rand() % NAMES.size()]; }