From 73c1a9dfc181a21228ebbc41d229409d91ae3421 Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Fri, 29 Sep 2023 07:52:12 +0200 Subject: [PATCH] Created the rpc.cpp --- rpc.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 rpc.cpp diff --git a/rpc.cpp b/rpc.cpp new file mode 100644 index 0000000..03ea36f --- /dev/null +++ b/rpc.cpp @@ -0,0 +1,43 @@ +#include + +using namespace std; + +int getIdByText(string text) { + return text == "Schere" ? 1 : text == "Stein" ? 2 : text == "Papier" ? 3 : 0; +} + +string getTextById(int id) { + return id == 1 ? "Schere" : id == 2 ? "Stein" : id == 3 ? "Papier" : "Nichts"; +} + +int main() { + srand((unsigned) time(NULL)); + + int random = rand() % 3 + 1; + + cout << "Was möchtest du spielen? [Schere/Stein/Papier]: "; + + string choice; + cin >> choice; + + int num = getIdByText(choice); + + if (num == 0) return main(); + + if (random == num) { + cout << "Unentschieden, ich habe mich auch für " << choice << " entschieden"; + } else if ((random == 1 && num == 3) || (random == 2 && num == 1) || (random == 3 && num == 2)) { + cout << "Ich habe gewonnen!. Ich hatte mich für " << getTextById(random) << " entschieden."; + } else { + cout << "Glückwunsch! " << choice << " hat mich geschlagen. Ich hatte " << getTextById(random); + } + + cout << "\nNochmal? [Ja/Nein] "; + + string again; + cin >> again; + + if (again == "Ja" || again == "ja") return main(); + + return 0; +} \ No newline at end of file