Browse Source

score added

remotes/origin/Saba
Saba Fazlali 11 months ago
parent
commit
7981d1fb69
  1. 3
      src/main/c/Hangman/playHangman.c

3
src/main/c/Hangman/playHangman.c

@ -11,6 +11,7 @@ char toLower(char ch) {
void playHangman(char *wordToGuess) { void playHangman(char *wordToGuess) {
int mistakes = 0; int mistakes = 0;
int score = 10;
char guessedLetters[30] = ""; //Guessed letters char guessedLetters[30] = ""; //Guessed letters
char currentGuess[50]; //Current state of the guessed word char currentGuess[50]; //Current state of the guessed word
@ -62,12 +63,14 @@ void playHangman(char *wordToGuess) {
// Update mistakes (if the guess is wrong) // Update mistakes (if the guess is wrong)
if (!found) { if (!found) {
mistakes++; mistakes++;
score--;
} }
// 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);
printf("your score is %d/10\n", score);
printf("\n" printf("\n"
" __ __ __ __ _ \n" " __ __ __ __ _ \n"
" \\ \\ / /__ _ _ \\ \\ / /__ _ _ | |\n" " \\ \\ / /__ _ _ \\ \\ / /__ _ _ | |\n"

Loading…
Cancel
Save