From c9ea847dba26759f7f154f9191ec542bbf1e95a7 Mon Sep 17 00:00:00 2001 From: jstmax! <87650746+jstmaxlol@users.noreply.github.com> Date: Fri, 7 Mar 2025 19:44:59 +0100 Subject: Yes, I am just creating beginner-friendly stupid cli programs to chill --- rockPaperScissorsCLI.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 rockPaperScissorsCLI.cpp (limited to 'rockPaperScissorsCLI.cpp') diff --git a/rockPaperScissorsCLI.cpp b/rockPaperScissorsCLI.cpp new file mode 100644 index 0000000..11d1960 --- /dev/null +++ b/rockPaperScissorsCLI.cpp @@ -0,0 +1,63 @@ +#include +#include +// scuffed rock/paper/scissors cli game +int convertUserMoveToInt(char& user); +char returnRoundResult(int& user, int& cpu); +void clearScreen(); +int main() { + clearScreen(); + std::cout << "welcome to RockPaperScissorsCLI\n\n"; + + int userScore = 0, cpuScore = 0; + while (true) { + char userMove; + std::cout << "[ rpsCLI / scoreboard ]\n" + << "[ user="<> userMove; + if (userMove == 'Q' || userMove == 'q') return 0; + int userMoveCorr = convertUserMoveToInt(userMove); + + int cpuMove = 1 + (rand() % 3); + + char round = returnRoundResult(userMoveCorr, cpuMove); + + clearScreen(); + if (round == 'w') { + ++userScore; + std::cout << "[ user won! ]\n\n"; + } else if (round == 'l') { + ++cpuScore; + std::cout << "[ cpu won! ]\n\n"; + } else if (round == 'd') { + std::cout << "[ it's a draw! ]\n\n"; + } + } +} +int convertUserMoveToInt(char& user) { + if (user == 'R' || user == 'r') return 1; + if (user == 'P' || user == 'p') return 2; + if (user == 'S' || user == 's') return 3; + else return -1; +} +char returnRoundResult(int& user, int& cpu) { + if (user == cpu) return 'd'; + + if (user == 1 && cpu == 2) return 'l'; + if (user == 1 && cpu == 3) return 'w'; + + if (user == 2 && cpu == 1) return 'w'; + if (user == 2 && cpu == 3) return 'l'; + + if (user == 3 && cpu == 1) return 'l'; + if (user == 3 && cpu == 2) return 'w'; + + else return 'E'; +} +#ifdef __WIN32 +void clearScreen() {system("cls");} +#endif +#ifdef __unix +void clearScreen() {system("clear");} +#endif -- cgit v1.3.1