diff --git a/src/main/c/Tim/SchereSteinPapier.c b/src/main/c/Tim/SchereSteinPapier.c index 72d76fc..6862522 100644 --- a/src/main/c/Tim/SchereSteinPapier.c +++ b/src/main/c/Tim/SchereSteinPapier.c @@ -17,13 +17,24 @@ void schereSteinPapier() scanf("%d", &user); if(user == 0) { + printf("Vielen Dank fürs Spielen! Tschau!\n"); break; } else if(user == 1 || user == 2 || user == 3) { srand(time(NULL)); com = rand() % 3 + 1; - printf("%d\n",com); + int win = calculateWinner(user, com); + switch (win) + { + case(-1):printf("Der Computer hat %d gewaehlt, Du hast verloren!!!\n\n", com); + break; + case(0): printf("Der Computer hat %d gewaehlt, Es steht unentschieden!!!\n\n", com); + break; + case(1): printf("Der Computer hat %d gewaehlt, Du hast gewonnen!!!\n\n", com); + break; + default: printf("Error!"); + } } else { @@ -31,3 +42,41 @@ void schereSteinPapier() } } } + + +int calculateWinner(int x, int y) +{ + switch (x) + { + case(1): + switch (y) { + case(1): return 0; + + case(2): return -1; + + case(3): return 1; + + default: return 3; + } + case(2): + switch (y) { + case(1): return 1; + + case(2): return 0; + + case(3): return -1; + + default: return 3; + } + case(3): + switch (y) { + case(1): return 1; + + case(2): return -1; + + case(3): return 0; + + default: return 3; + } + } +} \ No newline at end of file diff --git a/src/main/c/Tim/SchereSteinPapier.h b/src/main/c/Tim/SchereSteinPapier.h index 35c884b..a96c9f9 100644 --- a/src/main/c/Tim/SchereSteinPapier.h +++ b/src/main/c/Tim/SchereSteinPapier.h @@ -2,5 +2,6 @@ #define SCHERESTEINPAPIER_H void schereSteinPapier(); +int calculateWinner(int, int); #endif