I am working on a hangman game still, I would like some hints from this community again.
My code works as follows at the moment: if a user types only one char and hits enter there are two possible outcomes:
if the typed char matches a word in a file, then it returns a matched word.
if not, nothing happens.
On top of this, I would like to add some error messages if more than one char has been entered.
here’s what I have tried - it was supposed to return the error message “one char at a time” but actually nothing happens. I truly appreciate any hints or advice as I kept looking for the fix to no avail.
while (true)
{
string playerGuess;
playerGuess = Console.ReadLine();
if (playerGuess.Length > 2)
{
Console.WriteLine("one character at one time please");
}
char guessed = playerGuess[0];
for (int j = 0; j < mysteryWord.Length; j++)
{
if (guessed == mysteryWord[j])
{
hangman[j] = guessed;
amountOfLettersRevealed++;
}
}
Console.WriteLine(hangman);
if (hangman.Length == amountOfLettersRevealed)
{
Console.WriteLine("hip hip hurray");
}
}