示例#1
0
        /// <summary>
        /// Initial new Bulls and cows game
        /// </summary>
        public void StartGame()
        {
            Console.WriteLine(Messages.START_EXPRESSION);

            BullsAndCowsGame bullsAndCows = new BullsAndCowsGame();
            bullsAndCows.Initialize();

            this.helpUsedCount = 0;
            this.attemptsCount = 0;

            while (this.isGameRunning)
            {
                Console.WriteLine(Messages.ENTER_GUESS);
                string command = Console.ReadLine().Trim().ToLower();

                if (command == HelpCommand)
                {
                    string digitsRevealed = bullsAndCows.RevealRandomDigit(ref this.helpUsedCount);
                    Console.WriteLine(digitsRevealed);
                }
                else if (command == TopCommand)
                {
                    Console.WriteLine(this.scoreBoard);
                }
                else if (command == RestartCommand)
                {
                    Console.Clear();
                    this.StartGame();
                }
                else if (command == ExitCommand)
                {
                    this.isGameRunning = false;
                    Console.WriteLine("Good bye!");
                }
                else if (bullsAndCows.IsValidGuess(command))
                {
                    this.ProcessUserInputedDigits(command, bullsAndCows);
                }
                else
                {
                    Console.WriteLine(Messages.WRONG_INPUT);
                }
            }
        }
        public void IsValidGuess_TwoSymbols_OnlyNumbers_IsFalse()
        {
            BullsAndCowsGame demo = new BullsAndCowsGame();
            var guess = demo.IsValidGuess("10");

            Assert.IsFalse(guess);
        }
 public void TestWithNullGuess()
 {
     BullsAndCowsGame game = new BullsAndCowsGame();
     bool result = game.IsValidGuess(null);
 }
 public void TestValidGuessWithWhiteThreeDigits()
 {
     BullsAndCowsGame game = new BullsAndCowsGame();
     bool result = game.IsValidGuess("123");
     Assert.IsFalse(result);
 }
 public void TestValidGuessWithWhiteSpace()
 {
     BullsAndCowsGame game = new BullsAndCowsGame();
     bool result = game.IsValidGuess("\n\n\t\t");
     Assert.IsFalse(result);
 }
 public void TestValidGuessWithFourZeros()
 {
     BullsAndCowsGame game = new BullsAndCowsGame();
     bool result = game.IsValidGuess("0000");
     Assert.IsTrue(result);
 }
 public void TestValidGuessWithEmptyString()
 {
     BullsAndCowsGame game = new BullsAndCowsGame();
     bool result = game.IsValidGuess("");
     Assert.IsFalse(result);
 }
 public void TestValidGuessWithDuplicatedDigits()
 {
     BullsAndCowsGame game = new BullsAndCowsGame();
     bool result = game.IsValidGuess("8383");
     Assert.IsTrue(result);
 }
 public void TestValidGuess()
 {
     BullsAndCowsGame game = new BullsAndCowsGame();
     bool result = game.IsValidGuess("1234");
     Assert.IsTrue(result);
 }
 public void TestIsValidGuessWithLetters()
 {
     BullsAndCowsGame game = new BullsAndCowsGame();
     bool result = game.IsValidGuess("abced");
     Assert.IsFalse(result);
 }
        public void IsValidGuess_WrongInputExactlyFourSymbolsLength_WithNumbers_IsFalse()
        {
            BullsAndCowsGame demo = new BullsAndCowsGame();
            var guess = demo.IsValidGuess("12ab");

            Assert.IsFalse(guess);
        }