コード例 #1
0
ファイル: GameEngine.cs プロジェクト: angela-yang1/Mastermind
        public void Run()
        {
            _display.Welcome();
            _display.AvailableColours();
            var hasAWinner = false;

            var masterColours = _randomColourGenerator.Generate();

            Console.WriteLine("\nMASTER COLOURS: " + string.Join(", ", masterColours));

            while (!hasAWinner && !HasMaxTriesReached())
            {
                var userAnswer = _inputHandler.TakeInput();

                if (userAnswer.GetSelectedAlternative() == 2)
                {
                    var userSelectedOption = userAnswer.Value2;

                    if (QuitApplication(userSelectedOption))
                    {
                        break;
                    }
                }

                var userSelectedColours = userAnswer.Value1;
                var matchResult         = _colourMatchResult.CreateResult(masterColours, userSelectedColours);

                if (matchResult.Count != 0)
                {
                    _display.TurnCounter(_turnCountTracker.Counter, matchResult);
                    hasAWinner = IsThereAWinner(matchResult);
                }
                else
                {
                    _display.NoColourMatch();
                }

                _turnCountTracker.NextTurn();
            }
        }