private void playRound(string word)
        {
            string blanks = getBlanks(word);

            Console.WriteLine("Enter word or character from word to guess: " + blanks + " " + word + "\n");
            while (guessLogic.GetGuessCount() > 0)
            {
                Console.Write("> ");
                string guess = Console.ReadLine()?.ToLower();
                bool   correct;
                if (guess.Length > 1)
                {
                    correct = wordLogic.EvaluateWord(word, guess);
                }
                else
                {
                    correct = wordLogic.EvaluateLetter(word, blanks, guess);
                }
                if (correct)
                {
                    blanks = substituteLetters(word, blanks, guess);
                    guessLogic.IncrementGuessCount();
                    string guessProgress = blanks.Replace(" ", "");
                    bool   hasWon        = wordLogic.EvaluateWord(word, guessProgress);
                    if (hasWon)
                    {
                        Console.Clear();
                        Console.WriteLine("You Won! " + blanks.Replace(" ", ""));
                        break;
                    }
                    else
                    {
                        Console.Clear();
                        Console.Write("Correct!");
                    }
                }
                else
                {
                    Console.Clear();
                    Console.Write("Wrong!");
                    guessLogic.DecrementGuessCount();
                }
                Console.WriteLine(" Guesses left: " + guessLogic.GetGuessCount());
                Console.WriteLine(blanks + "\n");
            }
            guessLogic.ResetGuessCount();
        }
Example #2
0
        public void TestEvaluateLetter()
        {
            string word   = "word";
            string blanks = "_ o _ _";

            // Returns false when invalid value.
            Assert.IsFalse(logic.EvaluateLetter(word, blanks, ""));
            Assert.IsFalse(logic.EvaluateLetter(word, blanks, " "));
            Assert.IsFalse(logic.EvaluateLetter(word, blanks, "rd"));
            Assert.IsFalse(logic.EvaluateLetter(word, blanks, "k"));

            // Returns true if matches.
            Assert.IsTrue(logic.EvaluateLetter(word, blanks, "w"));
            Assert.IsTrue(logic.EvaluateLetter(word, blanks, "r"));
            Assert.IsTrue(logic.EvaluateLetter(word, blanks, "d"));
        }