From 13067a097c463aeba1a07bf328288a25a4405f1d Mon Sep 17 00:00:00 2001 From: fdai7727 Date: Thu, 25 Jan 2024 19:38:22 +0100 Subject: [PATCH 01/36] 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/36] =?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/36] 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/36] =?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/36] 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/36] =?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/36] =?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/36] =?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/36] =?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/36] =?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/36] 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/36] =?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/36] =?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/36] 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/36] =?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/36] =?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/36] 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/36] =?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/36] =?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/36] 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/36] =?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/36] =?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/36] =?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/36] =?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/36] 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/36] =?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/36] =?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/36] =?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/36] =?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/36] =?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/36] =?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/36] =?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/36] =?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/36] =?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/36] =?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/36] =?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