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