From 4411a4b1e66f0074f6768a3d6209ee0145ea1417 Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 19:06:32 +0100 Subject: [PATCH] =?UTF-8?q?refactoring:=20Verst=C3=A4ndlichere=20Benennung?= =?UTF-8?q?=20einiger=20Variablen:=20in=20schereSteinPapier():=20user->use?= =?UTF-8?q?rChoice,=20com->comChoice,=20win->winNum;=20formale=20Variable?= =?UTF-8?q?=20in=20calculateWinner():=20x->userSelection,=20y->comSelectio?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Tim/SchereSteinPapier.c | 36 +++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/main/c/Tim/SchereSteinPapier.c b/src/main/c/Tim/SchereSteinPapier.c index 12b9735..a0c9509 100644 --- a/src/main/c/Tim/SchereSteinPapier.c +++ b/src/main/c/Tim/SchereSteinPapier.c @@ -11,27 +11,27 @@ void schereSteinPapier() "Gibst du bei der Aufforderung 0 ein, gelangst du zurueck ins Hauptmenue!\n\n"); while(1) { - int com, user; + int comChoice, userChoice; printf("Bitte treffe deine Wahl!\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; } - else if(user == 1 || user == 2 || user == 3) + else if(userChoice == 1 || userChoice == 2 || userChoice == 3) { 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; - 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; - 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; default: printf("Error!"); } @@ -44,14 +44,14 @@ void schereSteinPapier() } //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): - switch (y) { + switch (comSelection) { case(1): return 0; case(2): return -1; @@ -61,7 +61,7 @@ int calculateWinner(int x, int y) default: return 3; } case(2): - switch (y) { + switch (comSelection) { case(1): return 1; case(2): return 0; @@ -71,7 +71,7 @@ int calculateWinner(int x, int y) default: return 3; } case(3): - switch (y) { + switch (comSelection) { case(1): return -1; case(2): return 1;