From 13067a097c463aeba1a07bf328288a25a4405f1d Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 19:38:22 +0100 Subject: [PATCH 01/61] Empfangsnachricht von Hangman + Implementation des gameloops --- src/main/c/Tim/hangman.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index d49319b..e0417d1 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -1,7 +1,19 @@ #include "hangman.h" #include + void hangman() { - printf("Hello World!"); + char userSelection; + printf("Willkommen bei Hangman!!!\n" + "Per Zufall wird jede Runde ein Wort aus einem Pool ausgewaehlt. Gebe einen Buchstaben ein, von dem du vermutest,\ndass er in dem gesuchten Wort ist, sobald die Konsole dich dazu auffordert.\n" + "Fuer jede falsche Antwort kommst du dem Tod immer naeher, also waehle weise!\n" + "Mit der Auswahl 0 kommst du zurueck ins Hauptmenue\n\n"); + + do + { + printf("Bitte gib einen Buchstaben ein!\n"); + scanf(" %c", &userSelection); + printf("%c\n", userSelection); + }while(userSelection != '0'); } From 3b1b6bfc319bbb34b4386ac18978014aaff9d3ab Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 19:39:21 +0100 Subject: [PATCH 02/61] =?UTF-8?q?Hinzuf=C3=BCgen=20der=20Liste=20der=20m?= =?UTF-8?q?=C3=B6glichen=20W=C3=B6rtern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Tim/hangman.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index e0417d1..81fa8ce 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -1,5 +1,12 @@ #include "hangman.h" #include +#include + +char wordlist[10][30] = { + "Kartoffel", "Zigarette", "Haus", "Fenster", "Kartenleseettiketiergerät", + "Kleiderschrank", "Schnee","Wasserhahn", + "Fernbedienung", "Computertastatur" +}; void hangman() From b945065a1a00784d55b5544e510d367aa75e1f1c Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 19:40:48 +0100 Subject: [PATCH 03/61] Implementation der Zufallsauswahl des gesuchten Wortes aus der Liste --- src/main/c/Tim/hangman.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index 81fa8ce..6704dee 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -1,9 +1,11 @@ #include "hangman.h" #include #include +#include +#include char wordlist[10][30] = { - "Kartoffel", "Zigarette", "Haus", "Fenster", "Kartenleseettiketiergerät", + "Kartoffel", "Zigarette", "Haus", "Fenster", "Kartenleseettiketiergeraet", "Kleiderschrank", "Schnee","Wasserhahn", "Fernbedienung", "Computertastatur" }; @@ -11,6 +13,7 @@ char wordlist[10][30] = { void hangman() { + srand(time(NULL)); char userSelection; printf("Willkommen bei Hangman!!!\n" "Per Zufall wird jede Runde ein Wort aus einem Pool ausgewaehlt. Gebe einen Buchstaben ein, von dem du vermutest,\ndass er in dem gesuchten Wort ist, sobald die Konsole dich dazu auffordert.\n" @@ -19,6 +22,13 @@ void hangman() do { + char guessWord[30]; + int length; + strcpy(guessWord,wordlist[rand() % 10]); + length = strlen(guessWord); + printf("%s %d\n",guessWord, length); + + printf("Bitte gib einen Buchstaben ein!\n"); scanf(" %c", &userSelection); printf("%c\n", userSelection); From 0ace76ce85a17b25edcf0863396d33fa43172585 Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 19:42:01 +0100 Subject: [PATCH 04/61] =?UTF-8?q?Hinzuf=C3=BCgen=20des=20Displaywortes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Tim/hangman.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index 6704dee..df569e2 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -23,11 +23,23 @@ void hangman() do { char guessWord[30]; + char displayWord[30]; int length; strcpy(guessWord,wordlist[rand() % 10]); length = strlen(guessWord); printf("%s %d\n",guessWord, length); - + for (int i = 0; i <= length; i++) + { + if(i Date: Thu, 25 Jan 2024 19:43:28 +0100 Subject: [PATCH 05/61] refactoring: Definition der konstanten Variablen LISTSIZE MAX_WORD_LENGTH und ersetzen an den jeweiligen Stellen --- src/main/c/Tim/hangman.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index df569e2..0e63451 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -4,7 +4,10 @@ #include #include -char wordlist[10][30] = { +#define LISTSIZE 10 +#define MAX_WORD_LENGTH 30 + +char wordlist[LISTSIZE][MAX_WORD_LENGTH] = { "Kartoffel", "Zigarette", "Haus", "Fenster", "Kartenleseettiketiergeraet", "Kleiderschrank", "Schnee","Wasserhahn", "Fernbedienung", "Computertastatur" @@ -22,10 +25,10 @@ void hangman() do { - char guessWord[30]; - char displayWord[30]; + char guessWord[MAX_WORD_LENGTH]; + char displayWord[MAX_WORD_LENGTH]; int length; - strcpy(guessWord,wordlist[rand() % 10]); + strcpy(guessWord,wordlist[rand() % LISTSIZE]); length = strlen(guessWord); printf("%s %d\n",guessWord, length); for (int i = 0; i <= length; i++) From b97858be05409df3c6e064206652d402c76c5c95 Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 19:44:33 +0100 Subject: [PATCH 06/61] =?UTF-8?q?refactoring:=20Auslagern=20von=20Funktion?= =?UTF-8?q?alit=C3=A4t=20um=20einen=20return-Wert=20f=C3=BCr=20Test=20zu?= =?UTF-8?q?=20erhalten=20+=20Separieren=20der=20Variablendeklaration=20von?= =?UTF-8?q?=20guessWord=20und=20displayWord=20f=C3=BCr=20erh=C3=B6hte=20?= =?UTF-8?q?=C3=9Cbersichtlichkeit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Tim/hangman.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index 0e63451..974f5b6 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -6,6 +6,8 @@ #define LISTSIZE 10 #define MAX_WORD_LENGTH 30 +char* getWordFromList(int); +int getParameters(int, char*); char wordlist[LISTSIZE][MAX_WORD_LENGTH] = { "Kartoffel", "Zigarette", "Haus", "Fenster", "Kartenleseettiketiergeraet", @@ -26,11 +28,12 @@ void hangman() do { char guessWord[MAX_WORD_LENGTH]; - char displayWord[MAX_WORD_LENGTH]; int length; - strcpy(guessWord,wordlist[rand() % LISTSIZE]); + strcpy(guessWord,getWordFromList(rand() % LISTSIZE)); length = strlen(guessWord); printf("%s %d\n",guessWord, length); + + char displayWord[MAX_WORD_LENGTH]; for (int i = 0; i <= length; i++) { if(i Date: Thu, 25 Jan 2024 19:46:22 +0100 Subject: [PATCH 07/61] =?UTF-8?q?Implementation=20der=20Tests=20f=C3=BCr?= =?UTF-8?q?=20ein=20g=C3=BCltiges=20Parameter=20bei=20der=20Funktion=20get?= =?UTF-8?q?WordFromList?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Tim/hangman.c | 3 +-- src/main/c/Tim/hangman.h | 1 + src/test/c/Tim/test_hangman.c | 23 +++++++++++++++++++---- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index 974f5b6..33293be 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -6,8 +6,7 @@ #define LISTSIZE 10 #define MAX_WORD_LENGTH 30 -char* getWordFromList(int); -int getParameters(int, char*); + char wordlist[LISTSIZE][MAX_WORD_LENGTH] = { "Kartoffel", "Zigarette", "Haus", "Fenster", "Kartenleseettiketiergeraet", diff --git a/src/main/c/Tim/hangman.h b/src/main/c/Tim/hangman.h index cd17d02..0995129 100644 --- a/src/main/c/Tim/hangman.h +++ b/src/main/c/Tim/hangman.h @@ -2,5 +2,6 @@ #define HANGMAN_H void hangman(); +char* getWordFromList(int); #endif diff --git a/src/test/c/Tim/test_hangman.c b/src/test/c/Tim/test_hangman.c index 2afdf17..6ae6216 100644 --- a/src/test/c/Tim/test_hangman.c +++ b/src/test/c/Tim/test_hangman.c @@ -1,5 +1,6 @@ #include "hangman.h" #include "unity.h" +#include @@ -13,12 +14,26 @@ void tearDown(void) } -void test_ceedling_functionality() +void test_getWordFromList_Kartoffel_0() { //arrange - int expectedResult = 0; + int pos = 0; + char expectedResult[] = "Kartoffel"; //act - int actualResult = 0; + char actualResult[30]; + strcpy(actualResult,getWordFromList(pos)); //assert - TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); + TEST_ASSERT_EQUAL_STRING(expectedResult, actualResult); +} + +void test_getWordFromList_Kleiderschrank_5() +{ + //arrange + int pos = 5; + char expectedResult[] = "Kleiderschrank"; + //act + char actualResult[30]; + strcpy(actualResult,getWordFromList(pos)); + //assert + TEST_ASSERT_EQUAL_STRING(expectedResult, actualResult); } \ No newline at end of file From 0fb0f028215e0b0539d13a465918bcbf0333fbc9 Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 19:47:53 +0100 Subject: [PATCH 08/61] =?UTF-8?q?Test=20f=C3=BCr=20zu=20gro=C3=9Fe=20Wert?= =?UTF-8?q?=C3=BCbergabe=20bei=20getWordFromList=20+=20Anpassung=20im=20Pr?= =?UTF-8?q?oduktivCode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Tim/hangman.c | 9 ++++++++- src/test/c/Tim/test_hangman.c | 13 +++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index 33293be..0f7c94d 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -55,6 +55,13 @@ void hangman() char* getWordFromList(int x) { - return wordlist[x]; + if(x Date: Thu, 25 Jan 2024 19:49:31 +0100 Subject: [PATCH 09/61] =?UTF-8?q?Einbauen=20Abbruchbedingung,=20dass=20das?= =?UTF-8?q?=20Wort=20erraten=20wurde=20+=20Hinzuf=C3=BCgen=20der=20Testf?= =?UTF-8?q?=C3=A4lle=20f=C3=BCr=20ungleich=20und=20gleich?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Tim/hangman.c | 22 +++++++++++++++++++--- src/main/c/Tim/hangman.h | 2 ++ src/test/c/Tim/test_hangman.c | 24 +++++++++++++++++++++++- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index 0f7c94d..9af39d7 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -3,6 +3,7 @@ #include #include #include +#include #define LISTSIZE 10 #define MAX_WORD_LENGTH 30 @@ -46,9 +47,13 @@ void hangman() } printf("%s\n", displayWord); - printf("Bitte gib einen Buchstaben ein!\n"); - scanf(" %c", &userSelection); - printf("%c\n", userSelection); + while(!wordGuessed(guessWord, displayWord)) + { + printf("Bitte gib einen Buchstaben ein!\n"); + scanf(" %c", &userSelection); + printf("%c\n", userSelection); + } + }while(userSelection != '0'); } @@ -65,3 +70,14 @@ char* getWordFromList(int x) } } +bool wordGuessed(char x[], char y[]) +{ + if(strcmp(x,y) == 0) + { + return true; + } + else + { + return false; + } +} \ No newline at end of file diff --git a/src/main/c/Tim/hangman.h b/src/main/c/Tim/hangman.h index 0995129..d3160df 100644 --- a/src/main/c/Tim/hangman.h +++ b/src/main/c/Tim/hangman.h @@ -1,7 +1,9 @@ +#include #ifndef HANGMAN_H #define HANGMAN_H void hangman(); char* getWordFromList(int); +bool wordGuessed(char[],char[]); #endif diff --git a/src/test/c/Tim/test_hangman.c b/src/test/c/Tim/test_hangman.c index 074a1c5..dc449e0 100644 --- a/src/test/c/Tim/test_hangman.c +++ b/src/test/c/Tim/test_hangman.c @@ -1,6 +1,7 @@ #include "hangman.h" #include "unity.h" #include +#include @@ -49,4 +50,25 @@ void test_getWordFromList_IndexOutOfList() strcpy(actualResult,getWordFromList(pos)); //assert TEST_ASSERT_EQUAL_STRING(expectedResult, actualResult); -} \ No newline at end of file +} + +void test_wonGame_wordGuessed() +{ + //arrange + char word1[] ="Kartoffel"; + char word2[] = "Kartoffel"; + //assert + TEST_ASSERT_TRUE(wordGuessed(word1, word2)); +} + +void test_not_wordGuessed() +{ + //arrange + char word1[] ="Kartoffel"; + char word2[] ="Thunfisch"; + //assert + TEST_ASSERT_FALSE(wordGuessed(word1, word2)); +} + + + From dbd68d4a907b944ef5bfa6c29c64cca944833e6a Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 19:51:28 +0100 Subject: [PATCH 10/61] =?UTF-8?q?Schreiben=20der=20Tests=20zu=20dem=20Test?= =?UTF-8?q?fall=20Gro=C3=9F-undKleinschreibung=20unterschiedlich=20f=C3=BC?= =?UTF-8?q?r=20wordGuessed()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/c/Tim/test_hangman.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/test/c/Tim/test_hangman.c b/src/test/c/Tim/test_hangman.c index dc449e0..3701b67 100644 --- a/src/test/c/Tim/test_hangman.c +++ b/src/test/c/Tim/test_hangman.c @@ -70,5 +70,13 @@ void test_not_wordGuessed() TEST_ASSERT_FALSE(wordGuessed(word1, word2)); } +void test_wordGuessed_differentCaps() +{ + //arrange + char word1[] ="Kartoffel"; + char word2[] ="karTOFFel"; + //assert + TEST_ASSERT_FALSE(wordGuessed(word1, word2)); +} From edc3b1f2df9143139d2c0db8cb04919cb76d7e16 Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 19:53:27 +0100 Subject: [PATCH 11/61] Implementation der Funktion, dass bei passenden Buchstaben das displayWord erweitert wird. --- src/main/c/Tim/hangman.c | 27 ++++++++++++++++++++++++++- src/main/c/Tim/hangman.h | 1 + 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index 9af39d7..43949e9 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -51,7 +51,9 @@ void hangman() { printf("Bitte gib einen Buchstaben ein!\n"); scanf(" %c", &userSelection); - printf("%c\n", userSelection); + + letterGuessed(userSelection, guessWord, length, displayWord); + printf("%s\n", displayWord); } }while(userSelection != '0'); @@ -74,10 +76,33 @@ bool wordGuessed(char x[], char y[]) { if(strcmp(x,y) == 0) { + printf("Du hast gewonnen!\n"); return true; } else { return false; } +} + + +bool letterGuessed(char x, char y[], int length, char ptr[]) +{ + int counter = 0; + for(int i = 0; i0) + { + return true; + } + else + { + return false; + } + } \ No newline at end of file diff --git a/src/main/c/Tim/hangman.h b/src/main/c/Tim/hangman.h index d3160df..9819b9a 100644 --- a/src/main/c/Tim/hangman.h +++ b/src/main/c/Tim/hangman.h @@ -5,5 +5,6 @@ void hangman(); char* getWordFromList(int); bool wordGuessed(char[],char[]); +bool letterGuessed(char, char[], int, char[]); #endif From c655a092fc2146d62c2e18d8b157737ada97dbb1 Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 19:55:10 +0100 Subject: [PATCH 12/61] =?UTF-8?q?Erweiterung=20der=20Funktion=20letterGues?= =?UTF-8?q?sed(),=20sodass=20Gro=C3=9F-=20und=20Kleinschreibung=20registri?= =?UTF-8?q?ert=20wird?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Tim/hangman.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index 43949e9..951e977 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -4,6 +4,7 @@ #include #include #include +#include #define LISTSIZE 10 #define MAX_WORD_LENGTH 30 @@ -90,11 +91,38 @@ bool letterGuessed(char x, char y[], int length, char ptr[]) { int counter = 0; for(int i = 0; i0) { From cb0f5e3d5825b3a85b30a5d92a4bdcbd45b4d07d Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 19:56:30 +0100 Subject: [PATCH 13/61] =?UTF-8?q?Schreiben=20der=20Tests=20f=C3=BCr=20die?= =?UTF-8?q?=20Funktion=20letterGuessed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/c/Tim/test_hangman.c | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/test/c/Tim/test_hangman.c b/src/test/c/Tim/test_hangman.c index 3701b67..e2b04da 100644 --- a/src/test/c/Tim/test_hangman.c +++ b/src/test/c/Tim/test_hangman.c @@ -80,3 +80,46 @@ void test_wordGuessed_differentCaps() } +void test_letterGuessed_differentCaps_small_big() +{ + //arrange + char x ='F'; + char y[] ="Kartoffel"; + int length = 9; + char z[] ="_________"; + //assert + TEST_ASSERT_TRUE(letterGuessed(x,y,length,z)); +} + +void test_letterGuessed_differentCaps_big_small() +{ + //arrange + char x ='k'; + char y[] ="Kartoffel"; + int length = 9; + char z[] ="_________"; + //assert + TEST_ASSERT_TRUE(letterGuessed(x,y,length,z)); +} +void test_letterGuessed_sameCaps_small() +{ + //arrange + char x ='f'; + char y[] ="Kartoffel"; + int length = 9; + char z[] ="_________"; + //assert + TEST_ASSERT_TRUE(letterGuessed(x,y,length,z)); +} + +void test_letterGuessed_sameCaps_big() +{ + //arrange + char x ='K'; + char y[] ="Kartoffel"; + int length = 9; + char z[] ="_________"; + //assert + TEST_ASSERT_TRUE(letterGuessed(x,y,length,z)); +} + From 89b622bb643e88503d30108e300dc187cccb106a Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 19:57:28 +0100 Subject: [PATCH 14/61] refactoring: Aufteilen der Funktion letterGuessed zu bool letterGuessed und changeLetter --- src/main/c/Tim/hangman.c | 44 +++++++++++++++++++++++++++++----------- src/main/c/Tim/hangman.h | 1 + 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index 951e977..d77f46a 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -54,6 +54,7 @@ void hangman() scanf(" %c", &userSelection); letterGuessed(userSelection, guessWord, length, displayWord); + changeLetter(userSelection, guessWord, length, displayWord); printf("%s\n", displayWord); } @@ -90,6 +91,37 @@ bool wordGuessed(char x[], char y[]) bool letterGuessed(char x, char y[], int length, char ptr[]) { int counter = 0; + for(int i = 0; i0) + { + return true; + } + else + { + return false; + } + +} + + +void changeLetter(char x, char y[], int length, char ptr[]) +{ for(int i = 0; i0) - { - return true; } - else - { - return false; - } - } \ No newline at end of file diff --git a/src/main/c/Tim/hangman.h b/src/main/c/Tim/hangman.h index 9819b9a..ae68d97 100644 --- a/src/main/c/Tim/hangman.h +++ b/src/main/c/Tim/hangman.h @@ -6,5 +6,6 @@ void hangman(); char* getWordFromList(int); bool wordGuessed(char[],char[]); bool letterGuessed(char, char[], int, char[]); +void changeLetter(char, char[], int, char[]); #endif From 90f36edc96324344ee41a44829e6eb275479c8ae Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 20:33:11 +0100 Subject: [PATCH 15/61] =?UTF-8?q?Kleine=20Verbesserung=20des=20Spielverhal?= =?UTF-8?q?tens=20(Verlassen=20durch=20Taste=200=20w=C3=A4hrend=20Spiel=20?= =?UTF-8?q?und=20nur=20einmaliges=20ausprinten=20bei=20doppelvorkommenden?= =?UTF-8?q?=20Buchstaben)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Tim/hangman.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index d77f46a..8b7db3b 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -52,6 +52,10 @@ void hangman() { printf("Bitte gib einen Buchstaben ein!\n"); scanf(" %c", &userSelection); + if(userSelection == '0') + { + break; + } letterGuessed(userSelection, guessWord, length, displayWord); changeLetter(userSelection, guessWord, length, displayWord); @@ -110,6 +114,7 @@ bool letterGuessed(char x, char y[], int length, char ptr[]) } if(counter>0) { + printf("Dein gewaehlter Buchstabe %c war ein Treffer!\n", x); return true; } else @@ -135,7 +140,6 @@ void changeLetter(char x, char y[], int length, char ptr[]) { ptr[i] = x+32; } - printf("Dein gewaehlter Buchstabe %c war ein Treffer!\n", x); } } else @@ -149,7 +153,6 @@ void changeLetter(char x, char y[], int length, char ptr[]) else { ptr[i] = x; } - printf("Dein gewaehlter Buchstabe %c war ein Treffer!\n", x); } } } From e4def0a3a258310558eb52fb3f56ee90df92600d Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 20:34:49 +0100 Subject: [PATCH 16/61] =?UTF-8?q?Hinzuf=C3=BCgen=20der=20ASCII-Art=20f?= =?UTF-8?q?=C3=BCr=20die=20Hangmanfigur=20+=20Kontrolle=20durch=20=C3=BCbe?= =?UTF-8?q?rgangsfunktion=20drawHangman?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Tim/hangman.c | 63 +++++++++++++++++++++++++++++++++++++++- src/main/c/Tim/hangman.h | 1 + 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index 8b7db3b..76b825c 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -16,6 +16,58 @@ char wordlist[LISTSIZE][MAX_WORD_LENGTH] = { "Fernbedienung", "Computertastatur" }; +char hangmanStages[7][100]={ + "+---+\n" + "| |\n" + "|\n" + "|\n" + "|\n" + "|\n" + "=========\n", + "+---+\n" + "| |\n" + "| O\n" + "|\n" + "|\n" + "|\n" + "=========\n", + "+---+\n" + "| |\n" + "| O\n" + "| |\n" + "|\n" + "|\n" + "=========\n", + "+---+\n" + "| |\n" + "| O\n" + "| /|\n" + "|\n" + "|\n" + "=========\n", + "+---+\n" + "| |\n" + "| O\n" + "| /|\\\n" + "|\n" + "|\n" + "=========\n", + "+---+\n" + "| |\n" + "| O\n" + "| /|\\\n" + "| /\n" + "|\n" + "=========\n", + "+---+\n" + "| |\n" + "| O\n" + "| /|\\\n" + "| / \\\n" + "|\n" + "=========\n", +}; + void hangman() { @@ -57,7 +109,10 @@ void hangman() break; } - letterGuessed(userSelection, guessWord, length, displayWord); + if(!letterGuessed(userSelection, guessWord, length, displayWord)) + { + drawHangman(); + } changeLetter(userSelection, guessWord, length, displayWord); printf("%s\n", displayWord); } @@ -156,4 +211,10 @@ void changeLetter(char x, char y[], int length, char ptr[]) } } } +} + +void drawHangman() +{ + for(int i = 0; i<7;i++) + printf("%s", hangmanStages[i]); } \ No newline at end of file diff --git a/src/main/c/Tim/hangman.h b/src/main/c/Tim/hangman.h index ae68d97..1a66ecb 100644 --- a/src/main/c/Tim/hangman.h +++ b/src/main/c/Tim/hangman.h @@ -7,5 +7,6 @@ char* getWordFromList(int); bool wordGuessed(char[],char[]); bool letterGuessed(char, char[], int, char[]); void changeLetter(char, char[], int, char[]); +void drawHangman(); #endif From 9709a768636810cded5b48cec7c8814ee5e41020 Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 20:35:55 +0100 Subject: [PATCH 17/61] refactoring: Definieren der Konstanten STAGENUM und ASCII_ART_SIZE --- src/main/c/Tim/hangman.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index 76b825c..7db0052 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -8,6 +8,8 @@ #define LISTSIZE 10 #define MAX_WORD_LENGTH 30 +#define STAGENUM 7 +#define ASCII_ART_SIZE 1000 char wordlist[LISTSIZE][MAX_WORD_LENGTH] = { @@ -16,7 +18,7 @@ char wordlist[LISTSIZE][MAX_WORD_LENGTH] = { "Fernbedienung", "Computertastatur" }; -char hangmanStages[7][100]={ +char hangmanStages[STAGENUM][ASCII_ART_SIZE]={ "+---+\n" "| |\n" "|\n" @@ -215,6 +217,6 @@ void changeLetter(char x, char y[], int length, char ptr[]) void drawHangman() { - for(int i = 0; i<7;i++) + for(int i = 0; i Date: Thu, 25 Jan 2024 20:37:18 +0100 Subject: [PATCH 18/61] =?UTF-8?q?Hinzuf=C3=BCgen,=20dass=20der=20Hangman?= =?UTF-8?q?=20bei=20falschen=20Raten=20erweitert=20wird?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Tim/hangman.c | 14 ++++++++------ src/main/c/Tim/hangman.h | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index 7db0052..799ceba 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -84,11 +84,13 @@ void hangman() { char guessWord[MAX_WORD_LENGTH]; int length; + int countWrongGuess=0; strcpy(guessWord,getWordFromList(rand() % LISTSIZE)); length = strlen(guessWord); printf("%s %d\n",guessWord, length); char displayWord[MAX_WORD_LENGTH]; + drawHangman(countWrongGuess); for (int i = 0; i <= length; i++) { if(i Date: Thu, 25 Jan 2024 20:48:48 +0100 Subject: [PATCH 19/61] =?UTF-8?q?Entfernen=20eines=20ungenutzten=20formale?= =?UTF-8?q?n=20Parameters=20bei=20Funktion=20letterGuessed()=20und=20Hinzu?= =?UTF-8?q?f=C3=BCgen=20eines=20Counters,=20der=20die=20Anzahl=20der=20Res?= =?UTF-8?q?tversuche=20angibt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Tim/hangman.c | 7 ++++--- src/main/c/Tim/hangman.h | 2 +- src/test/c/Tim/test_hangman.c | 12 ++++-------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index 799ceba..1a52a87 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -113,9 +113,10 @@ void hangman() break; } - if(!letterGuessed(userSelection, guessWord, length, displayWord)) + if(!letterGuessed(userSelection, guessWord, length)) { countWrongGuess++; + printf("Der von dir getippte Buchstabe war falsch! Du hast noch %d Versuche.\n", 6-countWrongGuess); } changeLetter(userSelection, guessWord, length, displayWord); drawHangman(countWrongGuess); @@ -152,7 +153,7 @@ bool wordGuessed(char x[], char y[]) } -bool letterGuessed(char x, char y[], int length, char ptr[]) +bool letterGuessed(char x, char y[], int length) { int counter = 0; for(int i = 0; i0) { - printf("Dein gewaehlter Buchstabe %c war ein Treffer!\n", x); + printf("Dein gewaehlter Buchstabe %c war ein Treffer! Du hast noch %d Versuche.\n", x); return true; } else diff --git a/src/main/c/Tim/hangman.h b/src/main/c/Tim/hangman.h index a258422..9a47b14 100644 --- a/src/main/c/Tim/hangman.h +++ b/src/main/c/Tim/hangman.h @@ -5,7 +5,7 @@ void hangman(); char* getWordFromList(int); bool wordGuessed(char[],char[]); -bool letterGuessed(char, char[], int, char[]); +bool letterGuessed(char, char[], int); void changeLetter(char, char[], int, char[]); void drawHangman(int); diff --git a/src/test/c/Tim/test_hangman.c b/src/test/c/Tim/test_hangman.c index e2b04da..757ed29 100644 --- a/src/test/c/Tim/test_hangman.c +++ b/src/test/c/Tim/test_hangman.c @@ -86,9 +86,8 @@ void test_letterGuessed_differentCaps_small_big() char x ='F'; char y[] ="Kartoffel"; int length = 9; - char z[] ="_________"; //assert - TEST_ASSERT_TRUE(letterGuessed(x,y,length,z)); + TEST_ASSERT_TRUE(letterGuessed(x,y,length)); } void test_letterGuessed_differentCaps_big_small() @@ -97,9 +96,8 @@ void test_letterGuessed_differentCaps_big_small() char x ='k'; char y[] ="Kartoffel"; int length = 9; - char z[] ="_________"; //assert - TEST_ASSERT_TRUE(letterGuessed(x,y,length,z)); + TEST_ASSERT_TRUE(letterGuessed(x,y,length)); } void test_letterGuessed_sameCaps_small() { @@ -107,9 +105,8 @@ void test_letterGuessed_sameCaps_small() char x ='f'; char y[] ="Kartoffel"; int length = 9; - char z[] ="_________"; //assert - TEST_ASSERT_TRUE(letterGuessed(x,y,length,z)); + TEST_ASSERT_TRUE(letterGuessed(x,y,length)); } void test_letterGuessed_sameCaps_big() @@ -118,8 +115,7 @@ void test_letterGuessed_sameCaps_big() char x ='K'; char y[] ="Kartoffel"; int length = 9; - char z[] ="_________"; //assert - TEST_ASSERT_TRUE(letterGuessed(x,y,length,z)); + TEST_ASSERT_TRUE(letterGuessed(x,y,length)); } From ccf87e12cf994d48dc2702ef84bf34c4fa7043fc Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 20:52:12 +0100 Subject: [PATCH 20/61] Einbau der Abbruchbedingung bei zu viel falschen Tipps --- src/main/c/Tim/hangman.c | 25 ++++++++++++++++++------- src/main/c/Tim/hangman.h | 1 + 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index 1a52a87..ab0255d 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -104,20 +104,20 @@ void hangman() } printf("\n\n%s\n", displayWord); - while(!wordGuessed(guessWord, displayWord)) + while(1) { printf("Bitte gib einen Buchstaben ein!\n"); scanf(" %c", &userSelection); - if(userSelection == '0') - { - break; - } if(!letterGuessed(userSelection, guessWord, length)) { countWrongGuess++; printf("Der von dir getippte Buchstabe war falsch! Du hast noch %d Versuche.\n", 6-countWrongGuess); } + if(userSelection == '0'||wordGuessed(guessWord, displayWord)||noTrysLeft(countWrongGuess)) + { + break; + } changeLetter(userSelection, guessWord, length, displayWord); drawHangman(countWrongGuess); printf("\n\n%s\n", displayWord); @@ -152,7 +152,6 @@ bool wordGuessed(char x[], char y[]) } } - bool letterGuessed(char x, char y[], int length) { int counter = 0; @@ -185,7 +184,6 @@ bool letterGuessed(char x, char y[], int length) } - void changeLetter(char x, char y[], int length, char ptr[]) { for(int i = 0; i Date: Thu, 25 Jan 2024 20:55:17 +0100 Subject: [PATCH 21/61] =?UTF-8?q?refactoring:=20Einf=C3=BChren=20der=20kon?= =?UTF-8?q?stanten=20Variable=20POSSIBLE=5FTRYS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Tim/hangman.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index ab0255d..62f28ff 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -10,6 +10,7 @@ #define MAX_WORD_LENGTH 30 #define STAGENUM 7 #define ASCII_ART_SIZE 1000 +#define POSSIBLE_TRYS 6 char wordlist[LISTSIZE][MAX_WORD_LENGTH] = { @@ -87,7 +88,6 @@ void hangman() int countWrongGuess=0; strcpy(guessWord,getWordFromList(rand() % LISTSIZE)); length = strlen(guessWord); - printf("%s %d\n",guessWord, length); char displayWord[MAX_WORD_LENGTH]; drawHangman(countWrongGuess); @@ -112,7 +112,7 @@ void hangman() if(!letterGuessed(userSelection, guessWord, length)) { countWrongGuess++; - printf("Der von dir getippte Buchstabe war falsch! Du hast noch %d Versuche.\n", 6-countWrongGuess); + printf("Der von dir getippte Buchstabe war falsch! Du hast noch %d Versuche.\n", POSSIBLE_TRYS-countWrongGuess); } if(userSelection == '0'||wordGuessed(guessWord, displayWord)||noTrysLeft(countWrongGuess)) { @@ -224,7 +224,7 @@ void drawHangman(int x) bool noTrysLeft(int x) { - if(x == 6) + if(x == POSSIBLE_TRYS) { printf("Du hast verloren!\n\n"); return true; From 72cd0c6b44831a3749992ba0c7c66f9e543d8210 Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 20:57:49 +0100 Subject: [PATCH 22/61] =?UTF-8?q?Einige=20kleine=20Komfortabilit=C3=A4ts?= =?UTF-8?q?=C3=A4nderung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Tim/hangman.c | 14 +++++++------- src/main/c/Tim/hangman.h | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index 62f28ff..49b7035 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -114,12 +114,12 @@ void hangman() countWrongGuess++; printf("Der von dir getippte Buchstabe war falsch! Du hast noch %d Versuche.\n", POSSIBLE_TRYS-countWrongGuess); } - if(userSelection == '0'||wordGuessed(guessWord, displayWord)||noTrysLeft(countWrongGuess)) + changeLetter(userSelection, guessWord, length, displayWord); + drawHangman(countWrongGuess); + if(userSelection == '0'||wordGuessed(guessWord, displayWord)||noTrysLeft(countWrongGuess,guessWord)) { break; } - changeLetter(userSelection, guessWord, length, displayWord); - drawHangman(countWrongGuess); printf("\n\n%s\n", displayWord); } @@ -143,7 +143,7 @@ bool wordGuessed(char x[], char y[]) { if(strcmp(x,y) == 0) { - printf("Du hast gewonnen!\n"); + printf("Du hast gewonnen!\nDas gesuchte Wort war \"%s\"\n\nHier hast du ein neues Wort zum erraten.\n\n",x); return true; } else @@ -174,7 +174,7 @@ bool letterGuessed(char x, char y[], int length) } if(counter>0) { - printf("Dein gewaehlter Buchstabe %c war ein Treffer! Du hast noch %d Versuche.\n", x); + printf("Dein gewaehlter Buchstabe %c war ein Treffer!\n", x); return true; } else @@ -222,11 +222,11 @@ void drawHangman(int x) printf("%s", hangmanStages[x]); } -bool noTrysLeft(int x) +bool noTrysLeft(int x, char y[]) { if(x == POSSIBLE_TRYS) { - printf("Du hast verloren!\n\n"); + printf("Du hast verloren!\n\nDas gesuchte Wort war \"%s\"\n\nHier hast du ein neues Wort zum erraten.\n\n",y); return true; } else diff --git a/src/main/c/Tim/hangman.h b/src/main/c/Tim/hangman.h index a2d13ab..380e5ab 100644 --- a/src/main/c/Tim/hangman.h +++ b/src/main/c/Tim/hangman.h @@ -8,6 +8,6 @@ bool wordGuessed(char[],char[]); bool letterGuessed(char, char[], int); void changeLetter(char, char[], int, char[]); void drawHangman(int); -bool noTrysLeft(int); +bool noTrysLeft(int,char[]); #endif From 3a2ef63aba64c4fef00d7f432fbc6f02b2ebfb7e Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 20:59:29 +0100 Subject: [PATCH 23/61] =?UTF-8?q?Erweiterung=20der=20Wortliste=20f=C3=BCr?= =?UTF-8?q?=20Hangman?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Tim/hangman.c | 11 ++++++++--- src/main/c/Tim/hangman.h | 1 + src/test/c/Tim/test_hangman.c | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index 49b7035..96ecc80 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -6,7 +6,7 @@ #include #include -#define LISTSIZE 10 +#define LISTSIZE 30 #define MAX_WORD_LENGTH 30 #define STAGENUM 7 #define ASCII_ART_SIZE 1000 @@ -15,8 +15,13 @@ char wordlist[LISTSIZE][MAX_WORD_LENGTH] = { "Kartoffel", "Zigarette", "Haus", "Fenster", "Kartenleseettiketiergeraet", - "Kleiderschrank", "Schnee","Wasserhahn", - "Fernbedienung", "Computertastatur" + "Kleiderschrank", "Schnee","Wasserhahn","Fernbedienung", + "Computertastatur", "Verlies","Zucchini","lizenzieren", + "Portemonnaie","brillant","Rückgrat","Toilettenpapier", + "Dachpappe","Hund","Zwiebelsuppe","Zebra", + "Kruzifix","Anschnallgurt","Bügeleisen","Fliesenleger", + "Adventskranz","Weihnachtsbaum","Autoreifen","Waschbecken", + "Busfahrkarte" }; char hangmanStages[STAGENUM][ASCII_ART_SIZE]={ diff --git a/src/main/c/Tim/hangman.h b/src/main/c/Tim/hangman.h index 380e5ab..45feb3e 100644 --- a/src/main/c/Tim/hangman.h +++ b/src/main/c/Tim/hangman.h @@ -2,6 +2,7 @@ #ifndef HANGMAN_H #define HANGMAN_H + void hangman(); char* getWordFromList(int); bool wordGuessed(char[],char[]); diff --git a/src/test/c/Tim/test_hangman.c b/src/test/c/Tim/test_hangman.c index 757ed29..4e6d98e 100644 --- a/src/test/c/Tim/test_hangman.c +++ b/src/test/c/Tim/test_hangman.c @@ -43,7 +43,7 @@ void test_getWordFromList_Kleiderschrank_5() void test_getWordFromList_IndexOutOfList() { //arrange - int pos = 15; + int pos = 60; char expectedResult[] = "Index nicht vorhanden"; //act char actualResult[30]; From 1e643eb08a4ba0548bfc73098af3243d664463be Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 21:00:50 +0100 Subject: [PATCH 24/61] =?UTF-8?q?Verschieben=20der=20define=20Variablen=20?= =?UTF-8?q?in=20die=20.h-Datei,=20sodass=20sie=20ebenfalls=20f=C3=BCr=20di?= =?UTF-8?q?e=20Testdatei=20verf=C3=BCgbar=20ist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Tim/hangman.c | 6 +----- src/main/c/Tim/hangman.h | 5 +++++ src/test/c/Tim/test_hangman.c | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index 96ecc80..427f788 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -6,11 +6,7 @@ #include #include -#define LISTSIZE 30 -#define MAX_WORD_LENGTH 30 -#define STAGENUM 7 -#define ASCII_ART_SIZE 1000 -#define POSSIBLE_TRYS 6 + char wordlist[LISTSIZE][MAX_WORD_LENGTH] = { diff --git a/src/main/c/Tim/hangman.h b/src/main/c/Tim/hangman.h index 45feb3e..732f005 100644 --- a/src/main/c/Tim/hangman.h +++ b/src/main/c/Tim/hangman.h @@ -2,6 +2,11 @@ #ifndef HANGMAN_H #define HANGMAN_H +#define LISTSIZE 30 +#define MAX_WORD_LENGTH 30 +#define STAGENUM 7 +#define ASCII_ART_SIZE 1000 +#define POSSIBLE_TRYS 6 void hangman(); char* getWordFromList(int); diff --git a/src/test/c/Tim/test_hangman.c b/src/test/c/Tim/test_hangman.c index 4e6d98e..0ddb407 100644 --- a/src/test/c/Tim/test_hangman.c +++ b/src/test/c/Tim/test_hangman.c @@ -43,7 +43,7 @@ void test_getWordFromList_Kleiderschrank_5() void test_getWordFromList_IndexOutOfList() { //arrange - int pos = 60; + int pos = LISTSIZE+1; char expectedResult[] = "Index nicht vorhanden"; //act char actualResult[30]; From eaebe737cafdcf176bb49963dc233f9d78983776 Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 21:02:48 +0100 Subject: [PATCH 25/61] refactoring: Auslagern der Empfangsnachricht aus dem GameLoop in Hangman --- src/main/c/Tim/hangman.c | 14 +++++++++----- src/main/c/Tim/hangman.h | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index 427f788..49ef297 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -77,10 +77,7 @@ void hangman() { srand(time(NULL)); char userSelection; - printf("Willkommen bei Hangman!!!\n" - "Per Zufall wird jede Runde ein Wort aus einem Pool ausgewaehlt. Gebe einen Buchstaben ein, von dem du vermutest,\ndass er in dem gesuchten Wort ist, sobald die Konsole dich dazu auffordert.\n" - "Fuer jede falsche Antwort kommst du dem Tod immer naeher, also waehle weise!\n" - "Mit der Auswahl 0 kommst du zurueck ins Hauptmenue\n\n"); + getWelcomeMessageHangman(); do { @@ -126,7 +123,14 @@ void hangman() }while(userSelection != '0'); } - +void getWelcomeMessageHangman() +{ + printf("Willkommen bei Hangman!!!\n\n"); + drawHangman(6); + printf("\nPer Zufall wird jede Runde ein Wort aus einem Pool ausgewaehlt. Gebe einen Buchstaben ein, von dem du vermutest, dass er in dem gesuchten Wort ist, sobald die Konsole dich dazu auffordert.\n" + "Fuer jede falsche Antwort kommst du dem Tod immer naeher, also waehle weise!\n" + "Mit der Auswahl 0 kommst du zurueck ins Hauptmenue\n\n"); +} char* getWordFromList(int x) { diff --git a/src/main/c/Tim/hangman.h b/src/main/c/Tim/hangman.h index 732f005..c29858a 100644 --- a/src/main/c/Tim/hangman.h +++ b/src/main/c/Tim/hangman.h @@ -9,6 +9,7 @@ #define POSSIBLE_TRYS 6 void hangman(); +void getWelcomeMessageHangman(); char* getWordFromList(int); bool wordGuessed(char[],char[]); bool letterGuessed(char, char[], int); From 2af82e0adc77a3302212f81a942c57c44e22b91c Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 21:03:45 +0100 Subject: [PATCH 26/61] =?UTF-8?q?Aufteilen=20der=20Abbruchbedingung,=20sod?= =?UTF-8?q?ass=20bei=20Eingabe=20von=200=20nicht=20nochmal=20Hangman=20gez?= =?UTF-8?q?eichnet=20wird=20+=20Hinzuf=C3=BCgen=20Abschiedsnachricht?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Tim/hangman.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index 49ef297..85050d1 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -106,7 +106,10 @@ void hangman() { printf("Bitte gib einen Buchstaben ein!\n"); scanf(" %c", &userSelection); - + if(userSelection == '0') + { + break; + } if(!letterGuessed(userSelection, guessWord, length)) { countWrongGuess++; @@ -114,7 +117,7 @@ void hangman() } changeLetter(userSelection, guessWord, length, displayWord); drawHangman(countWrongGuess); - if(userSelection == '0'||wordGuessed(guessWord, displayWord)||noTrysLeft(countWrongGuess,guessWord)) + if(wordGuessed(guessWord, displayWord)||noTrysLeft(countWrongGuess,guessWord)) { break; } @@ -122,6 +125,7 @@ void hangman() } }while(userSelection != '0'); + printf("Danke fuers Spielen! Auf Wiedersehen!\n"); } void getWelcomeMessageHangman() { From 3b7e8d14844447cbd84ace35f2e139e995cca184 Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 21:04:48 +0100 Subject: [PATCH 27/61] =?UTF-8?q?Hinzuf=C3=BCgen=20der=20Tests=20f=C3=BCr?= =?UTF-8?q?=20noTrysLeft()=20+=20Anpassung=20im=20Produktivcode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Tim/hangman.c | 2 +- src/test/c/Tim/test_hangman.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index 85050d1..2c534e3 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -233,7 +233,7 @@ void drawHangman(int x) bool noTrysLeft(int x, char y[]) { - if(x == POSSIBLE_TRYS) + if(x >= POSSIBLE_TRYS) { printf("Du hast verloren!\n\nDas gesuchte Wort war \"%s\"\n\nHier hast du ein neues Wort zum erraten.\n\n",y); return true; diff --git a/src/test/c/Tim/test_hangman.c b/src/test/c/Tim/test_hangman.c index 0ddb407..a3c54c6 100644 --- a/src/test/c/Tim/test_hangman.c +++ b/src/test/c/Tim/test_hangman.c @@ -119,3 +119,30 @@ void test_letterGuessed_sameCaps_big() TEST_ASSERT_TRUE(letterGuessed(x,y,length)); } +void test_noTrysLeft_x_equals_POSSIBLE_TRYS() +{ + //arrange + char x = POSSIBLE_TRYS; + char y[] ="Kartoffel"; + //assert + TEST_ASSERT_TRUE(noTrysLeft(x, y)); +} + +void test_noTrysLeft_x_lower_POSSIBLE_TRYS() +{ + //arrange + char x = POSSIBLE_TRYS-2; + char y[] ="Kartoffel"; + //assert + TEST_ASSERT_FALSE(noTrysLeft(x, y)); +} + +void test_noTrysLeft_x_higher_POSSIBLE_TRYS() +{ + //arrange + char x = POSSIBLE_TRYS+2; + char y[] ="Kartoffel"; + //assert + TEST_ASSERT_TRUE(noTrysLeft(x, y)); +} + From bd53927ab27b7c716a88c170626df8a545649f0d Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 21:05:56 +0100 Subject: [PATCH 28/61] =?UTF-8?q?Schreiben=20des=20Test=20f=C3=BCr=20unter?= =?UTF-8?q?schiedliche=20Buchstaben=20bei=20letterGuessed()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Tim/hangman.c | 1 + src/test/c/Tim/test_hangman.c | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index 2c534e3..f684076 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -127,6 +127,7 @@ void hangman() }while(userSelection != '0'); printf("Danke fuers Spielen! Auf Wiedersehen!\n"); } + void getWelcomeMessageHangman() { printf("Willkommen bei Hangman!!!\n\n"); diff --git a/src/test/c/Tim/test_hangman.c b/src/test/c/Tim/test_hangman.c index a3c54c6..bfbe9c6 100644 --- a/src/test/c/Tim/test_hangman.c +++ b/src/test/c/Tim/test_hangman.c @@ -108,6 +108,16 @@ void test_letterGuessed_sameCaps_small() //assert TEST_ASSERT_TRUE(letterGuessed(x,y,length)); } +void test_letterGuessed_differentLetter() +{ + //arrange + char x ='p'; + char y[] ="Kartoffel"; + int length = 9; + //assert + TEST_ASSERT_FALSE(letterGuessed(x,y,length)); +} + void test_letterGuessed_sameCaps_big() { From 37f32fef2bb247d51a08647b672bb624e73ad903 Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 21:07:11 +0100 Subject: [PATCH 29/61] =?UTF-8?q?Erweiterung=20des=20Testfall=20unterschie?= =?UTF-8?q?dlicher=20Buchstabe=20bei=20letterGuessed()=20um=20Gro=C3=9F-?= =?UTF-8?q?=20und=20Kleinschreibung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/c/Tim/test_hangman.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/test/c/Tim/test_hangman.c b/src/test/c/Tim/test_hangman.c index bfbe9c6..bc1048b 100644 --- a/src/test/c/Tim/test_hangman.c +++ b/src/test/c/Tim/test_hangman.c @@ -108,7 +108,7 @@ void test_letterGuessed_sameCaps_small() //assert TEST_ASSERT_TRUE(letterGuessed(x,y,length)); } -void test_letterGuessed_differentLetter() +void test_letterGuessed_differentLetter_small() { //arrange char x ='p'; @@ -117,6 +117,15 @@ void test_letterGuessed_differentLetter() //assert TEST_ASSERT_FALSE(letterGuessed(x,y,length)); } +void test_letterGuessed_differentLetter_big() +{ + //arrange + char x ='P'; + char y[] ="Kartoffel"; + int length = 9; + //assert + TEST_ASSERT_FALSE(letterGuessed(x,y,length)); +} void test_letterGuessed_sameCaps_big() From 43abfa0aa1ff887ee3bb0315a173c385698cc232 Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 21:08:23 +0100 Subject: [PATCH 30/61] =?UTF-8?q?Erweiterung=20der=20Test=20f=C3=BCr=20get?= =?UTF-8?q?WordFromList=20f=C3=BCr=20Index=20=C3=BCber=20und=20unter=20Wor?= =?UTF-8?q?tliste=20+=20Anpassung=20im=20Produktivcode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Tim/hangman.c | 2 +- src/test/c/Tim/test_hangman.c | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index f684076..5f99432 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -139,7 +139,7 @@ void getWelcomeMessageHangman() char* getWordFromList(int x) { - if(x=0 && x Date: Thu, 25 Jan 2024 21:09:44 +0100 Subject: [PATCH 31/61] =?UTF-8?q?Hinzuf=C3=BCgen=20einer=20Weiterspielabfr?= =?UTF-8?q?age=20nach=20Ende=20einer=20Spielrunde?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Tim/hangman.c | 21 ++++++++++++++++++--- src/main/c/Tim/hangman.h | 2 ++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index 5f99432..d5c5255 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -123,7 +123,7 @@ void hangman() } printf("\n\n%s\n", displayWord); } - + userSelection = endGame(); }while(userSelection != '0'); printf("Danke fuers Spielen! Auf Wiedersehen!\n"); } @@ -153,7 +153,7 @@ bool wordGuessed(char x[], char y[]) { if(strcmp(x,y) == 0) { - printf("Du hast gewonnen!\nDas gesuchte Wort war \"%s\"\n\nHier hast du ein neues Wort zum erraten.\n\n",x); + printf("Du hast gewonnen!\nDas gesuchte Wort war \"%s\"\n\n",x); return true; } else @@ -236,11 +236,26 @@ bool noTrysLeft(int x, char y[]) { if(x >= POSSIBLE_TRYS) { - printf("Du hast verloren!\n\nDas gesuchte Wort war \"%s\"\n\nHier hast du ein neues Wort zum erraten.\n\n",y); + printf("Du hast verloren!\n\nDas gesuchte Wort war \"%s\"\n\n",y); return true; } else { return false; } +} + +char endGame() +{ + char userSelect; + endGameQuestionHangman(); + scanf(" %c", &userSelect); + + return userSelect; +} + + +void endGameQuestionHangman() +{ + printf("Moechtest du nochmal spielen?\n\nBeliebige Taste: Nochmal spielen\n 0 : Beenden\n"); } \ No newline at end of file diff --git a/src/main/c/Tim/hangman.h b/src/main/c/Tim/hangman.h index c29858a..f68abf8 100644 --- a/src/main/c/Tim/hangman.h +++ b/src/main/c/Tim/hangman.h @@ -16,5 +16,7 @@ bool letterGuessed(char, char[], int); void changeLetter(char, char[], int, char[]); void drawHangman(int); bool noTrysLeft(int,char[]); +char endGame(); +void endGameQuestionHangman(); #endif From 516049f1bda011542f2019c4d79e939f12cb3211 Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 21:10:42 +0100 Subject: [PATCH 32/61] =?UTF-8?q?Hotfix:=20Bei=20W=C3=B6rtern=20mit=20klei?= =?UTF-8?q?nen=20Buchstaben=20werden=20die=20Buchstaben=20als=20klein=20?= =?UTF-8?q?=C3=BCbernommen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Tim/hangman.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index d5c5255..8719211 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -201,7 +201,7 @@ void changeLetter(char x, char y[], int length, char ptr[]) { if (x == y[i]-32 || x == y[i] ) { - if(i ==0) + if(i ==0 && isupper(y[0])!=0) { ptr[i] = x; } @@ -215,7 +215,7 @@ void changeLetter(char x, char y[], int length, char ptr[]) { if (x == y[i]||x == y[i]+32) { - if(i == 0) + if(i == 0 && isupper(y[0])!=0) { ptr[i] = x-32; } From 64247b0c528e32e42c2e96e5729cad24f925a3f0 Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 21:12:21 +0100 Subject: [PATCH 33/61] =?UTF-8?q?refactoring:=20Umbenennen=20der=20formale?= =?UTF-8?q?n=20Parameter=20von=20wordGuessed()=20zu=20verst=C3=A4ndlichere?= =?UTF-8?q?n=20Namen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Tim/hangman.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index 8719211..64e6ccb 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -149,11 +149,11 @@ char* getWordFromList(int x) } } -bool wordGuessed(char x[], char y[]) +bool wordGuessed(char guessWord[], char displayWord[]) { - if(strcmp(x,y) == 0) + if(strcmp(guessWord, displayWord) == 0) { - printf("Du hast gewonnen!\nDas gesuchte Wort war \"%s\"\n\n",x); + printf("Du hast gewonnen!\nDas gesuchte Wort war \"%s\"\n\n",guessWord); return true; } else From c086500f893e5736ba8bb4fc94806434526c56d0 Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 21:13:26 +0100 Subject: [PATCH 34/61] =?UTF-8?q?refactoring:=20Umbenennen=20der=20formale?= =?UTF-8?q?n=20Parameter=20von=20letterGuessedzu=20verst=C3=A4ndlicheren?= =?UTF-8?q?=20Namen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Tim/hangman.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index 64e6ccb..040a085 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -162,20 +162,20 @@ bool wordGuessed(char guessWord[], char displayWord[]) } } -bool letterGuessed(char x, char y[], int length) +bool letterGuessed(char selectedLetter, char guessWord[], int length) { int counter = 0; for(int i = 0; i0) { - printf("Dein gewaehlter Buchstabe %c war ein Treffer!\n", x); + printf("Dein gewaehlter Buchstabe %c war ein Treffer!\n", selectedLetter); return true; } else From e6c9d0dcb67ddb3fbec7423e48eddde31dfc68a3 Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 21:14:39 +0100 Subject: [PATCH 35/61] =?UTF-8?q?refactoring:=20Umbenennen=20der=20formale?= =?UTF-8?q?n=20Parameter=20von=20changeLetter()=20zu=20verst=C3=A4ndlicher?= =?UTF-8?q?en=20Name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Tim/hangman.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index 040a085..228d02a 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -194,33 +194,33 @@ bool letterGuessed(char selectedLetter, char guessWord[], int length) } -void changeLetter(char x, char y[], int length, char ptr[]) +void changeLetter(char selectedLetter, char guessWord[], int length, char ptrDisplayWord[]) { for(int i = 0; i Date: Thu, 25 Jan 2024 21:15:54 +0100 Subject: [PATCH 36/61] =?UTF-8?q?refactoring:=20Umbenennen=20der=20formale?= =?UTF-8?q?n=20Parameter=20von=20drawHangman=20und=20noTrysLeft=20zu=20ver?= =?UTF-8?q?st=C3=A4ndlicheren=20Namen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Tim/hangman.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/c/Tim/hangman.c b/src/main/c/Tim/hangman.c index 228d02a..08886d6 100644 --- a/src/main/c/Tim/hangman.c +++ b/src/main/c/Tim/hangman.c @@ -227,16 +227,16 @@ void changeLetter(char selectedLetter, char guessWord[], int length, char ptrDis } } -void drawHangman(int x) +void drawHangman(int wrongGuessCount) { - printf("%s", hangmanStages[x]); + printf("%s", hangmanStages[wrongGuessCount]); } -bool noTrysLeft(int x, char y[]) +bool noTrysLeft(int wrongGuessCount, char guessWord[]) { - if(x >= POSSIBLE_TRYS) + if(wrongGuessCount >= POSSIBLE_TRYS) { - printf("Du hast verloren!\n\nDas gesuchte Wort war \"%s\"\n\n",y); + printf("Du hast verloren!\n\nDas gesuchte Wort war \"%s\"\n\n", guessWord); return true; } else From 78f23e4622eec07f204b8764d78912fc74943a68 Mon Sep 17 00:00:00 2001 From: fdai7472 Date: Thu, 25 Jan 2024 22:22:10 +0100 Subject: [PATCH 37/61] Anlegen der Dateien slot_machine.c, slot_machine.h, test_slot_machine.c --- src/main/c/Stefan/place_your_code_here.txt | 0 src/main/c/Stefan/slot_machine.c | 3 +++ src/main/c/Stefan/slot_machine.h | 6 ++++++ src/test/c/Stefan/place_your_tests_here.txt | 0 src/test/c/Stefan/test_slot_machine.c | 8 ++++++++ 5 files changed, 17 insertions(+) delete mode 100644 src/main/c/Stefan/place_your_code_here.txt create mode 100644 src/main/c/Stefan/slot_machine.c create mode 100644 src/main/c/Stefan/slot_machine.h delete mode 100644 src/test/c/Stefan/place_your_tests_here.txt create mode 100644 src/test/c/Stefan/test_slot_machine.c diff --git a/src/main/c/Stefan/place_your_code_here.txt b/src/main/c/Stefan/place_your_code_here.txt deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/c/Stefan/slot_machine.c b/src/main/c/Stefan/slot_machine.c new file mode 100644 index 0000000..0489155 --- /dev/null +++ b/src/main/c/Stefan/slot_machine.c @@ -0,0 +1,3 @@ +#include "slot_machine.h" + +void slotMachine(){} \ No newline at end of file diff --git a/src/main/c/Stefan/slot_machine.h b/src/main/c/Stefan/slot_machine.h new file mode 100644 index 0000000..802a09f --- /dev/null +++ b/src/main/c/Stefan/slot_machine.h @@ -0,0 +1,6 @@ +#ifndef SLOT_MACHINE_H +#define SLOT_MACHINE_H + +void slotMachine(); + +#endif // SLOT_MACHINE_H \ No newline at end of file diff --git a/src/test/c/Stefan/place_your_tests_here.txt b/src/test/c/Stefan/place_your_tests_here.txt deleted file mode 100644 index e69de29..0000000 diff --git a/src/test/c/Stefan/test_slot_machine.c b/src/test/c/Stefan/test_slot_machine.c new file mode 100644 index 0000000..b327568 --- /dev/null +++ b/src/test/c/Stefan/test_slot_machine.c @@ -0,0 +1,8 @@ +#include "slot_machine.h" +#include "unity.h" + +void setUp() {} + +void tearDown() {} + +void test_test(){} \ No newline at end of file From a2b67996497e3992efc3575abb430c774457614d Mon Sep 17 00:00:00 2001 From: fdai7472 Date: Mon, 29 Jan 2024 09:44:29 +0100 Subject: [PATCH 38/61] Slot Machine im main included und im switch angefuegt --- src/main/c/main.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/c/main.c b/src/main/c/main.c index 4dc37a9..49f4cdd 100644 --- a/src/main/c/main.c +++ b/src/main/c/main.c @@ -14,6 +14,7 @@ #include "SchereSteinPapier.h" #include "hangman.h" #include "tictactoe.h" +#include "slot_machine.h" void openInterface(); @@ -35,7 +36,8 @@ void openInterface() "Du hast folgende Spiele zur Auswahl:\n\n" "1: Schere-Stein-Papier\n" "2: Hangman\n" - "3: TicTacToe\n"); + "3: TicTacToe\n" + "4: Slot Machine\n"); printf("\nBitte waehle die Zahl des entsprechenden Spiels aus, um damit zu starten.\nAm Ende eines Spiels kannst du mit der Taste 0 wieder zurueck zum Hauptmenue kommen.\nIm Hauptmenue beendest du mit der Auswahl 0 das Programm \n\n"); scanf_s("%d", &selection); @@ -54,10 +56,10 @@ void openInterface() case(3): startTicTacToe(); break; - /*case(4): - //Spiel() + case(4): + slotMachine(); break; - case(5): + /*case(5): //Spiel() break;*/ default: From 7aebe2a9dc0fb96365149fdde3b095e7bd66eb51 Mon Sep 17 00:00:00 2001 From: fdai7472 Date: Mon, 29 Jan 2024 15:43:49 +0100 Subject: [PATCH 39/61] Welcome Message added --- src/main/c/Stefan/slot_machine.c | 23 ++++++++++++++++++++++- src/main/c/Stefan/slot_machine.h | 1 + 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/c/Stefan/slot_machine.c b/src/main/c/Stefan/slot_machine.c index 0489155..b5ad747 100644 --- a/src/main/c/Stefan/slot_machine.c +++ b/src/main/c/Stefan/slot_machine.c @@ -1,3 +1,24 @@ #include "slot_machine.h" +#include -void slotMachine(){} \ No newline at end of file +void slotMachine(){ + + welcomeMessage(); + + + + + + + +} + +void welcomeMessage(){ + printf("Herzlich Willkommen zur \n\n" + " _ _ _ _ \n" + " | | | | | | (_) \n" + " ___| | ___ | |_ _ __ ___ __ _ ___| |__ _ _ __ ___ \n" + "/ __| |/ _ \\| __| | '_ ` _ \\ / _` |/ __| '_ \\| | '_ \\ / _ \\\n" + "\\__ \\ | (_) | |_ | | | | | (_| | (__| | | | | | | | __/\n" + "|___/_|\\___/ \\__| |_| |_| |_|\\__,_|\\___|_| |_|_|_| |_|\\___|\n\n"); +} \ No newline at end of file diff --git a/src/main/c/Stefan/slot_machine.h b/src/main/c/Stefan/slot_machine.h index 802a09f..588b6ea 100644 --- a/src/main/c/Stefan/slot_machine.h +++ b/src/main/c/Stefan/slot_machine.h @@ -2,5 +2,6 @@ #define SLOT_MACHINE_H void slotMachine(); +void welcomeMessage(); #endif // SLOT_MACHINE_H \ No newline at end of file From 8b185a3cdcc14b64f25a7577db3d993bd2acd63c Mon Sep 17 00:00:00 2001 From: fdai7472 Date: Mon, 29 Jan 2024 15:48:06 +0100 Subject: [PATCH 40/61] getBalance() added --- src/main/c/Stefan/slot_machine.c | 8 ++++++++ src/main/c/Stefan/slot_machine.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/main/c/Stefan/slot_machine.c b/src/main/c/Stefan/slot_machine.c index b5ad747..f0ee169 100644 --- a/src/main/c/Stefan/slot_machine.c +++ b/src/main/c/Stefan/slot_machine.c @@ -5,12 +5,20 @@ void slotMachine(){ welcomeMessage(); + int balance = getBalance(); +} + +int getBalance(){ + int balance; + printf("Guthaben einwerfen: "); + scanf_s("%d", &balance); + return balance; } void welcomeMessage(){ diff --git a/src/main/c/Stefan/slot_machine.h b/src/main/c/Stefan/slot_machine.h index 588b6ea..3da8ff8 100644 --- a/src/main/c/Stefan/slot_machine.h +++ b/src/main/c/Stefan/slot_machine.h @@ -3,5 +3,7 @@ void slotMachine(); void welcomeMessage(); +int getBalance(); + #endif // SLOT_MACHINE_H \ No newline at end of file From d3880981729b54656e3bd33dda9b2696515221e4 Mon Sep 17 00:00:00 2001 From: fdai7472 Date: Mon, 29 Jan 2024 15:53:07 +0100 Subject: [PATCH 41/61] getBalance erweitert mit userInput --- src/main/c/Stefan/slot_machine.c | 9 ++++++++- src/main/c/Stefan/slot_machine.h | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/c/Stefan/slot_machine.c b/src/main/c/Stefan/slot_machine.c index f0ee169..ff07038 100644 --- a/src/main/c/Stefan/slot_machine.c +++ b/src/main/c/Stefan/slot_machine.c @@ -17,10 +17,17 @@ void slotMachine(){ int getBalance(){ int balance; printf("Guthaben einwerfen: "); - scanf_s("%d", &balance); + balance = userInput(); + printf("Dein Guthaben: %d", balance); return balance; } +int userInput(){ + int input; + scanf_s("%d", &input); + return input; +} + void welcomeMessage(){ printf("Herzlich Willkommen zur \n\n" " _ _ _ _ \n" diff --git a/src/main/c/Stefan/slot_machine.h b/src/main/c/Stefan/slot_machine.h index 3da8ff8..56cebac 100644 --- a/src/main/c/Stefan/slot_machine.h +++ b/src/main/c/Stefan/slot_machine.h @@ -4,6 +4,6 @@ void slotMachine(); void welcomeMessage(); int getBalance(); - +int userInput(); #endif // SLOT_MACHINE_H \ No newline at end of file From f87ef43a2c84b147cc0b586f74381f95020f92c6 Mon Sep 17 00:00:00 2001 From: fdai7472 Date: Mon, 29 Jan 2024 16:03:07 +0100 Subject: [PATCH 42/61] Eingabe Wetteinsatz added --- src/main/c/Stefan/slot_machine.c | 15 ++++++++++++++- src/main/c/Stefan/slot_machine.h | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/c/Stefan/slot_machine.c b/src/main/c/Stefan/slot_machine.c index ff07038..dfddd13 100644 --- a/src/main/c/Stefan/slot_machine.c +++ b/src/main/c/Stefan/slot_machine.c @@ -7,7 +7,12 @@ void slotMachine(){ int balance = getBalance(); + while(balance > 0){ + int bet = getBet(balance); + balance -= bet; + printf("%d\n", balance); + } @@ -18,7 +23,7 @@ int getBalance(){ int balance; printf("Guthaben einwerfen: "); balance = userInput(); - printf("Dein Guthaben: %d", balance); + printf("Dein Guthaben: %d\n", balance); return balance; } @@ -28,6 +33,14 @@ int userInput(){ return input; } +int getBet(int balance){ + int bet; + printf("Wetteinsatz: "); + bet = userInput(); + + return bet; +} + void welcomeMessage(){ printf("Herzlich Willkommen zur \n\n" " _ _ _ _ \n" diff --git a/src/main/c/Stefan/slot_machine.h b/src/main/c/Stefan/slot_machine.h index 56cebac..14a3217 100644 --- a/src/main/c/Stefan/slot_machine.h +++ b/src/main/c/Stefan/slot_machine.h @@ -5,5 +5,6 @@ void slotMachine(); void welcomeMessage(); int getBalance(); int userInput(); +int getBet(int balance); #endif // SLOT_MACHINE_H \ No newline at end of file From 6b9011afcb5740a2e9edd834f877e5bd62ad9c83 Mon Sep 17 00:00:00 2001 From: fdai7472 Date: Mon, 29 Jan 2024 16:09:03 +0100 Subject: [PATCH 43/61] Ungueltige Wetteinsaetze werden abgefangen --- src/main/c/Stefan/slot_machine.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/c/Stefan/slot_machine.c b/src/main/c/Stefan/slot_machine.c index dfddd13..4d1e33f 100644 --- a/src/main/c/Stefan/slot_machine.c +++ b/src/main/c/Stefan/slot_machine.c @@ -34,11 +34,17 @@ int userInput(){ } int getBet(int balance){ - int bet; - printf("Wetteinsatz: "); - bet = userInput(); - return bet; + while(1){ + printf("Wetteinsatz: "); + int bet = userInput(); + + if(bet <= balance && bet >= 0){ + return bet; + } else { + printf("Ungueltige Eingabe!\n"); + } + } } void welcomeMessage(){ From d15d3aa55bcc743dc31688beffbd3aa87518a84b Mon Sep 17 00:00:00 2001 From: fdai7472 Date: Mon, 29 Jan 2024 16:17:02 +0100 Subject: [PATCH 44/61] Wetteinsatz vom Guthaben abziehen + erster Test dazu --- src/main/c/Stefan/slot_machine.c | 7 +++++-- src/main/c/Stefan/slot_machine.h | 1 + src/test/c/Stefan/test_slot_machine.c | 12 +++++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/c/Stefan/slot_machine.c b/src/main/c/Stefan/slot_machine.c index 4d1e33f..ef586f5 100644 --- a/src/main/c/Stefan/slot_machine.c +++ b/src/main/c/Stefan/slot_machine.c @@ -10,8 +10,7 @@ void slotMachine(){ while(balance > 0){ int bet = getBet(balance); - balance -= bet; - printf("%d\n", balance); + balance = subtractBetFromBalance(bet, balance); } @@ -47,6 +46,10 @@ int getBet(int balance){ } } +int subtractBetFromBalance(int bet, int balance){ + return balance - bet; +} + void welcomeMessage(){ printf("Herzlich Willkommen zur \n\n" " _ _ _ _ \n" diff --git a/src/main/c/Stefan/slot_machine.h b/src/main/c/Stefan/slot_machine.h index 14a3217..b0119f4 100644 --- a/src/main/c/Stefan/slot_machine.h +++ b/src/main/c/Stefan/slot_machine.h @@ -6,5 +6,6 @@ void welcomeMessage(); int getBalance(); int userInput(); int getBet(int balance); +int subtractBetFromBalance(int bet, int balance); #endif // SLOT_MACHINE_H \ No newline at end of file diff --git a/src/test/c/Stefan/test_slot_machine.c b/src/test/c/Stefan/test_slot_machine.c index b327568..4afa387 100644 --- a/src/test/c/Stefan/test_slot_machine.c +++ b/src/test/c/Stefan/test_slot_machine.c @@ -5,4 +5,14 @@ void setUp() {} void tearDown() {} -void test_test(){} \ No newline at end of file +void test_subtract_bet_10_from_balance_10() { + + //arrange + int expectedResult = 0; + + //act + int actualResult = subtractBetFromBalance(10, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} \ No newline at end of file From a8c5b73431720cac5a4a7a5479c5441345f13b99 Mon Sep 17 00:00:00 2001 From: fdai7472 Date: Mon, 29 Jan 2024 16:19:46 +0100 Subject: [PATCH 45/61] weitere Tests Wetteinsatz vom Guthaben abziehen --- src/test/c/Stefan/test_slot_machine.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/test/c/Stefan/test_slot_machine.c b/src/test/c/Stefan/test_slot_machine.c index 4afa387..9781e62 100644 --- a/src/test/c/Stefan/test_slot_machine.c +++ b/src/test/c/Stefan/test_slot_machine.c @@ -13,6 +13,29 @@ void test_subtract_bet_10_from_balance_10() { //act int actualResult = subtractBetFromBalance(10, 10); + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} +void test_subtract_bet_0_from_balance_10() { + + //arrange + int expectedResult = 10; + + //act + int actualResult = subtractBetFromBalance(0, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} + +void test_subtract_bet_5_from_balance_10() { + + //arrange + int expectedResult = 5; + + //act + int actualResult = subtractBetFromBalance(5, 10); + //assert TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); } \ No newline at end of file From e87430bfc9454b1768b5dff4853dc9298dfef036 Mon Sep 17 00:00:00 2001 From: fdai7472 Date: Mon, 29 Jan 2024 16:28:04 +0100 Subject: [PATCH 46/61] Symbole (A,B,C,D) mit bestimmten Wahrscheinlichkeiten und Werten erstellen --- src/main/c/Stefan/slot_machine.c | 44 +++++++++++++++++++++++++++++--- src/main/c/Stefan/slot_machine.h | 8 ++++++ 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/main/c/Stefan/slot_machine.c b/src/main/c/Stefan/slot_machine.c index ef586f5..a554065 100644 --- a/src/main/c/Stefan/slot_machine.c +++ b/src/main/c/Stefan/slot_machine.c @@ -1,20 +1,23 @@ #include "slot_machine.h" #include +#include +#include void slotMachine(){ welcomeMessage(); + Symbol symbols[NUM_OF_SYMBOLS]; + int balance = getBalance(); while(balance > 0){ int bet = getBet(balance); balance = subtractBetFromBalance(bet, balance); - } - - + createSymbols(symbols); + } } @@ -50,6 +53,41 @@ int subtractBetFromBalance(int bet, int balance){ return balance - bet; } +void createSymbols(Symbol symbols[]){ + + char possibleLetter[] = "ABCD"; + int possibleValue[] = { 3,5,10,20 }; + + srand(time(NULL)); + + for (int i = 0; i < NUM_OF_SYMBOLS; i++) { + + int r = rand() % 100; + + // 35% chance für A + if (r < 35) { + symbols[i].letter = possibleLetter[0]; + symbols[i].value = possibleValue[0]; + } + // 30% chance für B + else if (r < 65) { + symbols[i].letter = possibleLetter[1]; + symbols[i].value = possibleValue[1]; + } + // 20% chance für C + else if (r < 85) { + symbols[i].letter = possibleLetter[2]; + symbols[i].value = possibleValue[2]; + } + // 15% chance für D + else { + symbols[i].letter = possibleLetter[3]; + symbols[i].value = possibleValue[3]; + } + } + +} + void welcomeMessage(){ printf("Herzlich Willkommen zur \n\n" " _ _ _ _ \n" diff --git a/src/main/c/Stefan/slot_machine.h b/src/main/c/Stefan/slot_machine.h index b0119f4..5cf2295 100644 --- a/src/main/c/Stefan/slot_machine.h +++ b/src/main/c/Stefan/slot_machine.h @@ -1,11 +1,19 @@ #ifndef SLOT_MACHINE_H #define SLOT_MACHINE_H +typedef struct { + char letter; + int value; +} Symbol; + +#define NUM_OF_SYMBOLS 9 + void slotMachine(); void welcomeMessage(); int getBalance(); int userInput(); int getBet(int balance); int subtractBetFromBalance(int bet, int balance); +void createSymbols(Symbol symbols[]); #endif // SLOT_MACHINE_H \ No newline at end of file From 5038d8194aed26fc86577f3422820c44e8a37a07 Mon Sep 17 00:00:00 2001 From: fdai7472 Date: Mon, 29 Jan 2024 16:36:59 +0100 Subject: [PATCH 47/61] refactoring: Funktion createSymbols zu randomizeSymbols umbenannt --- src/main/c/Stefan/slot_machine.c | 4 ++-- src/main/c/Stefan/slot_machine.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/c/Stefan/slot_machine.c b/src/main/c/Stefan/slot_machine.c index a554065..f57a38e 100644 --- a/src/main/c/Stefan/slot_machine.c +++ b/src/main/c/Stefan/slot_machine.c @@ -16,7 +16,7 @@ void slotMachine(){ int bet = getBet(balance); balance = subtractBetFromBalance(bet, balance); - createSymbols(symbols); + randomizeSymbols(symbols); } } @@ -53,7 +53,7 @@ int subtractBetFromBalance(int bet, int balance){ return balance - bet; } -void createSymbols(Symbol symbols[]){ +void randomizeSymbols(Symbol symbols[]){ char possibleLetter[] = "ABCD"; int possibleValue[] = { 3,5,10,20 }; diff --git a/src/main/c/Stefan/slot_machine.h b/src/main/c/Stefan/slot_machine.h index 5cf2295..bebd77b 100644 --- a/src/main/c/Stefan/slot_machine.h +++ b/src/main/c/Stefan/slot_machine.h @@ -14,6 +14,6 @@ int getBalance(); int userInput(); int getBet(int balance); int subtractBetFromBalance(int bet, int balance); -void createSymbols(Symbol symbols[]); +void randomizeSymbols(Symbol symbols[]); #endif // SLOT_MACHINE_H \ No newline at end of file From ac710a45782b67b65668d134def99acb54a96cd5 Mon Sep 17 00:00:00 2001 From: fdai7472 Date: Mon, 29 Jan 2024 16:44:02 +0100 Subject: [PATCH 48/61] Symbole in einer Reihe vergleichen und Gewinn berechnen --- src/main/c/Stefan/slot_machine.c | 26 ++++++++++++++++++++++++++ src/main/c/Stefan/slot_machine.h | 3 +++ 2 files changed, 29 insertions(+) diff --git a/src/main/c/Stefan/slot_machine.c b/src/main/c/Stefan/slot_machine.c index f57a38e..1bb050e 100644 --- a/src/main/c/Stefan/slot_machine.c +++ b/src/main/c/Stefan/slot_machine.c @@ -17,6 +17,7 @@ void slotMachine(){ balance = subtractBetFromBalance(bet, balance); randomizeSymbols(symbols); + spin(symbols, bet, balance); } } @@ -88,6 +89,31 @@ void randomizeSymbols(Symbol symbols[]){ } +int spin(Symbol symbols[], int bet, int balance){ + + int winnings = getWinnings(symbols, bet); + + return balance; +} + +int getWinnings(Symbol symbols[], int bet){ + + int winnings = 0; + + // 0 | 1 | 2 + // 3 | 4 | 5 + // 6 | 7 | 8 + + // 3 gleiche Symbole in einer Reihe gewinnen, Gewinn berechnen + for (int i = 0; i < ROWS; i++){ + if (symbols[i * ROWS].letter == symbols[i * ROWS + 1].letter && symbols[i * ROWS].letter == symbols[i * ROWS + 2].letter) { + winnings += bet * symbols[i * ROWS].value; + } + } + + return winnings; +} + void welcomeMessage(){ printf("Herzlich Willkommen zur \n\n" " _ _ _ _ \n" diff --git a/src/main/c/Stefan/slot_machine.h b/src/main/c/Stefan/slot_machine.h index bebd77b..1ed2f00 100644 --- a/src/main/c/Stefan/slot_machine.h +++ b/src/main/c/Stefan/slot_machine.h @@ -7,6 +7,7 @@ typedef struct { } Symbol; #define NUM_OF_SYMBOLS 9 +#define ROWS 9 void slotMachine(); void welcomeMessage(); @@ -15,5 +16,7 @@ int userInput(); int getBet(int balance); int subtractBetFromBalance(int bet, int balance); void randomizeSymbols(Symbol symbols[]); +int spin(Symbol symbols[], int bet, int balance); +int getWinnings(Symbol symbols[], int bet); #endif // SLOT_MACHINE_H \ No newline at end of file From 4b24734142dd37e12a0de794137e8745e4b52533 Mon Sep 17 00:00:00 2001 From: fdai7472 Date: Mon, 29 Jan 2024 17:42:34 +0100 Subject: [PATCH 49/61] Struct symbols durch einfaches String ersetzt und Code dementsprechend angepasst --- src/main/c/Stefan/slot_machine.c | 39 ++++++++++++++++++-------------- src/main/c/Stefan/slot_machine.h | 10 +++----- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/main/c/Stefan/slot_machine.c b/src/main/c/Stefan/slot_machine.c index 1bb050e..2a9b689 100644 --- a/src/main/c/Stefan/slot_machine.c +++ b/src/main/c/Stefan/slot_machine.c @@ -7,7 +7,7 @@ void slotMachine(){ welcomeMessage(); - Symbol symbols[NUM_OF_SYMBOLS]; + char symbols[NUM_OF_SYMBOLS]; int balance = getBalance(); @@ -15,6 +15,8 @@ void slotMachine(){ int bet = getBet(balance); balance = subtractBetFromBalance(bet, balance); + printf("Guthaben: %d\n", balance); + randomizeSymbols(symbols); spin(symbols, bet, balance); @@ -47,17 +49,16 @@ int getBet(int balance){ } else { printf("Ungueltige Eingabe!\n"); } + } + } int subtractBetFromBalance(int bet, int balance){ return balance - bet; } -void randomizeSymbols(Symbol symbols[]){ - - char possibleLetter[] = "ABCD"; - int possibleValue[] = { 3,5,10,20 }; +void randomizeSymbols(char symbols[]){ srand(time(NULL)); @@ -67,36 +68,32 @@ void randomizeSymbols(Symbol symbols[]){ // 35% chance für A if (r < 35) { - symbols[i].letter = possibleLetter[0]; - symbols[i].value = possibleValue[0]; + symbols[i] = 'A'; } // 30% chance für B else if (r < 65) { - symbols[i].letter = possibleLetter[1]; - symbols[i].value = possibleValue[1]; + symbols[i] = 'B'; } // 20% chance für C else if (r < 85) { - symbols[i].letter = possibleLetter[2]; - symbols[i].value = possibleValue[2]; + symbols[i] = 'C'; } // 15% chance für D else { - symbols[i].letter = possibleLetter[3]; - symbols[i].value = possibleValue[3]; + symbols[i] = 'D'; } } } -int spin(Symbol symbols[], int bet, int balance){ +int spin(char symbols[], int bet, int balance){ int winnings = getWinnings(symbols, bet); return balance; } -int getWinnings(Symbol symbols[], int bet){ +int getWinnings(char symbols[], int bet){ int winnings = 0; @@ -106,8 +103,16 @@ int getWinnings(Symbol symbols[], int bet){ // 3 gleiche Symbole in einer Reihe gewinnen, Gewinn berechnen for (int i = 0; i < ROWS; i++){ - if (symbols[i * ROWS].letter == symbols[i * ROWS + 1].letter && symbols[i * ROWS].letter == symbols[i * ROWS + 2].letter) { - winnings += bet * symbols[i * ROWS].value; + + if (symbols[i * ROWS] == symbols[i * ROWS + 1] && symbols[i * ROWS] == symbols[i * ROWS + 2]) { + + switch(symbols[i]){ + case 'A': winnings = bet * 3; break; + case 'B': winnings = bet * 5; break; + case 'C': winnings = bet * 10; break; + case 'D': winnings = bet * 20; break; + } + } } diff --git a/src/main/c/Stefan/slot_machine.h b/src/main/c/Stefan/slot_machine.h index 1ed2f00..dc37dae 100644 --- a/src/main/c/Stefan/slot_machine.h +++ b/src/main/c/Stefan/slot_machine.h @@ -1,10 +1,6 @@ #ifndef SLOT_MACHINE_H #define SLOT_MACHINE_H -typedef struct { - char letter; - int value; -} Symbol; #define NUM_OF_SYMBOLS 9 #define ROWS 9 @@ -15,8 +11,8 @@ int getBalance(); int userInput(); int getBet(int balance); int subtractBetFromBalance(int bet, int balance); -void randomizeSymbols(Symbol symbols[]); -int spin(Symbol symbols[], int bet, int balance); -int getWinnings(Symbol symbols[], int bet); +void randomizeSymbols(char symbols[]); +int spin(char symbols[], int bet, int balance); +int getWinnings(char symbols[], int bet); #endif // SLOT_MACHINE_H \ No newline at end of file From a34f5abef406274b84df7004b5e89f602bef4715 Mon Sep 17 00:00:00 2001 From: fdai7472 Date: Mon, 29 Jan 2024 17:49:58 +0100 Subject: [PATCH 50/61] Ergebnis anzeigen implementiert + typo in .h korrigiert ROWS 9 -> ROWS 3 --- src/main/c/Stefan/slot_machine.c | 8 ++++++++ src/main/c/Stefan/slot_machine.h | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/c/Stefan/slot_machine.c b/src/main/c/Stefan/slot_machine.c index 2a9b689..54ac3e9 100644 --- a/src/main/c/Stefan/slot_machine.c +++ b/src/main/c/Stefan/slot_machine.c @@ -89,6 +89,7 @@ void randomizeSymbols(char symbols[]){ int spin(char symbols[], int bet, int balance){ int winnings = getWinnings(symbols, bet); + showResult(symbols); return balance; } @@ -119,6 +120,13 @@ int getWinnings(char symbols[], int bet){ return winnings; } +void showResult(char symbols[]){ + + for (int i = 0; i < ROWS; i++){ + printf(" %c | %c | %c\n", symbols[i * ROWS], symbols[i * ROWS + 1], symbols[i * ROWS + 2]); + } +} + void welcomeMessage(){ printf("Herzlich Willkommen zur \n\n" " _ _ _ _ \n" diff --git a/src/main/c/Stefan/slot_machine.h b/src/main/c/Stefan/slot_machine.h index dc37dae..3639e7e 100644 --- a/src/main/c/Stefan/slot_machine.h +++ b/src/main/c/Stefan/slot_machine.h @@ -3,7 +3,7 @@ #define NUM_OF_SYMBOLS 9 -#define ROWS 9 +#define ROWS 3 void slotMachine(); void welcomeMessage(); @@ -14,5 +14,6 @@ int subtractBetFromBalance(int bet, int balance); void randomizeSymbols(char symbols[]); int spin(char symbols[], int bet, int balance); int getWinnings(char symbols[], int bet); +void showResult(char symbols[]); #endif // SLOT_MACHINE_H \ No newline at end of file From 607f656bed28be3b4450f0e54b77e5645533b769 Mon Sep 17 00:00:00 2001 From: fdai7472 Date: Mon, 29 Jan 2024 17:54:00 +0100 Subject: [PATCH 51/61] Gewinne werden jetzt angezeigt --- src/main/c/Stefan/slot_machine.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/c/Stefan/slot_machine.c b/src/main/c/Stefan/slot_machine.c index 54ac3e9..a779776 100644 --- a/src/main/c/Stefan/slot_machine.c +++ b/src/main/c/Stefan/slot_machine.c @@ -88,8 +88,8 @@ void randomizeSymbols(char symbols[]){ int spin(char symbols[], int bet, int balance){ - int winnings = getWinnings(symbols, bet); showResult(symbols); + int winnings = getWinnings(symbols, bet); return balance; } @@ -113,15 +113,20 @@ int getWinnings(char symbols[], int bet){ case 'C': winnings = bet * 10; break; case 'D': winnings = bet * 20; break; } - } } + if (winnings > 0) { + printf("\nDu hast %d gewonnen!\n", winnings - bet); + } + else { + printf("\nLeider verloren.\n"); + } return winnings; } void showResult(char symbols[]){ - + for (int i = 0; i < ROWS; i++){ printf(" %c | %c | %c\n", symbols[i * ROWS], symbols[i * ROWS + 1], symbols[i * ROWS + 2]); } From a0f27247c4ac765c43b06b382a070c130e919166 Mon Sep 17 00:00:00 2001 From: fdai7472 Date: Mon, 29 Jan 2024 18:00:51 +0100 Subject: [PATCH 52/61] Guthaben wird nach jeder Runde angezeigt --- src/main/c/Stefan/slot_machine.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/c/Stefan/slot_machine.c b/src/main/c/Stefan/slot_machine.c index a779776..114583d 100644 --- a/src/main/c/Stefan/slot_machine.c +++ b/src/main/c/Stefan/slot_machine.c @@ -15,8 +15,6 @@ void slotMachine(){ int bet = getBet(balance); balance = subtractBetFromBalance(bet, balance); - printf("Guthaben: %d\n", balance); - randomizeSymbols(symbols); spin(symbols, bet, balance); @@ -89,8 +87,10 @@ void randomizeSymbols(char symbols[]){ int spin(char symbols[], int bet, int balance){ showResult(symbols); - int winnings = getWinnings(symbols, bet); + int winnings = getWinnings(symbols, bet); + balance += winnings; + printf("Aktuelles Guthaben: %d\n-------------------------\n", balance); return balance; } From c8faaa8ba57710efbf577c08c25c6079e5c91ebf Mon Sep 17 00:00:00 2001 From: fdai7472 Date: Mon, 29 Jan 2024 18:09:06 +0100 Subject: [PATCH 53/61] Test, falls keine Reihe gewinnt --- src/main/c/Stefan/slot_machine.c | 2 +- src/test/c/Stefan/test_slot_machine.c | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/c/Stefan/slot_machine.c b/src/main/c/Stefan/slot_machine.c index 114583d..5acc8bf 100644 --- a/src/main/c/Stefan/slot_machine.c +++ b/src/main/c/Stefan/slot_machine.c @@ -107,7 +107,7 @@ int getWinnings(char symbols[], int bet){ if (symbols[i * ROWS] == symbols[i * ROWS + 1] && symbols[i * ROWS] == symbols[i * ROWS + 2]) { - switch(symbols[i]){ + switch(symbols[i * ROWS]){ case 'A': winnings = bet * 3; break; case 'B': winnings = bet * 5; break; case 'C': winnings = bet * 10; break; diff --git a/src/test/c/Stefan/test_slot_machine.c b/src/test/c/Stefan/test_slot_machine.c index 9781e62..76f8258 100644 --- a/src/test/c/Stefan/test_slot_machine.c +++ b/src/test/c/Stefan/test_slot_machine.c @@ -38,4 +38,19 @@ void test_subtract_bet_5_from_balance_10() { //assert TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); -} \ No newline at end of file +} + +void test_no_rows_won_bet_equals_10() { + + //arrange + char testSymbols[] = {"AABAACAAD"}; + + + int expectedResult = 0; + + //act + int actualResult = getWinnings(testSymbols, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} From 289293d5ffc3d165e6963c94022613589d83dfee Mon Sep 17 00:00:00 2001 From: fdai7472 Date: Mon, 29 Jan 2024 18:24:54 +0100 Subject: [PATCH 54/61] Tests, falls eine Reihe gewinnt --- src/test/c/Stefan/test_slot_machine.c | 57 ++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/src/test/c/Stefan/test_slot_machine.c b/src/test/c/Stefan/test_slot_machine.c index 76f8258..8a05f53 100644 --- a/src/test/c/Stefan/test_slot_machine.c +++ b/src/test/c/Stefan/test_slot_machine.c @@ -45,7 +45,6 @@ void test_no_rows_won_bet_equals_10() { //arrange char testSymbols[] = {"AABAACAAD"}; - int expectedResult = 0; //act @@ -54,3 +53,59 @@ void test_no_rows_won_bet_equals_10() { //assert TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); } + +void test_3_A_won_bet_equals_10() { + + //arrange + char testSymbols[] = {"AAAAACAAD"}; + + int expectedResult = 30; + + //act + int actualResult = getWinnings(testSymbols, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} + +void test_3_B_won_bet_equals_10() { + + //arrange + char testSymbols[] = {"BBBAACAAD"}; + + int expectedResult = 50; + + //act + int actualResult = getWinnings(testSymbols, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} + +void test_3_C_won_bet_equals_10() { + + //arrange + char testSymbols[] = {"BABAACCCC"}; + + int expectedResult = 100; + + //act + int actualResult = getWinnings(testSymbols, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} + +void test_3_D_won_bet_equals_10() { + + //arrange + char testSymbols[] = {"BABDDDCAC"}; + + int expectedResult = 200; + + //act + int actualResult = getWinnings(testSymbols, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} From cb6b8471df336ddaf482acb45d527209b5415105 Mon Sep 17 00:00:00 2001 From: fdai7472 Date: Mon, 29 Jan 2024 18:31:17 +0100 Subject: [PATCH 55/61] Tests, falls 2 Reihen gewinnen + Fehler bei Gewinnberechnung behoben --- src/main/c/Stefan/slot_machine.c | 8 +-- src/test/c/Stefan/test_slot_machine.c | 85 +++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 4 deletions(-) diff --git a/src/main/c/Stefan/slot_machine.c b/src/main/c/Stefan/slot_machine.c index 5acc8bf..e6395ba 100644 --- a/src/main/c/Stefan/slot_machine.c +++ b/src/main/c/Stefan/slot_machine.c @@ -108,10 +108,10 @@ int getWinnings(char symbols[], int bet){ if (symbols[i * ROWS] == symbols[i * ROWS + 1] && symbols[i * ROWS] == symbols[i * ROWS + 2]) { switch(symbols[i * ROWS]){ - case 'A': winnings = bet * 3; break; - case 'B': winnings = bet * 5; break; - case 'C': winnings = bet * 10; break; - case 'D': winnings = bet * 20; break; + case 'A': winnings += bet * 3; break; + case 'B': winnings += bet * 5; break; + case 'C': winnings += bet * 10; break; + case 'D': winnings += bet * 20; break; } } } diff --git a/src/test/c/Stefan/test_slot_machine.c b/src/test/c/Stefan/test_slot_machine.c index 8a05f53..3739660 100644 --- a/src/test/c/Stefan/test_slot_machine.c +++ b/src/test/c/Stefan/test_slot_machine.c @@ -16,6 +16,7 @@ void test_subtract_bet_10_from_balance_10() { //assert TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); } + void test_subtract_bet_0_from_balance_10() { //arrange @@ -109,3 +110,87 @@ void test_3_D_won_bet_equals_10() { //assert TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); } + +void test_6_A_won_bet_equals_10() { + + //arrange + char testSymbols[] = {"AAAAAACAC"}; + + int expectedResult = 60; + + //act + int actualResult = getWinnings(testSymbols, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} + +void test_6_B_won_bet_equals_10() { + + //arrange + char testSymbols[] = {"BBBBBBCAC"}; + + int expectedResult = 100; + + //act + int actualResult = getWinnings(testSymbols, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} + +void test_6_C_won_bet_equals_10() { + + //arrange + char testSymbols[] = {"CCCCCCCAC"}; + + int expectedResult = 200; + + //act + int actualResult = getWinnings(testSymbols, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} + +void test_6_D_won_bet_equals_10() { + + //arrange + char testSymbols[] = {"DDDDDDCAC"}; + + int expectedResult = 400; + + //act + int actualResult = getWinnings(testSymbols, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} + +void test_3_A_3_B_won_bet_equals_10() { + + //arrange + char testSymbols[] = {"AAABBBCAC"}; + + int expectedResult = 80; + + //act + int actualResult = getWinnings(testSymbols, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} + +void test_3_C_3_D_won_bet_equals_10() { + + //arrange + char testSymbols[] = {"BAACCCDDD"}; + + int expectedResult = 300; + + //act + int actualResult = getWinnings(testSymbols, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} From 4e72b760f002ecebad718f162cbcdf34ec07f4c5 Mon Sep 17 00:00:00 2001 From: fdai7472 Date: Mon, 29 Jan 2024 18:33:31 +0100 Subject: [PATCH 56/61] Tests, falls 3 Reihen gewinnen --- src/test/c/Stefan/test_slot_machine.c | 28 +++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/test/c/Stefan/test_slot_machine.c b/src/test/c/Stefan/test_slot_machine.c index 3739660..f2a17c9 100644 --- a/src/test/c/Stefan/test_slot_machine.c +++ b/src/test/c/Stefan/test_slot_machine.c @@ -194,3 +194,31 @@ void test_3_C_3_D_won_bet_equals_10() { //assert TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); } + +void test_9_A_won_bet_equals_10() { + + //arrange + char testSymbols[] = {"AAAAAAAAA"}; + + int expectedResult = 90; + + //act + int actualResult = getWinnings(testSymbols, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} + +void test_3_B_3_C_3_D_won_bet_equals_10() { + + //arrange + char testSymbols[] = {"BBBCCCDDD"}; + + int expectedResult = 350; + + //act + int actualResult = getWinnings(testSymbols, 10); + + //assert + TEST_ASSERT_EQUAL_INT(expectedResult, actualResult); +} \ No newline at end of file From 12ff8cbc056949898d3b347b87875228d832374c Mon Sep 17 00:00:00 2001 From: fdai7472 Date: Mon, 29 Jan 2024 18:37:22 +0100 Subject: [PATCH 57/61] refactoring: Konsolenausgabe etwas schoener formatiert --- src/main/c/Stefan/slot_machine.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/c/Stefan/slot_machine.c b/src/main/c/Stefan/slot_machine.c index e6395ba..d97ff48 100644 --- a/src/main/c/Stefan/slot_machine.c +++ b/src/main/c/Stefan/slot_machine.c @@ -126,6 +126,7 @@ int getWinnings(char symbols[], int bet){ } void showResult(char symbols[]){ + printf("\n"); for (int i = 0; i < ROWS; i++){ printf(" %c | %c | %c\n", symbols[i * ROWS], symbols[i * ROWS + 1], symbols[i * ROWS + 2]); From ad5d29af775a87b4b50f5049c2cb0d56cf2ed4f1 Mon Sep 17 00:00:00 2001 From: fdai7472 Date: Mon, 29 Jan 2024 18:38:36 +0100 Subject: [PATCH 58/61] bugfix: Wetteinsatz von 0 nicht mehr moeglich --- src/main/c/Stefan/slot_machine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/c/Stefan/slot_machine.c b/src/main/c/Stefan/slot_machine.c index d97ff48..a3731e6 100644 --- a/src/main/c/Stefan/slot_machine.c +++ b/src/main/c/Stefan/slot_machine.c @@ -42,7 +42,7 @@ int getBet(int balance){ printf("Wetteinsatz: "); int bet = userInput(); - if(bet <= balance && bet >= 0){ + if(bet <= balance && bet > 0){ return bet; } else { printf("Ungueltige Eingabe!\n"); From a35238d83f2afb679494a8634608d564f4c94903 Mon Sep 17 00:00:00 2001 From: fdai7472 Date: Mon, 29 Jan 2024 19:03:24 +0100 Subject: [PATCH 59/61] Ergebnis wird mit coolem ascii art angezeigt --- src/main/c/Stefan/slot_machine.c | 32 ++++++++++++++++++++++++++------ src/main/c/Stefan/slot_machine.h | 2 +- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/main/c/Stefan/slot_machine.c b/src/main/c/Stefan/slot_machine.c index a3731e6..c7bda9e 100644 --- a/src/main/c/Stefan/slot_machine.c +++ b/src/main/c/Stefan/slot_machine.c @@ -2,6 +2,7 @@ #include #include #include +#include void slotMachine(){ @@ -86,9 +87,10 @@ void randomizeSymbols(char symbols[]){ int spin(char symbols[], int bet, int balance){ - showResult(symbols); - int winnings = getWinnings(symbols, bet); + + showResult(symbols, winnings); + balance += winnings; printf("Aktuelles Guthaben: %d\n-------------------------\n", balance); return balance; @@ -125,12 +127,30 @@ int getWinnings(char symbols[], int bet){ return winnings; } -void showResult(char symbols[]){ - printf("\n"); +void showResult(char symbols[], int winnings){ - for (int i = 0; i < ROWS; i++){ - printf(" %c | %c | %c\n", symbols[i * ROWS], symbols[i * ROWS + 1], symbols[i * ROWS + 2]); + char winnerMessage[] = {""}; + + if(winnings > 0){ + strcpy(winnerMessage, " WINNER "); + } else { + strcpy(winnerMessage, " LOSER "); } + + printf("\n" + " .-------.\n" + " {-%s-} \n" + " .=============.\n" + " | | __\n" + " | [%c] [%c] [%c] |( )\n" + " | [%c] [%c] [%c] | ||\n" + " | [%c] [%c] [%c] | ||\n" + " | |_||\n" + " | xxx ::::::: |--'\n" + " | ooo ::::::: |\n" + " | $$$ ::::::: |\n" + " | __ |\n" + " |_____/__\\____|\n\n", winnerMessage, symbols[0], symbols[1], symbols[2], symbols[3], symbols[4], symbols[5], symbols[6], symbols[7], symbols[8]); } void welcomeMessage(){ diff --git a/src/main/c/Stefan/slot_machine.h b/src/main/c/Stefan/slot_machine.h index 3639e7e..c08b4bb 100644 --- a/src/main/c/Stefan/slot_machine.h +++ b/src/main/c/Stefan/slot_machine.h @@ -14,6 +14,6 @@ int subtractBetFromBalance(int bet, int balance); void randomizeSymbols(char symbols[]); int spin(char symbols[], int bet, int balance); int getWinnings(char symbols[], int bet); -void showResult(char symbols[]); +void showResult(char symbols[], int winnings); #endif // SLOT_MACHINE_H \ No newline at end of file From 28f34d7c9ffaa76dfd6423fa610954d05a9037a3 Mon Sep 17 00:00:00 2001 From: fdai7472 Date: Mon, 29 Jan 2024 19:06:40 +0100 Subject: [PATCH 60/61] bugfix: Guthaben wird nach einem win richtig aktualisiert --- src/main/c/Stefan/slot_machine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/c/Stefan/slot_machine.c b/src/main/c/Stefan/slot_machine.c index c7bda9e..3a34c10 100644 --- a/src/main/c/Stefan/slot_machine.c +++ b/src/main/c/Stefan/slot_machine.c @@ -18,7 +18,7 @@ void slotMachine(){ balance = subtractBetFromBalance(bet, balance); randomizeSymbols(symbols); - spin(symbols, bet, balance); + balance = spin(symbols, bet, balance); } } From d52d1233c4f22a09419cf861f790decbc1a032fc Mon Sep 17 00:00:00 2001 From: fdai7472 Date: Thu, 1 Feb 2024 18:00:44 +0100 Subject: [PATCH 61/61] refactoring: scanf_s zu scanf geaendert --- src/main/c/Stefan/slot_machine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/c/Stefan/slot_machine.c b/src/main/c/Stefan/slot_machine.c index 3a34c10..f659eab 100644 --- a/src/main/c/Stefan/slot_machine.c +++ b/src/main/c/Stefan/slot_machine.c @@ -33,7 +33,7 @@ int getBalance(){ int userInput(){ int input; - scanf_s("%d", &input); + scanf("%d", &input); return input; }