/// <summary> /// Main loop; game logic /// </summary> /// <param name="hangman"></param> /// <returns></returns> bool PlayHangman(HangmanGame hangman) { List <char> enteredLetters = new List <char>(); int attempts = 8; bool wordGuessed = hangman.isGuessed(); while (attempts > 0 && wordGuessed == false) { char letter = ReadLetter(enteredLetters); enteredLetters.Add(letter); // Deduct attempts if a wrong letter was entered if (!hangman.GuessLetter(letter)) { attempts--; } // Display current information Console.Write("Entered letters: "); DisplayLetters(enteredLetters); Console.WriteLine("{0} Attempts left.", attempts); Console.WriteLine(); DisplayWord(hangman.guessedWord); Console.WriteLine(); // Exit once the game is won wordGuessed = hangman.isGuessed(); if (wordGuessed) { return(true); } } return(false); }
bool PlayHangman(HangmanGame hangman) { List <char> enteredLetters = new List <char>(); DisplayWord(hangman.guessedWord); //from question int attempts = 8; //starting amount of attempts for guessing Console.WriteLine(); //for spacing //this is for the attepts and askng for the letters while (!hangman.isGuessed() && attempts > 1) //if the word is not guess and the nr of attempts are more than one. { char letter = ReadLetter(enteredLetters); if (!hangman.GuessLetter(letter))//of the letter is not in the word, lose 1 attempts. { attempts--; } Console.Write("Entered letters: "); DisplayLetters(enteredLetters); Console.WriteLine();//for the spacings Console.WriteLine("Attempts left: " + attempts); DisplayWord(hangman.guessedWord); Console.WriteLine(); } return(hangman.isGuessed()); }