mercredi 24 mars 2021

Coding a Wheel of Fortune in C#?

I need to create a text version of 'Wheel of Fortune.' The program has to pick a random phrase from a file I already have answers stored in, and the user has to guess the letters in the random phrase. An example of what the code should output to the console is:

Wheel of Fortune
Letters Used:
Guesses: 0
****** *** ***

All the way to:

Letters Used: hteio
Guesses: 5
*e*o** the *e*

I'm looking for a way to make a while iteration until the phrase is complete, error check for multiple letters inputted by the user, instantiate a working string, and replace each asterisk with the correctly guessed letter. I need two strings, one phrase from the file, and a working string for the asterisks. I also have a random number generator to pick a new phrase each time, just not sure where to insert it. I currently have my code written as such thus far:

System.IO.StreamReader file =
                new System.IO.StreamReader("answers.txt");
            
            
            int numofansw = int.Parse(file.ReadLine());     // know how many answers there are

            string[] Answers = new string[numofansw];       // creates a slot for every stored answer

            
            // While () to keep iterating until completion

            
            Console.WriteLine("Please enter a single letter: ");
            string input = Console.ReadLine();

            
            //error check for numbers and multiple letters
            while (string.IsNullOrEmpty(input))
            {
                Console.WriteLine("You cannot guess nothing. Input a single letter.");
                input = Console.ReadLine();
            }

            input = input.ToLower();

            
            // instantiate a working answer string

            
            for(int i = 0; i < Answers.Length - 1; i++)
            {
                if (input.Equals(Answers[i]))
                {
                    // Replace stars with correct letters
                }
                
            }



Aucun commentaire:

Enregistrer un commentaire