|
@ -55,22 +55,32 @@ void playHangman(char *wordToGuess) { |
|
|
printf("Enter your guess: \n"); |
|
|
printf("Enter your guess: \n"); |
|
|
scanf("%s", input); |
|
|
scanf("%s", input); |
|
|
|
|
|
|
|
|
// Check if a valid character is entered |
|
|
|
|
|
if (guess == '\0') { |
|
|
|
|
|
|
|
|
// Check if the input is a single letter |
|
|
|
|
|
if(strlen(input) > 1) { |
|
|
printf("Invalid input. Please enter a single letter.\n"); |
|
|
printf("Invalid input. Please enter a single letter.\n"); |
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Check if the input is an alphabet |
|
|
|
|
|
char guess = input[0]; |
|
|
|
|
|
if (!isalpha(guess)) { |
|
|
|
|
|
printf("Please enter a valid alphabet.\n"); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Convert uppercase letter to lowercase |
|
|
// Convert uppercase letter to lowercase |
|
|
guess = toLower(guess); |
|
|
guess = toLower(guess); |
|
|
|
|
|
|
|
|
// Check if the guess is a letter (valid) |
|
|
|
|
|
if (!isalpha(guess)) { |
|
|
|
|
|
printf("Please enter a valid alphabet.\n"); |
|
|
|
|
|
ignoreExtraInput(); |
|
|
|
|
|
|
|
|
// Check if the letter has already been guessed by the player |
|
|
|
|
|
if (strchr(guessedLetters, guess) != NULL) { |
|
|
|
|
|
printf("You already guessed that letter. Try another letter.\n"); |
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Add the guessed letter to the list |
|
|
|
|
|
guessedLetters[strlen(guessedLetters)] = guess; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check if the letter has already been guessed by the player |
|
|
// Check if the letter has already been guessed by the player |
|
|
if (strchr(guessedLetters, guess) != NULL) { |
|
|
if (strchr(guessedLetters, guess) != NULL) { |
|
|
printf("You already guessed that letter. Try another letter.\n"); |
|
|
printf("You already guessed that letter. Try another letter.\n"); |
|
|