Created the rpc.cpp

This commit is contained in:
Mathias Wagner 2023-09-29 07:52:12 +02:00
parent 4c33528156
commit 73c1a9dfc1
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

43
rpc.cpp Normal file
View File

@ -0,0 +1,43 @@
#include <iostream>
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;
}