Browse Source

hint after 3 mistakes - function impl

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

28
src/main/c/Hangman/playHangman.c

@ -9,6 +9,34 @@ char toLower(char ch) {
return ch;
}
// Hint function
char *hint = NULL;
int hintAvailable = 1;
char generateHint(char *wordToGuess, char *guessedLetters) {
int length = strlen(wordToGuess);
char availableLetters[length]; // Array to store letters not guessed yet
int numAvailableLetters = 0;
// Check each letter in the word
for (int i = 0; i < length; i++) {
char letter = wordToGuess[i];
// Check if the letter has not been guessed
if (strchr(guessedLetters, letter) == NULL) {
availableLetters[numAvailableLetters++] = letter; // Store the available letter
}
}
// Randomly select a letter from available letters
if (numAvailableLetters > 0) {
int randomIndex = rand() % numAvailableLetters;
return availableLetters[randomIndex];
} else {
// No available letters, return a placeholder value
return '-';
}
}
void playHangman() {
char *wordToGuess;
int mistakes = 0;

Loading…
Cancel
Save