I am creating a hangman game right now. The error in the title pops up while my code tries to translate user inputs into string
. Could anyone kindly give me some hints?
static void Main(string[] args)
{
int amountOfLettersRevealed = 0;
Console.WriteLine("Welcome to Hangman!!!!!!!!!!");
Console.InputEncoding = Encoding.Default;
string[] listwords = File.ReadAllLines(@"/Users/annamusterfrau/Desktop/C#_co/italian.txt");
Random randGen = new Random();
var idx = randGen.Next(0, 9);
string mysteryWord = listwords[idx];
string[] hangman = new string[mysteryWord.Length];
Console.Write("Please enter your guess: ");
for (int p = 0; p < mysteryWord.Length; p++)
{
hangman[p] = "*";
}
while (true)
{
string playerGuess;
playerGuess = Console.ReadLine();
var guessed = Int32.Parse(playerGuess);
//char playerGuess = char.Parse(Console.ReadLine());
for (int j = 0; j < mysteryWord.Length; j++)
{
if (guessed == mysteryWord[j])
{
//Cannot convert source type 'int' to target type 'string'
hangman[j] = guessed;
amountOfLettersRevealed++;
}
}
Console.WriteLine(hangman);
if (hangman.Length == amountOfLettersRevealed)
{
Console.WriteLine("hip hip hurray");
}
}
}