Create a console based application with a game similar to Hangman in which a pla
ID: 3650095 • Letter: C
Question
Create a console based application with a game similar to Hangman in which a player guessesletters to try to replicate a hidden word. Store at least eight
words in an array, and randomly select one to be the hidden
word. (Th e statements needed to generate a random number
are shown in the Exercises in the Decision Making and
Looping chapters.) Initially, display the hidden word using
asterisks to represent each letter. Allow the user to guess letters
to replace the asterisks in the hidden word until the user
completes the entire word. If the user guesses a letter that is
not in the hidden word, display an appropriate message. If
the user guesses a letter that appears multiple times in the
hidden word, make sure that each correct letter is placed
Explanation / Answer
Solution: namespace Hangman2 { class Hangman { static void Main(string[] args) { Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.Red; string Name; string sInput; //declaring the word array string[] wordBank = new string[5]; wordBank[0] = "Dog"; wordBank[1] = "Computer"; wordBank[2] = "Tree"; wordBank[3] = "Balls"; wordBank[4] = "House"; //displaying the game layout Console.WriteLine(" ************************ "); Console.WriteLine(" * HANGMAN! * "); Console.WriteLine(" ************************ "); Console.WriteLine(" ________________ "); Console.WriteLine(" | | "); Console.WriteLine(" | ( ) "); Console.WriteLine(" | /|\ "); Console.WriteLine(" | | "); Console.WriteLine(" | /|\ "); Console.WriteLine(" | "); Console.WriteLine(" | "); Console.WriteLine(" |_______ "); //Ask user to Enter Name Console.Write("Enter your Name: "); Name = Convert.ToString(Console.ReadLine()); Console.Clear(); //displaying user greeting message Console.WriteLine(Name + ", Welcome"); Console.WriteLine(" ************************ "); Console.WriteLine(" * HANGMAN! * "); Console.WriteLine(" ************************ "); Console.WriteLine(); //draw the hang structure Console.WriteLine(" ______________ "); Console.WriteLine(" |/ "); Console.WriteLine(" | "); Console.WriteLine(" | "); Console.WriteLine(" | "); Console.WriteLine(" | "); Console.WriteLine(" | "); Console.WriteLine(" |_______ "); //declare the word list display/output condition if (wordBank[0].Length == 3) { Console.WriteLine(" The word is : _ _ _ "); } else if (wordBank[1].Length == 8) { Console.WriteLine(" The word is : _ _ _ _ _ _ _ _ "); } else if (wordBank[2].Length == 4) { Console.WriteLine(" The word is : _ _ _ _ "); } else if (wordBank[3].Length == 5) { Console.WriteLine(" The word is : _ _ _ _ _ "); } else if (wordBank[4].Length == 5) { Console.WriteLine(" The word is : _ _ _ _ _ "); } Console.WriteLine(); Console.WriteLine(" ***Enter a new letter***"); sInput = Convert.ToString(Console.ReadLine()); Console.ReadKey(); } } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.