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/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.c b/src/main/c/Hangman/playHangman.c index 93d9998..59fa7cc 100644 --- a/src/main/c/Hangman/playHangman.c +++ b/src/main/c/Hangman/playHangman.c @@ -9,13 +9,23 @@ 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, 2 or 3)\n"); + printf("1. Easy \n"); + printf("2. Hard \n"); + printf("3. Super hard \n"); + scanf("%d", &difficulty); + wordToGuess = selectRandomWord(difficulty); + // Initialize the current guess and print the rules initializeHangman(wordToGuess, currentGuess); currentState(currentGuess, mistakes); @@ -62,12 +72,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" @@ -81,7 +93,17 @@ void playHangman(char *wordToGuess) { 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); diff --git a/src/main/c/Hangman/playHangman.h b/src/main/c/Hangman/playHangman.h index 01e6e6d..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(char *wordToGuess); -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]; -void displayRules(); -#define MAX_MISTAKES 6 +void playHangman(); #endif // PMUW_PROJEKT_NOTEBINDER_PLAYHANGMAN_H diff --git a/src/main/c/Hangman/word_selector.c b/src/main/c/Hangman/word_selector.c index 5b2b914..2edbc1c 100644 --- a/src/main/c/Hangman/word_selector.c +++ b/src/main/c/Hangman/word_selector.c @@ -1,33 +1,92 @@ #include "word_selector.h" -const char wordsList[NUM_WORDS][MAX_WORD_LENGTH + 1] = { - "skill", +// easy words +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 +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" +}; + +// 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 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]; + case 3: + return wordsList_super_hard[randomIndex]; + default: + printf("Invalid difficulty level. We choose easy level for you.\n"); + return wordsList_easy[randomIndex]; + } } \ No newline at end of file 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 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(); 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(); +}