#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(); int main() { srand(static_cast(time(nullptr))); ResultT i; int j; for(i = FIRST_RESULT; i < ResultT::UNKNOWN; i =NextResultT(i)) { cout << static_cast(i) << setw(20) << ResultTToString(i) << endl; } cout << endl; cout << endl; cout << "Some random results" << RESULT_RANGE << endl; for(j = 0; j < 130; j++) { i = RollDie(); cout << ResultTToString(i) << endl; } return 0; } 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; }