コード例 #1
0
ファイル: Test.cs プロジェクト: hardydrachmann/WordGuesser
        public void TestEvaluateWord()
        {
            string word = "word";

            // Returns false when invalid value.
            Assert.IsFalse(logic.EvaluateWord(word, ""));
            Assert.IsFalse(logic.EvaluateWord(word, " "));
            Assert.IsFalse(logic.EvaluateWord(word, "w"));
            Assert.IsFalse(logic.EvaluateWord(word, "ord"));

            // Returns true if matches.
            Assert.IsTrue(logic.EvaluateWord(word, "word"));
        }
コード例 #2
0
        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();
        }