Example #1
0
 public void ThrowExceptionWhenInputLengthIsNotFour(string selection)
 {
     if (selection.Length != 4)
     {
         throw new Exception(GameInstruction.InvalidInputLengthMessage());
     }
 }
Example #2
0
 public void ThrowExceptionWhenTriedTooManyTimes(int guessCount)
 {
     if (guessCount > 60)
     {
         throw new Exception(GameInstruction.TooMoreTriesMessage());
     }
 }
Example #3
0
 public void ThrowExceptionWhenSelectedColourIsInvalid(int number, int coloursLength)
 {
     if (number < 0 || number > coloursLength)
     {
         throw new Exception(GameInstruction.InvalidColourMessage());
     }
 }
Example #4
0
        public void Play()
        {
            var isWinning = false;

            while (!isWinning)
            {
                GuessCount += 1;
                _inputValidator.ThrowExceptionWhenTriedTooManyTimes(GuessCount);

                DisplayAllowedColours();
                var selectedColours = UserSelectColours();
                _currentSolution = Player.GenerateSolution(selectedColours);
                Output.Write(_currentSolution);
                var shuffledHint = Mastermind.CreateShuffledHintBasedOnPlayerSolution(_currentSolution);
                Output.Write(shuffledHint);
                isWinning = Rule.IsWinningCondition(shuffledHint);
            }
            Player.IsWinner = true;
            Output.Write(GameInstruction.YouWonMessage());
        }
Example #5
0
 private void WelcomeUser()
 {
     Output.Write(GameInstruction.WelcomePlayerMessage(Player.Name));
 }
Example #6
0
 private void DisplayInputRule()
 {
     Output.Write(GameInstruction.DisplayInputRuleMessage());
 }
Example #7
0
 private string CollectUserInput()
 {
     return(Input.Ask(GameInstruction.YourSelectionMessage()));
 }