public void CheckRandomGenerator()
        {
            BullsAndCowsNumber secretNumberOne = new BullsAndCowsNumber();
            Thread.Sleep(100);
            BullsAndCowsNumber secretNumberTwo = new BullsAndCowsNumber();

            Assert.AreEqual(false, secretNumberOne.SecretDigits == secretNumberTwo.SecretDigits);
        }
        public void CheckGuessWithGreaterLenght()
        {
            BullsAndCowsNumber secretNumber = new BullsAndCowsNumber();

            string guess = "12345";
            int bulls = 0, cows = 0;

            Assert.IsFalse(secretNumber.IsGuessCorrect(guess, ref bulls, ref cows));
        }
        public void CheckIncorectGuessAtempt()
        {
            BullsAndCowsNumber secretNumber = new BullsAndCowsNumber();

            string guess = "pesh";
            int bulls = 0, cows = 0;

            Assert.IsFalse(secretNumber.IsGuessCorrect(guess, ref bulls, ref cows));
        }
        public void FourCowsTest()
        {
            List<int> secretNumber = new List<int>() { 1, 2, 3, 4 };
            BullsAndCowsNumber game = new BullsAndCowsNumber();

            Type type = typeof(BullsAndCowsNumber);
            var fieldValue = type.GetField("secretDigits", BindingFlags.Instance | BindingFlags.NonPublic);
            fieldValue.SetValue(game, secretNumber);

            int bulls = 0;
            int cows = 0;
            game.IsGuessCorrect("4321", ref bulls, ref cows);
            Assert.IsTrue(bulls == 0 && cows == 4);
        }
        /// <summary>
        /// Stats the game, gets user input and using a switch statement selects the
        /// apropriate menu
        /// </summary>
        public void StartGame()
        {
            Console.WriteLine(StartText);

            BullsAndCowsNumber secretNumber = new BullsAndCowsNumber();
            this.helpUsedCount = 0;
            this.atemptsCount = 0;

            do
            {
                Console.WriteLine("Enter your guess or command: ");
                string inputLine = Console.ReadLine().Trim().ToLower();

                switch (inputLine)
                {
                    case "help":
                        string digitsRevealed = secretNumber.RevealRandomDigit(ref this.helpUsedCount);
                        Console.WriteLine(digitsRevealed);
                        break;
                    case "top":
                        Console.WriteLine(this.scoreBoard);
                        break;
                    case "restart":
                        Console.Clear();
                        this.StartGame();
                        break;
                    case "exit":
                        this.isGameRunning = false;
                        Console.WriteLine("Good bye!");
                        break;
                    default:
                        this.ManageUserGuess(inputLine, secretNumber);
                        break;
                }
            }
            while (this.isGameRunning);
        }
        public void TestMaxHelpsUsed()
        {
            BullsAndCowsNumber secretNumber = new BullsAndCowsNumber();
            int usedHelps = secretNumber.DigitsNumber;

            string expected = secretNumber.RevealRandomDigit(ref usedHelps);

            Assert.AreEqual(expected, "You cannot use more help.\r\nGame Over.");
        }
        public void TestHelpDigitsOutputOnlyDigits()
        {
            BullsAndCowsNumber secretNumber = new BullsAndCowsNumber();
            int usedHelps = 0;
            int secretDigits = secretNumber.SecretDigits;

            for (int index = 0; index < secretNumber.DigitsNumber - 1; index++)
            {
                secretNumber.RevealRandomDigit(ref usedHelps);
            }
            string expected = secretNumber.RevealRandomDigit(ref usedHelps);

            Assert.AreEqual(expected, string.Format("The numbers look like {0}", secretDigits));
        }
        public void TestHelpDigitsOutput()
        {
            BullsAndCowsNumber secretNumber = new BullsAndCowsNumber();
            int usedHelps = 0;
            int firstSectetDigit = secretNumber.SecretDigits / 1000;

            string expected = secretNumber.RevealRandomDigit(ref usedHelps);

            Assert.AreEqual(expected, string.Format("The numbers look like {0}XXX", firstSectetDigit));
        }
        public void OneBullOneCowTest()
        {
            List<int> secretNumber = new List<int>() { 5, 5, 8, 9 };
            BullsAndCowsNumber game = new BullsAndCowsNumber();

            Type type = typeof(BullsAndCowsNumber);
            var fieldValue = type.GetField("secretDigits", BindingFlags.Instance | BindingFlags.NonPublic);
            fieldValue.SetValue(game, secretNumber);

            int bulls = 0;
            int cows = 0;
            game.IsGuessCorrect("4553", ref bulls, ref cows);
            Assert.IsTrue(bulls == 1 && cows == 1);
        }
        public void OneBullAndZeroCowsTestWithTwoEqualDigitsInTheGuess()
        {
            List<int> secretNumber = new List<int>() { 1, 2, 3, 4 };
            BullsAndCowsNumber game = new BullsAndCowsNumber();

            Type type = typeof(BullsAndCowsNumber);
            var fieldValue = type.GetField("secretDigits", BindingFlags.Instance | BindingFlags.NonPublic);
            fieldValue.SetValue(game, secretNumber);

            int bulls = 0;
            int cows = 0;
            game.IsGuessCorrect("2259", ref bulls, ref cows);
            Assert.IsTrue(bulls == 1 && cows == 0);
        }
        /// <summary>
        /// A private method which manages the user guess if the input is a string 
        /// different than a command. If the guess is a string of numbers, the 
        /// method is executed completely. If not prints an apropriate message.
        /// </summary>
        private void ManageUserGuess(string inputLine, BullsAndCowsNumber secretNumber)
        {
            int bullsCount = 0;
            int cowsCount = 0;

            if (secretNumber.IsGuessCorrect(inputLine, ref bullsCount, ref cowsCount))
            {
                this.atemptsCount++;

                if (bullsCount == secretNumber.DigitsNumber)
                {
                    Console.WriteLine("Congratulations! You guessed the secret number in {0} attempts and {1} cheats.", this.atemptsCount, this.helpUsedCount);
                    Console.WriteLine(new string('-', 80));

                    if (this.helpUsedCount == 0 && this.scoreBoard.IsHighScore(this.atemptsCount))
                    {
                        Console.WriteLine("Please enter your name for the top scoreboard: ");

                        string name = Console.ReadLine();
                        this.scoreBoard.Add(name, this.atemptsCount);
                    }
                    else
                    {
                        Console.WriteLine("You are not allowed to enter the top scoreboard.");
                    }

                    Console.WriteLine(this.scoreBoard);
                    this.StartGame();
                }
                else
                {
                    Console.WriteLine("Wrong number! Bulls: {0}, Cows: {1}\n", bullsCount, cowsCount);
                }
            }
            else
            {
                Console.WriteLine("Wrong input format!\n");
            }
        }