|
@ -11,27 +11,27 @@ void schereSteinPapier() |
|
|
"Gibst du bei der Aufforderung 0 ein, gelangst du zurueck ins Hauptmenue!\n\n"); |
|
|
"Gibst du bei der Aufforderung 0 ein, gelangst du zurueck ins Hauptmenue!\n\n"); |
|
|
while(1) |
|
|
while(1) |
|
|
{ |
|
|
{ |
|
|
int com, user; |
|
|
|
|
|
|
|
|
int comChoice, userChoice; |
|
|
printf("Bitte treffe deine Wahl!\n" |
|
|
printf("Bitte treffe deine Wahl!\n" |
|
|
"1: Schere \n2: Stein \n3: Papier\n0: Spiel verlassen\n"); |
|
|
"1: Schere \n2: Stein \n3: Papier\n0: Spiel verlassen\n"); |
|
|
scanf("%d", &user); |
|
|
|
|
|
if(user == 0) |
|
|
|
|
|
|
|
|
scanf("%d", &userChoice); |
|
|
|
|
|
if(userChoice == 0) |
|
|
{ |
|
|
{ |
|
|
printf("Vielen Dank fürs Spielen! Tschau!\n"); |
|
|
|
|
|
|
|
|
printf("Vielen Dank fuers Spielen! Tschau!\n"); |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
else if(user == 1 || user == 2 || user == 3) |
|
|
|
|
|
|
|
|
else if(userChoice == 1 || userChoice == 2 || userChoice == 3) |
|
|
{ |
|
|
{ |
|
|
srand(time(NULL)); |
|
|
srand(time(NULL)); |
|
|
com = rand() % 3 + 1; |
|
|
|
|
|
int win = calculateWinner(user, com); |
|
|
|
|
|
switch (win) |
|
|
|
|
|
|
|
|
comChoice = rand() % 3 + 1; |
|
|
|
|
|
int winNum = calculateWinner(userChoice, comChoice); |
|
|
|
|
|
switch (winNum) |
|
|
{ |
|
|
{ |
|
|
case(-1):printf("Der Computer hat %d gewaehlt, Du hast verloren!!!\n\n", com); |
|
|
|
|
|
|
|
|
case(-1):printf("Der Computer hat %d gewaehlt, Du hast verloren!!!\n\n", comChoice); |
|
|
break; |
|
|
break; |
|
|
case(0): printf("Der Computer hat %d gewaehlt, Es steht unentschieden!!!\n\n", com); |
|
|
|
|
|
|
|
|
case(0): printf("Der Computer hat %d gewaehlt, Es steht unentschieden!!!\n\n", comChoice); |
|
|
break; |
|
|
break; |
|
|
case(1): printf("Der Computer hat %d gewaehlt, Du hast gewonnen!!!\n\n", com); |
|
|
|
|
|
|
|
|
case(1): printf("Der Computer hat %d gewaehlt, Du hast gewonnen!!!\n\n", comChoice); |
|
|
break; |
|
|
break; |
|
|
default: printf("Error!"); |
|
|
default: printf("Error!"); |
|
|
} |
|
|
} |
|
@ -44,14 +44,14 @@ void schereSteinPapier() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//Berechnung,welche Auswahl gewinnt. |
|
|
//Berechnung,welche Auswahl gewinnt. |
|
|
//@return: 0 = unentschieden; 1 = gewonnen; -1 = verloren; 3 = Fehler bei der Wertübergabe |
|
|
|
|
|
//@param x = UserChoice; y = COMChoice |
|
|
|
|
|
int calculateWinner(int x, int y) |
|
|
|
|
|
|
|
|
//@return: 0 = unentschieden; 1 = gewonnen; -1 = verloren; 3 = Fehler bei der Wertuebergabe |
|
|
|
|
|
//@param userSelection = UserChoice; comSelection = COMChoice |
|
|
|
|
|
int calculateWinner(int userSelection, int comSelection) |
|
|
{ |
|
|
{ |
|
|
switch (x) |
|
|
|
|
|
|
|
|
switch (userSelection) |
|
|
{ |
|
|
{ |
|
|
case(1): |
|
|
case(1): |
|
|
switch (y) { |
|
|
|
|
|
|
|
|
switch (comSelection) { |
|
|
case(1): return 0; |
|
|
case(1): return 0; |
|
|
|
|
|
|
|
|
case(2): return -1; |
|
|
case(2): return -1; |
|
@ -61,7 +61,7 @@ int calculateWinner(int x, int y) |
|
|
default: return 3; |
|
|
default: return 3; |
|
|
} |
|
|
} |
|
|
case(2): |
|
|
case(2): |
|
|
switch (y) { |
|
|
|
|
|
|
|
|
switch (comSelection) { |
|
|
case(1): return 1; |
|
|
case(1): return 1; |
|
|
|
|
|
|
|
|
case(2): return 0; |
|
|
case(2): return 0; |
|
@ -71,7 +71,7 @@ int calculateWinner(int x, int y) |
|
|
default: return 3; |
|
|
default: return 3; |
|
|
} |
|
|
} |
|
|
case(3): |
|
|
case(3): |
|
|
switch (y) { |
|
|
|
|
|
|
|
|
switch (comSelection) { |
|
|
case(1): return -1; |
|
|
case(1): return -1; |
|
|
|
|
|
|
|
|
case(2): return 1; |
|
|
case(2): return 1; |
|
|