Exemple #1
0
 public Game(Player player, Mastermind mastermind, IInput input, IOutput output, IRule rule)
 {
     Player          = player;
     Mastermind      = mastermind;
     Input           = input;
     Output          = output;
     Rule            = rule;
     _inputValidator = new InputValidator();
 }
Exemple #2
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());
        }
Exemple #3
0
        static void Main(string[] args)
        {
            var consoleInput            = new ConsoleInput();
            var consoleOutput           = new ConsoleOutput();
            var solutionGenerator       = new NormalSolutionGenerator();
            var player                  = new Player("Lan", solutionGenerator);
            var secretSolutionGenerator = new SecretSolutionGenerator();
            var mastermind              = new Mastermind(secretSolutionGenerator);
            var rule = new Rule();
            var game = new Game(player, mastermind, consoleInput, consoleOutput, rule);

            try
            {
                game.Start();
                game.Play();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Exemple #4
0
 public void Start()
 {
     WelcomeUser();
     DisplayInputRule();
     Mastermind.SetSecretSolution(Colours);
 }