diff options
-rw-r--r-- | blarandom.cpp | 72 |
1 files changed, 69 insertions, 3 deletions
diff --git a/blarandom.cpp b/blarandom.cpp index 2a6136b..4099d0b 100644 --- a/blarandom.cpp +++ b/blarandom.cpp @@ -23,6 +23,9 @@ v0.1 - Initial release v0.2 - Added Makefile v0.3 - Added help + v0.31 - Changed help description + v0.4 - Added coin & dice presets + v0.5 - Added 8ball preset */ @@ -35,7 +38,7 @@ int main() { - std::string version = "0.2"; + std::string version = "0.5"; RandomLib::Random r; // Create r r.Reseed(); // and give it a unique seed @@ -61,7 +64,7 @@ int main() { } if (!args[0].compare("-h") || !args[0].compare("--help")) { - std::cout << "Usage: !random [minimum bound] [maximum bound] [count] | Examples: !random : returns a number from 1 to 10 | !random 20 : Returns a number from 1 to 20 | !random 10 20 : Returns a number from 10 to 20 | !random 1 10 3 : Returns 3 random numbers from 1 to 10" << std::endl; + std::cout << "Usage: !random [minimum bound] [maximum bound] [count] | Examples: !random : returns a number from 1 to 10 inclusive | !random 20 : Returns a number from 1 to 20 inclusive | !random 10 20 : Returns a number from 10 to 20 inclusive | !random 1 10 3 : Returns 3 random numbers from 1 to 10 inclusive" << std::endl; return 0; } @@ -80,13 +83,76 @@ int main() { min = atoi(args[0].c_str()); } + bool coin = false; + bool letter = false; + bool eightball = false; + if (args[0].empty()) { min = 1; max = 10; + } else if (!args[0].compare("dice")) { + min = 1; + max = 6; + } else if (!args[0].compare("coin")) { + min = 0; + max = 1; + coin = true; + } else if (!args[0].compare("d20")) { + min = 1; + max = 20; + } else if (!args[0].compare("letter")) { + min = 1; + max = 26; + letter = true; + } else if (!args[0].compare("8ball")) { + min = 0; + max = 17; + eightball = true; } + int intResult = 0; + std::string strResult = ""; + char letters[26] = { 'A','B','C','D','E','F','G','H','I','J','K', + 'L','M','N','O','P','Q','R','S','T','U','V', + 'W','X','Y','Z' }; + std::string eightBallStr[18] = { "Yes.", + "No.", + "Outlook so so.", + "Absolutely.", + "My sources say no.", + "Yes definitely.", + "Very doubtful.", + "Most likely.", + "Forget about it.", + "Are you kidding?", + "Go for it.", + "Not now.", + "Looking good.", + "Who knows.", + "A definite yes.", + "You will have to wait.", + "Yes, in due time.", + "I have my doubts." }; + for (int i = 0; i < count; i++) { - std::cout << r.IntegerC(min, max) << " "; + intResult = r.IntegerC(min, max); + if (coin) { + if (intResult == 1) { + strResult = "H"; + } else { + strResult = "T"; + } + } else if (letter) { + strResult = letters[intResult]; + } else if (eightball) { + strResult = eightBallStr[intResult]; + } else { + std::stringstream ss; + ss << intResult; + strResult = ss.str(); + } + std::cout << strResult << " "; + } std::cout << std::endl; |