From d260ad59d57e2ba7ae9f72e46ee51c493889f8df Mon Sep 17 00:00:00 2001 From: Saba Fazlali Date: Thu, 8 Feb 2024 21:03:55 +0100 Subject: [PATCH 1/9] test displayRules --- test/Hangman/test_initializeHangman.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 test/Hangman/test_initializeHangman.c diff --git a/test/Hangman/test_initializeHangman.c b/test/Hangman/test_initializeHangman.c new file mode 100644 index 0000000..9b5238b --- /dev/null +++ b/test/Hangman/test_initializeHangman.c @@ -0,0 +1,23 @@ +#include +#include "playHangman.h" + + +void test_displayRules() { + printf("Test Case 1: User inputs '1'\n"); + printf("Expected Output: 'Let's get started!'\n"); + printf("Actual Output: "); + printf("1\n"); + displayRules(); + + printf("\nTest Case 2: User inputs '2'\n"); + printf("Expected Output: Output of printRules() function\n"); + printf("Actual Output: "); + printf("2\n"); + displayRules(); + + printf("\nTest Case 3: User inputs invalid value\n"); + printf("Expected Output: 'Please enter either 1 or 2 to continue'\n"); + printf("Actual Output: "); + printf("invalid\n"); + displayRules(); +} From 7981d1fb692df505ee359cc8234a6a9d957cf2ef Mon Sep 17 00:00:00 2001 From: Saba Fazlali Date: Thu, 8 Feb 2024 21:21:33 +0100 Subject: [PATCH 2/9] score added --- src/main/c/Hangman/playHangman.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/c/Hangman/playHangman.c b/src/main/c/Hangman/playHangman.c index 93d9998..68e34c0 100644 --- a/src/main/c/Hangman/playHangman.c +++ b/src/main/c/Hangman/playHangman.c @@ -11,6 +11,7 @@ char toLower(char ch) { void playHangman(char *wordToGuess) { int mistakes = 0; + int score = 10; char guessedLetters[30] = ""; //Guessed letters char currentGuess[50]; //Current state of the guessed word @@ -62,12 +63,14 @@ void playHangman(char *wordToGuess) { // Update mistakes (if the guess is wrong) if (!found) { mistakes++; + score--; } // Win: Check if the player guessed all the letters if (strcmp(currentGuess, wordToGuess) == 0) { currentState(currentGuess, mistakes); printf("Bravo! You guessed the word: %s \n", wordToGuess); + printf("your score is %d/10\n", score); printf("\n" " __ __ __ __ _ \n" " \\ \\ / /__ _ _ \\ \\ / /__ _ _ | |\n" From 50cf84877ddc6005e6404456b0eed43f4cf6ac0b Mon Sep 17 00:00:00 2001 From: Saba Fazlali Date: Thu, 8 Feb 2024 23:06:22 +0100 Subject: [PATCH 3/9] adding difficulty to playHangman part one --- .idea/vcs.xml | 7 +++++++ src/main/c/Hangman/playHangman.c | 10 +++++++++- src/main/c/Hangman/playHangman.h | 4 ++-- 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 .idea/vcs.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..9599e0f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/src/main/c/Hangman/playHangman.c b/src/main/c/Hangman/playHangman.c index 68e34c0..166a23b 100644 --- a/src/main/c/Hangman/playHangman.c +++ b/src/main/c/Hangman/playHangman.c @@ -9,14 +9,22 @@ char toLower(char ch) { return ch; } -void playHangman(char *wordToGuess) { +void playHangman() { + char *wordToGuess; int mistakes = 0; int score = 10; char guessedLetters[30] = ""; //Guessed letters char currentGuess[50]; //Current state of the guessed word + int difficulty; displayRules(); + printf("choose the difficulty level: (1 or 2)\n"); + printf("1. Easy \n"); + printf("2. Hard \n"); + scanf("%d", &difficulty); + wordToGuess = selectRandomWord(difficulty); + // Initialize the current guess and print the rules initializeHangman(wordToGuess, currentGuess); currentState(currentGuess, mistakes); diff --git a/src/main/c/Hangman/playHangman.h b/src/main/c/Hangman/playHangman.h index 01e6e6d..b516283 100644 --- a/src/main/c/Hangman/playHangman.h +++ b/src/main/c/Hangman/playHangman.h @@ -10,13 +10,13 @@ // Include function implementations directly from .c files -void playHangman(char *wordToGuess); +void playHangman(); void initializeHangman(char *wordToGuess, char *currentGuess); void printRules(); void drawHangman(int incorrectGuesses); void currentState(char *currentGuess, int mistakes); const char* selectRandomWord(); -const char wordsList[NUM_WORDS][MAX_WORD_LENGTH + 1]; +const char wordsList_easy[NUM_WORDS][MAX_WORD_LENGTH + 1]; void displayRules(); #define MAX_MISTAKES 6 From c726d4f19acadfae274305ead298e8a330f9b6d4 Mon Sep 17 00:00:00 2001 From: Saba Fazlali Date: Thu, 8 Feb 2024 23:07:19 +0100 Subject: [PATCH 4/9] adding difficulty to initialize (part two) --- src/main/c/Hangman/word_selector.c | 68 ++++++++++++++++++++++-------- src/main/c/main.c | 2 +- 2 files changed, 52 insertions(+), 18 deletions(-) diff --git a/src/main/c/Hangman/word_selector.c b/src/main/c/Hangman/word_selector.c index 5b2b914..ff25adb 100644 --- a/src/main/c/Hangman/word_selector.c +++ b/src/main/c/Hangman/word_selector.c @@ -1,33 +1,67 @@ #include "word_selector.h" +#include "playHangman.h" -const char wordsList[NUM_WORDS][MAX_WORD_LENGTH + 1] = { - "skill", +// easy words +const char wordsList_easy[NUM_WORDS][MAX_WORD_LENGTH + 1] = { + "apple", "world", - "difference", - "celebration", - "association", - "customer", + "banana", + "cat", + "lemon", + "dog", "mood", - "agreement", - "audience", - "professor", + "orange", + "kite", + "nest", "year", - "dealer", - "patience", - "table tennis", - "pollution", - "awareness", + "grape", + "sun", + "mouse", + "tennis", + "queen", "problem", "vehicle", "death", "cousin" }; -const char* selectRandomWord() { +// hard words +const char wordsList_hard[NUM_WORDS][MAX_WORD_LENGTH + 1] = { + "database", + "programming", + "mountain", + "customer", + "table tennis", + "customer", + "laughter", + "expression", + "audience", + "professor", + "twilight", + "dealer", + "symphony", + "table tennis", + "pollution", + "inspiration", + "supermarket", + "difficulty", + "budget", + "quarter" +}; + +const char* selectRandomWord(int difficulty) { - // pick a random number and assign it to index of wordsList array + // pick a random number and assign it to index of wordsList_easy array srand((unsigned int)time(NULL)); int randomIndex = rand() % NUM_WORDS; - return wordsList[randomIndex]; + switch(difficulty){ + case 1: + return wordsList_easy[randomIndex]; + case 2: + return wordsList_hard[randomIndex]; + default: + printf("Invalid difficulty level. Using easy difficulty.\n"); + return wordsList_easy[randomIndex]; + } } \ No newline at end of file diff --git a/src/main/c/main.c b/src/main/c/main.c index 4f8b2c5..6155d68 100644 --- a/src/main/c/main.c +++ b/src/main/c/main.c @@ -30,7 +30,7 @@ int main(){ switch (option){ case 1: - playHangman(selectRandomWord()); + playHangman(); break; case 2: pong(); From 96f7a2f77abc8cea751e13dcc723965ab68ec578 Mon Sep 17 00:00:00 2001 From: Saba Fazlali Date: Thu, 8 Feb 2024 23:21:23 +0100 Subject: [PATCH 5/9] clean up word_selector --- src/main/c/Hangman/word_selector.c | 7 +++---- src/main/c/Hangman/word_selector.h | 4 ++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/c/Hangman/word_selector.c b/src/main/c/Hangman/word_selector.c index ff25adb..ec9c547 100644 --- a/src/main/c/Hangman/word_selector.c +++ b/src/main/c/Hangman/word_selector.c @@ -1,8 +1,7 @@ #include "word_selector.h" -#include "playHangman.h" // easy words -const char wordsList_easy[NUM_WORDS][MAX_WORD_LENGTH + 1] = { +char wordsList_easy[NUM_WORDS][MAX_WORD_LENGTH + 1] = { "apple", "world", "banana", @@ -26,7 +25,7 @@ const char wordsList_easy[NUM_WORDS][MAX_WORD_LENGTH + 1] = { }; // hard words -const char wordsList_hard[NUM_WORDS][MAX_WORD_LENGTH + 1] = { +char wordsList_hard[NUM_WORDS][MAX_WORD_LENGTH + 1] = { "database", "programming", "mountain", @@ -49,7 +48,7 @@ const char wordsList_hard[NUM_WORDS][MAX_WORD_LENGTH + 1] = { "quarter" }; -const char* selectRandomWord(int difficulty) { +char* selectRandomWord(int difficulty) { // pick a random number and assign it to index of wordsList_easy array srand((unsigned int)time(NULL)); diff --git a/src/main/c/Hangman/word_selector.h b/src/main/c/Hangman/word_selector.h index d606871..cb13eb7 100644 --- a/src/main/c/Hangman/word_selector.h +++ b/src/main/c/Hangman/word_selector.h @@ -9,4 +9,8 @@ #define MAX_WORD_LENGTH 20 #define NUM_WORDS 20 +char* selectRandomWord(); +char wordsList_easy[NUM_WORDS][MAX_WORD_LENGTH + 1]; +char wordsList_hard[NUM_WORDS][MAX_WORD_LENGTH + 1]; + #endif //PMUW_PROJEKT_NOTEBINDER_WORD_SELECTOR_H From 2294174e2f6a47da4bbeb876d97ccc4cfe6447a1 Mon Sep 17 00:00:00 2001 From: Saba Fazlali Date: Thu, 8 Feb 2024 23:21:49 +0100 Subject: [PATCH 6/9] clean up header files --- src/main/c/Hangman/drawHangman.h | 3 +++ src/main/c/Hangman/initializeHangman.h | 5 +++++ src/main/c/Hangman/playHangman.h | 10 ++-------- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/c/Hangman/drawHangman.h b/src/main/c/Hangman/drawHangman.h index 2c31273..2c1256d 100644 --- a/src/main/c/Hangman/drawHangman.h +++ b/src/main/c/Hangman/drawHangman.h @@ -3,4 +3,7 @@ #include +void drawHangman(int incorrectGuesses); +void currentState(char *currentGuess, int mistakes); + #endif //PMUW_PROJEKT_NOTEBINDER_DRAWHANGMAN_H diff --git a/src/main/c/Hangman/initializeHangman.h b/src/main/c/Hangman/initializeHangman.h index 58f5700..a7159d1 100644 --- a/src/main/c/Hangman/initializeHangman.h +++ b/src/main/c/Hangman/initializeHangman.h @@ -3,4 +3,9 @@ #include #include #include + +void initializeHangman(char *wordToGuess, char *currentGuess); +void printRules(); +void displayRules(); + #endif //PMUW_PROJEKT_NOTEBINDER_INITIALIZEHANGMAN_H diff --git a/src/main/c/Hangman/playHangman.h b/src/main/c/Hangman/playHangman.h index b516283..4adc2ce 100644 --- a/src/main/c/Hangman/playHangman.h +++ b/src/main/c/Hangman/playHangman.h @@ -8,16 +8,10 @@ #include "drawHangman.h" #include "word_selector.h" +#define MAX_MISTAKES 6 + // Include function implementations directly from .c files void playHangman(); -void initializeHangman(char *wordToGuess, char *currentGuess); -void printRules(); -void drawHangman(int incorrectGuesses); -void currentState(char *currentGuess, int mistakes); -const char* selectRandomWord(); -const char wordsList_easy[NUM_WORDS][MAX_WORD_LENGTH + 1]; -void displayRules(); -#define MAX_MISTAKES 6 #endif // PMUW_PROJEKT_NOTEBINDER_PLAYHANGMAN_H From 548df522ad8b3a1ecc51c8608d1f17e36073c07b Mon Sep 17 00:00:00 2001 From: Saba Fazlali Date: Thu, 8 Feb 2024 23:31:39 +0100 Subject: [PATCH 7/9] super hard words in list --- src/main/c/Hangman/word_selector.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/main/c/Hangman/word_selector.c b/src/main/c/Hangman/word_selector.c index ec9c547..ed6d2ac 100644 --- a/src/main/c/Hangman/word_selector.c +++ b/src/main/c/Hangman/word_selector.c @@ -48,6 +48,30 @@ char wordsList_hard[NUM_WORDS][MAX_WORD_LENGTH + 1] = { "quarter" }; +// super hard words +char wordsList_super_hard[NUM_WORDS][MAX_WORD_LENGTH + 1] = { + "Cacophony", + "Rambunctious", + "Serendipity", + "Resilience", + "Discombobulate", + "Pernicious", + "Eccentricity", + "Mellifluous", + "Ineffable", + "Obfuscate", + "Quixotic", + "Paradoxical", + "Esoteric", + "Perspicacious", + "Indubitable", + "Incandescent", + "Vicissitude", + "Juxtaposition", + "Exacerbate", + "Epiphany" +}; + char* selectRandomWord(int difficulty) { // pick a random number and assign it to index of wordsList_easy array @@ -59,6 +83,8 @@ char* selectRandomWord(int difficulty) { return wordsList_easy[randomIndex]; case 2: return wordsList_hard[randomIndex]; + case 3: + return wordsList_super_hard[randomIndex]; default: printf("Invalid difficulty level. Using easy difficulty.\n"); return wordsList_easy[randomIndex]; From d0197b20aab5b53b3bf4f7eae12658a88aff12a8 Mon Sep 17 00:00:00 2001 From: Saba Fazlali Date: Thu, 8 Feb 2024 23:36:29 +0100 Subject: [PATCH 8/9] super hard level added to game --- src/main/c/Hangman/playHangman.c | 3 ++- src/main/c/Hangman/word_selector.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/c/Hangman/playHangman.c b/src/main/c/Hangman/playHangman.c index 166a23b..4aa6739 100644 --- a/src/main/c/Hangman/playHangman.c +++ b/src/main/c/Hangman/playHangman.c @@ -19,9 +19,10 @@ void playHangman() { displayRules(); - printf("choose the difficulty level: (1 or 2)\n"); + printf("choose the difficulty level: (1, 2 or 3)\n"); printf("1. Easy \n"); printf("2. Hard \n"); + printf("3. Super hard \n"); scanf("%d", &difficulty); wordToGuess = selectRandomWord(difficulty); diff --git a/src/main/c/Hangman/word_selector.c b/src/main/c/Hangman/word_selector.c index ed6d2ac..2edbc1c 100644 --- a/src/main/c/Hangman/word_selector.c +++ b/src/main/c/Hangman/word_selector.c @@ -86,7 +86,7 @@ char* selectRandomWord(int difficulty) { case 3: return wordsList_super_hard[randomIndex]; default: - printf("Invalid difficulty level. Using easy difficulty.\n"); + printf("Invalid difficulty level. We choose easy level for you.\n"); return wordsList_easy[randomIndex]; } } \ No newline at end of file From 31b3bbfb83761683e08aec16fef985886de3dc59 Mon Sep 17 00:00:00 2001 From: Saba Fazlali Date: Thu, 8 Feb 2024 23:56:19 +0100 Subject: [PATCH 9/9] ask the player for retry --- src/main/c/Hangman/playHangman.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/c/Hangman/playHangman.c b/src/main/c/Hangman/playHangman.c index 4aa6739..59fa7cc 100644 --- a/src/main/c/Hangman/playHangman.c +++ b/src/main/c/Hangman/playHangman.c @@ -93,7 +93,17 @@ void playHangman() { if (mistakes == MAX_MISTAKES) { currentState(currentGuess, mistakes); printf("Oops! You have no more guesses :( \n The answer was: %s \n", wordToGuess); - break; + int retry; + printf("Do you want to retry? \n"); + printf("1. YES\n"); + printf("2. NO\n"); + scanf("%d", &retry); + + if (retry == 1){ + playHangman(); + } else { + break; + } } currentState(currentGuess, mistakes);