#include #include #include #include #include "MyUtil.h" #include "ResultT.h" using namespace std; ResultT RollDie(); enum class StatusT { SANE, INSANE, UNKNOWN}; const StatusT FIRST_STATUS = StatusT::SANE; string StatusTToString(StatusT status); StatusT Next(StatusT status); const int MAX_SANITY = 18; const int START_SANITY = 3; struct NameT { string first; string last; string title; }; void PrintName(NameT name); void GetName(NameT & name); struct PlayerT { NameT name; int sanity; StatusT status; }; void PrintPlayer(PlayerT player); PlayerT GetPlayer(int & cthulhu); const size_t MAX_PLAYERS = 4; void GetPlayers(PlayerT team[MAX_PLAYERS], int & cthulhu); void PrintPlayers(const PlayerT team[MAX_PLAYERS]); void Battle(PlayerT & attacker, PlayerT & victim, int & chtulhu); int main() { int cthulhu = MAX_SANITY; PlayerT players[MAX_PLAYERS]; GetPlayers(players, cthulhu); PrintPlayers(players); return 0; } void GetPlayers(PlayerT team[MAX_PLAYERS], int & cthulhu){ size_t i; for(i =0; i < MAX_PLAYERS; i++) { cout << "Enter the information for player " << i << endl; team[i] = GetPlayer(cthulhu); cout << endl; } return; } void PrintPlayers(const PlayerT team[MAX_PLAYERS]){ size_t i; for(i =0; i < MAX_PLAYERS; i++) { cout << "Player " << i << endl; PrintPlayer(team[i]); cout << endl; } return; } void PrintName(NameT name){ if (name.title != "") { cout << name.title << " "; } cout << name.first; if (name.last != "") { cout << " " << name.last; } return; } void GetName(NameT & name){ cout << "Enter your title (or just return if you don't have a title): "; getline(cin,name.title); cout << "Enter your first name (or your name if you only have one): "; getline(cin, name.first); cout << "Enter your last name (or just return if you don't have a last name): "; getline(cin, name.last); } void PrintPlayer(PlayerT player){ // the name cout << "Name:" ; PrintName(player.name); cout << endl; cout << "Sanity: " << player.sanity << endl; cout << "Status: " << StatusTToString(player.status) << endl; return; } void Battle(PlayerT & attacker, PlayerT & victim, int & chtulhu){ } PlayerT GetPlayer(int & cthulhu){ PlayerT player; GetName(player.name); player.sanity = START_SANITY; cthulhu -= START_SANITY; player.status = StatusT::SANE; return player; } string StatusTToString(StatusT status){ string result; switch (status) { case StatusT::SANE: result = "Sane"; break; case StatusT::INSANE: result = "Insane"; break; case StatusT::UNKNOWN: default: result = "UNKNOWN"; break; } return result; } StatusT Next(StatusT status){ StatusT result = StatusT::UNKNOWN; if (status < StatusT::UNKNOWN) { result = static_cast(static_cast(status) + 1); } return result; } ResultT RollDie(){ ResultT result = ResultT::UNKNOWN; int roll; roll = rand() % 12; if (roll < 5) { result = ResultT::YELLOW_SIGN; } else if (roll < 9) { result = ResultT::TENTACLE; } else if (roll == 9) { result = ResultT::ELDER_SIGN; } else if (roll == 10) { result = ResultT::CTHULHU; } else if (roll == 11) { result = ResultT::EYE; } else { result = ResultT::UNKNOWN; } return result; }