Beispiel #1
0
 public void ThrowExceptionWhenInputLengthIsNotFour(string selection)
 {
     if (selection.Length != 4)
     {
         throw new Exception(GameInstruction.InvalidInputLengthMessage());
     }
 }
Beispiel #2
0
 public void ThrowExceptionWhenTriedTooManyTimes(int guessCount)
 {
     if (guessCount > 60)
     {
         throw new Exception(GameInstruction.TooMoreTriesMessage());
     }
 }
Beispiel #3
0
 public void ThrowExceptionWhenSelectedColourIsInvalid(int number, int coloursLength)
 {
     if (number < 0 || number > coloursLength)
     {
         throw new Exception(GameInstruction.InvalidColourMessage());
     }
 }
Beispiel #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());
        }
Beispiel #5
0
 private void WelcomeUser()
 {
     Output.Write(GameInstruction.WelcomePlayerMessage(Player.Name));
 }
Beispiel #6
0
 private void DisplayInputRule()
 {
     Output.Write(GameInstruction.DisplayInputRuleMessage());
 }
Beispiel #7
0
 private string CollectUserInput()
 {
     return(Input.Ask(GameInstruction.YourSelectionMessage()));
 }