Browse Source

draw hangman based on mistakes

remotes/origin/Saba
Saba Fazlali 11 months ago
parent
commit
4bd1c49cc3
  1. BIN
      cmake-build-debug/.ninja_deps
  2. 2
      cmake-build-debug/.ninja_log
  3. 4
      cmake-build-debug/Testing/Temporary/LastTest.log
  4. 1
      src/main/c/Hangman/currentState.c
  5. 1
      src/main/c/Hangman/currentState.h
  6. 2
      src/main/c/Hangman/drawHangman.c
  7. 13
      src/main/c/Hangman/playHangman.c
  8. 7
      src/main/c/Hangman/playHangman.h

BIN
cmake-build-debug/.ninja_deps

2
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 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 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 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

4
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

1
src/main/c/Hangman/currentState.c

@ -3,4 +3,5 @@
void currentState(char *currentGuess, int mistakes) { void currentState(char *currentGuess, int mistakes) {
printf("Current Word: %s \n", currentGuess); printf("Current Word: %s \n", currentGuess);
printf("Mistakes Made: %d/6 \n", mistakes); printf("Mistakes Made: %d/6 \n", mistakes);
drawHangman(mistakes);
} }

1
src/main/c/Hangman/currentState.h

@ -1,4 +1,5 @@
#ifndef PMUW_PROJEKT_NOTEBINDER_CURRENTSTATE_H #ifndef PMUW_PROJEKT_NOTEBINDER_CURRENTSTATE_H
#define PMUW_PROJEKT_NOTEBINDER_CURRENTSTATE_H #define PMUW_PROJEKT_NOTEBINDER_CURRENTSTATE_H
#include <stdio.h> #include <stdio.h>
#include "drawHangman.c"
#endif //PMUW_PROJEKT_NOTEBINDER_CURRENTSTATE_H #endif //PMUW_PROJEKT_NOTEBINDER_CURRENTSTATE_H

2
src/main/c/Hangman/drawHangman.c

@ -72,7 +72,7 @@ void drawHangman(int incorrectGuesses) {
printf("=========\n"); printf("=========\n");
} }
if (incorrectGuesses >= 7) {
if (incorrectGuesses >= 6) {
printf(" \n"); printf(" \n");
printf(" __ _ __ _ _ __ ___ ___ _____ _____ _ __ \n"); printf(" __ _ __ _ _ __ ___ ___ _____ _____ _ __ \n");
printf(" / _` |/ _` | '_ ` _ \\ / _ \\ / _ \\ \\ / / _ \\ '__|\n"); printf(" / _` |/ _` | '_ ` _ \\ / _ \\ / _ \\ \\ / / _ \\ '__|\n");

13
src/main/c/Hangman/playHangman.c

@ -1,9 +1,10 @@
#include "playHangman.h" #include "playHangman.h"
void playHangman(char *wordToGuess) { void playHangman(char *wordToGuess) {
int mistakes = 0; 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 // Initialize the current guess and print the rules
initializeHangman(wordToGuess, currentGuess); initializeHangman(wordToGuess, currentGuess);
@ -17,7 +18,7 @@ void playHangman(char *wordToGuess) {
printf("Enter your guess: \n"); printf("Enter your guess: \n");
scanf(" %c", &guess); 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)) { if (!isalpha(guess) || isupper(guess)) {
printf("Please enter a valid lowercase alphabet.\n"); printf("Please enter a valid lowercase alphabet.\n");
continue; continue;
@ -42,19 +43,19 @@ void playHangman(char *wordToGuess) {
} }
// Update mistakes (if the guess is wrong) // Update mistakes (if the guess is wrong)
if(!found){
if (!found) {
mistakes++; mistakes++;
} }
// Win: Check if the player guessed all the letters // Win: Check if the player guessed all the letters
if (strcmp(currentGuess,wordToGuess) == 0){
if (strcmp(currentGuess, wordToGuess) == 0) {
currentState(currentGuess, mistakes); currentState(currentGuess, mistakes);
printf("Bravo! You guessed the word: %s \n", wordToGuess); printf("Bravo! You guessed the word: %s \n", wordToGuess);
break; break;
} }
// Lose: Print the answer + game over // Lose: Print the answer + game over
if (mistakes == MAX_MISTAKES){
if (mistakes == MAX_MISTAKES) {
currentState(currentGuess, mistakes); currentState(currentGuess, mistakes);
printf("Oops! You have no more guesses :( \n The answer was: %s \n", wordToGuess); printf("Oops! You have no more guesses :( \n The answer was: %s \n", wordToGuess);
} }

7
src/main/c/Hangman/playHangman.h

@ -1,7 +1,3 @@
//
// Created by Saba Fazlali on 31.01.24.
//
#ifndef PMUW_PROJEKT_NOTEBINDER_PLAYHANGMAN_H #ifndef PMUW_PROJEKT_NOTEBINDER_PLAYHANGMAN_H
#define PMUW_PROJEKT_NOTEBINDER_PLAYHANGMAN_H #define PMUW_PROJEKT_NOTEBINDER_PLAYHANGMAN_H
#include <stdio.h> #include <stdio.h>
@ -10,4 +6,5 @@
#include "rules.c" #include "rules.c"
#include "currentState.c" #include "currentState.c"
#include "drawHangman.c" #include "drawHangman.c"
#endif //PMUW_PROJEKT_NOTEBINDER_PLAYHANGMAN_H
#include "word_selector.c"
#endif //PMUW_PROJEKT_NOTEBINDER_PLAYHANGMAN_H
Loading…
Cancel
Save