/// <summary> /// Draws the hangman to the console. /// </summary> /// <param name="hangmanPic">Array containing the hangman characters</param> /// <param name="hangManWord">The hidden word with various properties to help with drawing</param> public void DrawGraphics(char[] hangmanPic, HangManMysteryWord hangManWord) { //Extract properties from the class passed char[] mysteryWord = hangManWord.Word.ToCharArray(); MysteryTopic mysteryTopic = hangManWord.Topic; bool[] mysteryWordCover = hangManWord.WordCover; //Clear console to redraw hangman Console.Clear(); //Write each character in the hangman char array for (int i = 0; i < hangmanPic.Length; i++) { Console.Write(hangmanPic[i]); } //Writes the clue on what the word is Console.WriteLine("\n\nTry to guess the mystery {0}\n", mysteryTopic.ToString()); //Iterate through each character of the hidden word for (int i = 0; i < mysteryWord.Length; i++) { //if the cover is true at the index then it will hide the character if (mysteryWordCover[i]) { mysteryWord[i] = '_'; } Console.Write(mysteryWord[i]); } Console.WriteLine("\n"); }
/// <summary> /// GameSetUp(): /// Set up game for a new round /// /// Steps: /// -Get user to select from a topic. /// -Generate a hidden from the chosen topic /// -Reset wrong guesses count to 0. /// -Reset the hang man picture. /// -Clear previously stored input. /// </summary> public void GameSetUp() { Console.Clear(); //Instruct user to choose a topic which determines the kind of words that will be hidden Console.WriteLine("Choose a word topic:" + "\n1 = Planets" + "\n2 = Gods"); //Cast numeric input into enum selectedTopic = (MysteryTopic)InputValidation.ValidateInput((int)MysteryTopic.Planet, (int)MysteryTopic.God); //Generate the properties of the hidden word depending on the enum passed. hiddenWord.ChooseNewWord(selectedTopic); //Reset counter wrongGuesses = 0; //Reset picture to clear any body parts from the previous game fullPicCurrent = HangmanRefresh(fullPicNew.ToCharArray(), wrongGuesses); //Clear any stored inputs if (storedInputs.Count > 0) { storedInputs.Clear(); } }
/// <summary> /// Change the properties of this class depending on the enum passed. /// </summary> /// <param name="chosenTopic"></param> public void ChooseNewWord(MysteryTopic chosenTopic) { switch (chosenTopic) { case MysteryTopic.Planet: wordBank[0] = "MERCURY"; wordBank[1] = "VENUS"; wordBank[2] = "EARTH"; wordBank[3] = "MARS"; wordBank[4] = "JUPITER"; wordBank[5] = "SATURN"; wordBank[6] = "URANUS"; wordBank[7] = "NEPTUNE"; wordBank[8] = "PLUTO"; //Randomly select from word bank Word = wordBank[random.Next(0, (wordBank.Length))]; //Cover size will be the length of the word WordCover = GenerateCover(Word.Length); Topic = chosenTopic; break; case MysteryTopic.God: wordBank[1] = "HADES"; wordBank[2] = "APOLLO"; wordBank[3] = "ODIN"; wordBank[4] = "AEGIR"; wordBank[5] = "RAIJIN"; wordBank[6] = "AMATERASU"; wordBank[0] = "VISHNU"; wordBank[7] = "SHIVA"; wordBank[8] = "ANUBIS"; Word = wordBank[random.Next(0, (wordBank.Length))]; WordCover = GenerateCover(Word.Length); Topic = chosenTopic; break; default: break; } }
/// <summary> ///Default values for constructer, Call ChooseNewWord to change the properties /// </summary> public HangManMysteryWord() { Word = "MERCURY"; WordCover = GenerateCover(Word.Length); Topic = MysteryTopic.Planet; }