From 4bd1c49cc370b1a7ffc74a886b4d50379c1d17ed Mon Sep 17 00:00:00 2001 From: Saba Fazlali Date: Thu, 1 Feb 2024 15:35:14 +0100 Subject: [PATCH] draw hangman based on mistakes --- cmake-build-debug/.ninja_deps | Bin 12840 -> 13436 bytes cmake-build-debug/.ninja_log | 2 ++ .../Testing/Temporary/LastTest.log | 4 ++-- src/main/c/Hangman/currentState.c | 1 + src/main/c/Hangman/currentState.h | 1 + src/main/c/Hangman/drawHangman.c | 2 +- src/main/c/Hangman/playHangman.c | 13 +++++++------ src/main/c/Hangman/playHangman.h | 7 ++----- 8 files changed, 16 insertions(+), 14 deletions(-) diff --git a/cmake-build-debug/.ninja_deps b/cmake-build-debug/.ninja_deps index 7d5b5d0938bbe3b64c05a200b6d3367d5925ad09..b396b92a0d4c72c2842617482a283e1f842a0f49 100644 GIT binary patch delta 77 zcmZ3H@+V`1hLPwJ28M=M1_lOpBh^)V4zCxF1G4ibFO;1ux`L6RAr;8${`VX#lLlm` YgJdQL=!dWd0(n7`4duEgn`kNk001)?OaK4? delta 7 Ocmey9u_9%Ih7kY|#RGc) diff --git a/cmake-build-debug/.ninja_log b/cmake-build-debug/.ninja_log index d117789..5f3acae 100644 --- a/cmake-build-debug/.ninja_log +++ b/cmake-build-debug/.ninja_log @@ -13,3 +13,5 @@ 1 214 1706706276607344137 CMakeFiles/pmuw_projekt_notebinder.dir/src/main/c/Hangman/drawHangman.c.o de5f7edc6c2379d7 1 214 1706706276607374928 CMakeFiles/pmuw_projekt_notebinder.dir/src/main/c/Hangman/rules.c.o cdaff7b94c55641c 1 214 1706706276607365429 CMakeFiles/pmuw_projekt_notebinder.dir/src/main/c/Hangman/initializeHangman.c.o 7d64de4520ec9e97 +1 43 1706797998872539655 CMakeFiles/pmuw_projekt_notebinder.dir/src/main/c/Hangman/drawHangman.c.o de5f7edc6c2379d7 +2 56 1706797998885305995 CMakeFiles/pmuw_projekt_notebinder.dir/src/main/c/Hangman/playHangman.c.o f2e2af7048638ee6 diff --git a/cmake-build-debug/Testing/Temporary/LastTest.log b/cmake-build-debug/Testing/Temporary/LastTest.log index f24ee92..4dbb2b2 100644 --- a/cmake-build-debug/Testing/Temporary/LastTest.log +++ b/cmake-build-debug/Testing/Temporary/LastTest.log @@ -1,3 +1,3 @@ -Start testing: Jan 31 13:25 CET +Start testing: Feb 01 15:14 CET ---------------------------------------------------------- -End testing: Jan 31 13:25 CET +End testing: Feb 01 15:14 CET diff --git a/src/main/c/Hangman/currentState.c b/src/main/c/Hangman/currentState.c index 6ee9bac..e4bc459 100644 --- a/src/main/c/Hangman/currentState.c +++ b/src/main/c/Hangman/currentState.c @@ -3,4 +3,5 @@ void currentState(char *currentGuess, int mistakes) { printf("Current Word: %s \n", currentGuess); printf("Mistakes Made: %d/6 \n", mistakes); + drawHangman(mistakes); } \ No newline at end of file diff --git a/src/main/c/Hangman/currentState.h b/src/main/c/Hangman/currentState.h index 41a99ec..dbf10bf 100644 --- a/src/main/c/Hangman/currentState.h +++ b/src/main/c/Hangman/currentState.h @@ -1,4 +1,5 @@ #ifndef PMUW_PROJEKT_NOTEBINDER_CURRENTSTATE_H #define PMUW_PROJEKT_NOTEBINDER_CURRENTSTATE_H #include +#include "drawHangman.c" #endif //PMUW_PROJEKT_NOTEBINDER_CURRENTSTATE_H diff --git a/src/main/c/Hangman/drawHangman.c b/src/main/c/Hangman/drawHangman.c index 4a78ad5..46bed5b 100644 --- a/src/main/c/Hangman/drawHangman.c +++ b/src/main/c/Hangman/drawHangman.c @@ -72,7 +72,7 @@ void drawHangman(int incorrectGuesses) { printf("=========\n"); } - if (incorrectGuesses >= 7) { + if (incorrectGuesses >= 6) { printf(" \n"); printf(" __ _ __ _ _ __ ___ ___ _____ _____ _ __ \n"); printf(" / _` |/ _` | '_ ` _ \\ / _ \\ / _ \\ \\ / / _ \\ '__|\n"); diff --git a/src/main/c/Hangman/playHangman.c b/src/main/c/Hangman/playHangman.c index e90d030..31cfb79 100644 --- a/src/main/c/Hangman/playHangman.c +++ b/src/main/c/Hangman/playHangman.c @@ -1,9 +1,10 @@ #include "playHangman.h" + void playHangman(char *wordToGuess) { int mistakes = 0; - char guessedLetters[30]; //guessed letters - char currentGuess[50]; //current state of the guessed word + char guessedLetters[30]; //Guessed letters + char currentGuess[50]; //Current state of the guessed word // Initialize the current guess and print the rules initializeHangman(wordToGuess, currentGuess); @@ -17,7 +18,7 @@ void playHangman(char *wordToGuess) { printf("Enter your guess: \n"); scanf(" %c", &guess); - // check if the guess is lower case and is a letter (valid) + // Check if the guess is lower case and is a letter (valid) if (!isalpha(guess) || isupper(guess)) { printf("Please enter a valid lowercase alphabet.\n"); continue; @@ -42,19 +43,19 @@ void playHangman(char *wordToGuess) { } // Update mistakes (if the guess is wrong) - if(!found){ + if (!found) { mistakes++; } // Win: Check if the player guessed all the letters - if (strcmp(currentGuess,wordToGuess) == 0){ + if (strcmp(currentGuess, wordToGuess) == 0) { currentState(currentGuess, mistakes); printf("Bravo! You guessed the word: %s \n", wordToGuess); break; } // Lose: Print the answer + game over - if (mistakes == MAX_MISTAKES){ + if (mistakes == MAX_MISTAKES) { currentState(currentGuess, mistakes); printf("Oops! You have no more guesses :( \n The answer was: %s \n", wordToGuess); } diff --git a/src/main/c/Hangman/playHangman.h b/src/main/c/Hangman/playHangman.h index 6a96e42..ca1348e 100644 --- a/src/main/c/Hangman/playHangman.h +++ b/src/main/c/Hangman/playHangman.h @@ -1,7 +1,3 @@ -// -// Created by Saba Fazlali on 31.01.24. -// - #ifndef PMUW_PROJEKT_NOTEBINDER_PLAYHANGMAN_H #define PMUW_PROJEKT_NOTEBINDER_PLAYHANGMAN_H #include @@ -10,4 +6,5 @@ #include "rules.c" #include "currentState.c" #include "drawHangman.c" -#endif //PMUW_PROJEKT_NOTEBINDER_PLAYHANGMAN_H +#include "word_selector.c" +#endif //PMUW_PROJEKT_NOTEBINDER_PLAYHANGMAN_H \ No newline at end of file