Okay, so I'm creating a hang-man game (Lame, I know, but I gotta' start somewhere). I have successfully pulled ~30 random words from a text file into a variable and can properly display the word in a random order onto the screen (just to test and make sure the variable is obtaining a whole word in random order).
But I need to take that string and break it into single characters in order to 'blank' out the letters to be 'guessed' by the user. I assume an array is the best way to do this - coupled with a while loop that will run while the character != null.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Hangman
{
class Program
{
static void Main(string[] args)
{
String[] myWordArrays = File.ReadAllLines("WordList.txt");
Random randomWord = new Random();
int lineCount = File.ReadLines("WordList.txt").Count();
int activeWord = randomWord.Next(0, lineCount);
/*CharEnumerator activeWordChar = activeWord; --- I have tried this,
but it says "Cannot implicitly convert type 'int' to 'System.CharEnumerator'
--- while redlining "activeWord." */
/*CharEnumerator activeWordChar = activeWord.ToString
-- I have tried this but it says "Cannot convert method group 'ToString' to
non-delegate type 'System.CharEnumerator'. Did you intend to invoke the method?
I also tried moving the declaration of activeWordChar below the 'writeline'
that displays the word properly to the console.
I have even tried to create a Char[] activeWordChar = activeWord.toCharArray; But this doesn't work either.
*/
//I'm using this writeline "the word for this game is: " ONLY to test that the
//system is choosing random word **end comment
Console.WriteLine("The Word for this game is: " + myWordArrays[activeWord]);
//Console.WriteLine("The Characters are like this: " + activeWordChar[]);
//my attempt at printing something, but it doesn't work. :(
Console.ReadLine();
}
}
}
I'm open to references in order to figure it out myself, but I'm kinda' stuck here.
Also, how do I close the file that I've opened so that it can be accessed later on in the program if need be? I've only learned the StreamReader("filename") way of 'variable.Close();' - but that isn't working here.
Edit
And why someone would vote this question down is beyond me. lol
var chars = "abcd".ToArray();myWordArrays[activeWord].ToArray():)