#include #include #include #include using namespace std; enum class ResultT:unsigned char {YELLOW_SIGN, TENTACLE, ELDER_SIGN, CTHULHU, EYE, UNKNOWN}; const ResultT FIRST_RESULT = ResultT::YELLOW_SIGN; const size_t RESULT_RANGE = static_cast(ResultT::UNKNOWN) - static_cast(ResultT::YELLOW_SIGN); string ResultTToString(ResultT value); ResultT NextResultT(ResultT value); string MakeUpper(string value); ResultT StringToResultT(string value); 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 Battle(PlayerT & attacker, PlayerT & victim, int & chtulhu); void ReadPlayers(PlayerT thePlayers[MAX_PLAYERS], int & cthulhu); void PrintPlayers(const PlayerT group[]); int main() { int cthulhu = MAX_SANITY; PlayerT players[MAX_PLAYERS]; ReadPlayers(players, cthulhu); PrintPlayers(players); return 0; } void PrintPlayers(const PlayerT group[]){ size_t i{0}; for(i=0; i < MAX_PLAYERS; i++) { PrintPlayer(group[i]); } return; } void ReadPlayers(PlayerT thePlayers[MAX_PLAYERS], int & cthulhu){ size_t i; for(i = 0; i < MAX_PLAYERS; i++) { thePlayers[i] = GetPlayer(cthulhu); } 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 NextResultT(ResultT value) { ResultT result = ResultT::UNKNOWN; if (value != ResultT::UNKNOWN) { result = static_cast(static_cast(value) + 1) ; } return result; } string ResultTToString(ResultT value) { string result; switch (value) { case ResultT::YELLOW_SIGN: result = "Yellow Sign"; break; case ResultT::TENTACLE: result = "Tentacle"; break; case ResultT::ELDER_SIGN: result = "Elder Sign"; break; case ResultT::CTHULHU: result = "Cthulhu"; break; case ResultT::EYE: result = "EYE"; break; case ResultT::UNKNOWN: [[fallthrough]]; default: result = "Unknown Result"; } return result; } string MakeUpper(string value) { size_t i; for(i = 0; i < value.size(); i++) { value[i] = static_cast(toupper(value[i])); } return value; } ResultT StringToResultT(string value){ value = MakeUpper(value); ResultT result = ResultT::UNKNOWN; if (value == "YELLOW SIGN") { result = ResultT::YELLOW_SIGN; } else if (value == "TENTACLE") { result = ResultT::TENTACLE; } else if (value == "ELDER SIGN") { result = ResultT::ELDER_SIGN; } else if (value == "CTHULHU") { result = ResultT::CTHULHU; } else if (value == "EYE") { result = ResultT::EYE; } 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; }