So I am working on a hangman program. It will pull from a list of 126 different words and randomly select one of the words. It will also output an "_" for each character.
But now, when I'm trying to determine the 'correct guess' of the word, I can't figure out how to actually store the value of the randomly chosen word. Sounds funny, but what have you. lol.
String[] myWordArrays = File.ReadAllLines("WordList.txt");
Random randomWord = new Random();
//int lineCount = File.ReadLines("WordList.txt").Count();
int activeWord = randomWord.Next(0, myWordArrays.Length);
string userSelection = "";
Console.WriteLine("Are you Ready to play Hangman? yes/no: ");
userSelection = Console.ReadLine();
if(userSelection == "yes")
{
foreach(char letter in myWordArrays[activeWord])
{
//the console.write(activeword) only shows the line number o.0.
//when I try to print out .Write(myWordArrays) it shows a
//System.(something) on the screen. ugh.
Console.Write(activeWord);
Console.Write("_ ");
}
I believe this is all the code that needs to be referenced as it is really the only code that deals with the choosing of the random word. I'm truly baffled by this. I've tried to set different things to the active word and I can't think of any logical way to have the 'foreach' also place each letter into an array (which would be beneficial later when I'm ready to search for each letter when the user guesses the letter).
Aucun commentaire:
Enregistrer un commentaire