Browse Source

hint after 3 mistakes - usage

remotes/origin/Saba
Saba Fazlali 11 months ago
parent
commit
aedad7f488
  1. 25
      src/main/c/Hangman/playHangman.c

25
src/main/c/Hangman/playHangman.c

@ -40,7 +40,7 @@ char generateHint(char *wordToGuess, char *guessedLetters) {
void playHangman() {
char *wordToGuess;
int mistakes = 0;
int score = 10;
int score = 6;
char guessedLetters[30] = ""; //Guessed letters
char currentGuess[50]; //Current state of the guessed word
int difficulty;
@ -60,6 +60,27 @@ void playHangman() {
while (mistakes < MAX_MISTAKES) {
// Asks for hint
if (mistakes == 3 && hintAvailable) {
int wantHint;
printf("Do you want a hint? (1 or 2): \n");
printf("1. YES\n");
printf("2. NO\n");
scanf(" %d", &wantHint);
if (tolower(wantHint) == 1) {
char hintLetter = generateHint(wordToGuess, guessedLetters);
if (hintLetter != '-') {
printf("Hint: %c\n", hintLetter); // Provide the hint
hintAvailable = 0; // Hint is provided, mark as unavailable
} else {
printf("No available hint.\n");
}
} else {
printf("No hint provided.\n");
}
}
// Get a letter from the user
char input[20];
printf("Enter your guess: \n");
@ -107,7 +128,7 @@ void playHangman() {
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("your score is %d/6\n", score);
printf("\n"
" __ __ __ __ _ \n"
" \\ \\ / /__ _ _ \\ \\ / /__ _ _ | |\n"

Loading…
Cancel
Save