public void GuessHandlerTest_OrderedLettersMaskMustBeCorrectTest()
 {
     string word = "SomeWord";
     GuessCharacterHandler randerer = new GuessCharacterHandler();
     randerer.PlayRound(word);
     Assert.IsTrue(randerer.RevealedChars.Length == word.Length);
 }
        // used to be GuessLetter
        /// <summary>
        /// Handles player input.
        /// </summary>
        /// <param name="guessHandler">Data input by player.</param>
        public void HandleUserInput(GuessCharacterHandler guessHandler)
        {
            string supposedCharOrCommand = this.ReadPlayerInput();

            if (supposedCharOrCommand.Length == 1)
            {
                char supposedChar = supposedCharOrCommand[0];
                guessHandler.HandleUserGuess(Word, supposedChar);
            }
            else if (supposedCharOrCommand.Equals("help"))
            {
                CommandExecuter.Help(guessHandler, Word);
            }
            else if (supposedCharOrCommand.Equals("restart"))
            {
                CommandExecuter.Start();
            }
            else if (supposedCharOrCommand.Equals("exit"))
            {
                CommandExecuter.Exit(this);
            }
            else if (supposedCharOrCommand.Equals("top"))
            {
                CommandExecuter.Top();
            }
        }
 public void InitializationAfterTheGuessTest_TwoGestLettersAtTheSameTimeTest()
 {
     string word = "SomeWord";
     GuessCharacterHandler randerer = new GuessCharacterHandler();
     randerer.PlayRound(word);
     randerer.HandleUserGuess(word, 'o');
     Assert.IsTrue(randerer.GuessedCharsCounter == 2);
 }
 public void InitializationAfterTheGuessTest()
 {
     string word = "SomeWord";
     GuessCharacterHandler randerer = new GuessCharacterHandler();
     randerer.PlayRound(word);
     randerer.HandleUserGuess(word, 'a');
     Assert.IsTrue(randerer.MistakesCounter == 1);
 }
 public void RevealTheNextLetterByHelpTestUseHelpTwiceTest()
 {
     string word = "test";
     GuessCharacterHandler randerer = new GuessCharacterHandler();
     randerer.PlayRound(word);
     randerer.RevealTheNextLetterByHelp(word);
     randerer.RevealTheNextLetterByHelp(word);
     Assert.AreEqual(2, randerer.MistakesCounter);
 }
 public void InitializationAfterTheGuessTest_AlreadyRevelaedLetterTest()
 {
     string word = "test";
     GuessCharacterHandler randerer = new GuessCharacterHandler();
     randerer.PlayRound(word);
     randerer.HandleUserGuess(word, 't');
     int openLetters = randerer.GuessedCharsCounter;
     randerer.HandleUserGuess(word, 't');
     Assert.IsTrue(openLetters == randerer.GuessedCharsCounter);
 }
        /// <summary>
        /// Starts the game.
        /// </summary>
        public static void Start()
        {
            Console.WriteLine();
            WordSelector wordSelector = new WordSelector();
            string word = wordSelector.SelectRandomWord();
            GuessCharacterHandler guessHandler = new GuessCharacterHandler();
            guessHandler.PlayRound(word);
            UserInputHandler wordGuesser = new UserInputHandler();
            wordGuesser.Word = word;

            while (guessHandler.GuessedCharsCounter < word.Length && wordGuesser.HasExited == false)
            {
                wordGuesser.HandleUserInput(guessHandler);
            }
        }
        public void RevealedCharsTest()
        {
            string word = "word";
            GuessCharacterHandler randerer = new GuessCharacterHandler();
            randerer.PlayRound(word);
            UserInputHandler wordGuesser = new UserInputHandler(); // used to be wg
            wordGuesser.Word = word;

            using (StringReader sr = new StringReader(string.Format("help{0}", Environment.NewLine)))
            {
                Console.SetIn(sr);
                wordGuesser.HandleUserInput(randerer);
                Assert.IsNotNull(randerer.RevealedChars);
            }
        }
        public void HandleUserInput_HelpTest()
        {
            string word = "word";
            GuessCharacterHandler randerer = new GuessCharacterHandler();
            randerer.PlayRound(word);
            UserInputHandler wordGuesser = new UserInputHandler(); // used to be wg
            wordGuesser.Word = word;

            using (StringReader sr = new StringReader(string.Format("help{0}", Environment.NewLine)))
            {
                Console.SetIn(sr);
                wordGuesser.HandleUserInput(randerer);
                int guestCharsCounter = randerer.GuessedCharsCounter;
                Assert.IsTrue(guestCharsCounter == 1);
            }
        }
        public void HandleUserInput_TopTest()
        {
            string word = "word";
            GuessCharacterHandler randerer = new GuessCharacterHandler();
            randerer.PlayRound(word);
            UserInputHandler wordGuesser = new UserInputHandler(); // used to be wg
            wordGuesser.Word = word;

            using (StringWriter sw = new StringWriter())
            {
                using (StringReader sr = new StringReader(string.Format("top{0}", Environment.NewLine)))
                {
                    Console.SetIn(sr);
                    Console.SetOut(sw);
                    wordGuesser.HandleUserInput(randerer);
                    Assert.AreEqual<string>("Enter your guess: \r\n\r\n\r\n", sw.ToString());
                }
            }
        }
        public void HandleUserInput_CharTest()
        {
            string word = "word";
            GuessCharacterHandler randerer = new GuessCharacterHandler();
            randerer.PlayRound(word);
            UserInputHandler wordGuesser = new UserInputHandler(); // used to be wg
            wordGuesser.Word = word;

            using (StringWriter sw = new StringWriter())
            {
                using (StringReader sr = new StringReader(string.Format("z{0}exit", Environment.NewLine)))
                {
                    Console.SetIn(sr);
                    Console.SetOut(sw);
                    wordGuesser.HandleUserInput(randerer);
                    string testText = "Enter your guess: \r\nSorry! There are no unrevealed letters z\r\nThe secret word is:\r\n_ _ _ _ \r\n";
                    Assert.AreEqual<string>(testText, sw.ToString());
                }
            }
        }
 public static void Help(GuessCharacterHandler guessHandler, string word)
 {
     guessHandler.RevealTheNextLetterByHelp(word);
 }