示例#1
0
        public void GenerateDisplayWordString(HangmanModel model)
        {
            StringBuilder sb            = new StringBuilder();
            bool          correctLetter = false;
            string        winningWord   = model.WinningWord;

            for (int i = 0; i < winningWord.Length; i++)
            {
                correctLetter = false;
                foreach (string temp in model.GuessList)
                {
                    if (winningWord[i].ToString().Equals(temp))
                    {
                        correctLetter = true;
                    }
                }
                if (!correctLetter)
                {
                    sb.Append("_ ");
                }
                else
                {
                    sb.Append(winningWord[i].ToString()).Append(" ");
                }
            }
            model.DisplayWordString = sb.ToString();
        }
示例#2
0
        public void CheckLatestGuess(HangmanModel model, string newGuess)
        {
            StringBuilder sb            = new StringBuilder();
            bool          correctLetter = false;
            string        winningWord   = model.WinningWord;

            model.GuessList.Add(newGuess);
            for (int i = 0; i < winningWord.Length; i++)
            {
                if (winningWord[i].ToString().Equals(newGuess))
                {
                    model.CorrectGuessCount++;
                    correctLetter = true;
                }
            }
            if (!correctLetter)
            {
                model.WrongGuessCount++;
                model.WrongGuessList.Add(newGuess);
            }

            sb.Append("Wrong Guesses: ");
            foreach (string temp in model.WrongGuessList)
            {
                sb.Append(temp).Append(" ");
            }
            model.WrongGuesses = sb.ToString();
        }
示例#3
0
 public bool CheckAlreadyGuessed(HangmanModel model, string newGuess)
 {
     foreach (string temp in model.GuessList)
     {
         if (temp.Equals(newGuess))
         {
             return(true);
         }
     }
     return(false);
 }