Ejemplo n.º 1
0
        private void DisplayFinalResults()
        {
            _inputOutputWrapper.WriteLine($"Game over! You scored : {_normalPlayer.Wins} | Computer scored : {_computerPlayer.Wins}");
            var overallResult = _overallScoreCalculator.CalculateOverallWinner(_normalPlayer, _computerPlayer);

            if (overallResult == Result.Draw)
            {
                _inputOutputWrapper.WriteLine("It's a draw!");
            }
            else if (overallResult == Result.Player1Wins)
            {
                _inputOutputWrapper.WriteLine("You won!");
            }
            else
            {
                _inputOutputWrapper.WriteLine("Computer won!");
            }

            _inputOutputWrapper.ReadLine();
        }
Ejemplo n.º 2
0
        public void PlayRound(IPlayer normalPlayer, IComputerPlayer computerPlayer)
        {
            GameMoveViewModel chosenMove = null;

            while (chosenMove == null)
            {
                _inputOutputWrapper.WriteLine("Please enter your choice:");
                var choice = _inputOutputWrapper.ReadLine();
                chosenMove = _gameMoveViewModelHelper.GameMoveViewModels.FirstOrDefault(x => x.InputValue == choice);
                if (chosenMove == null)
                {
                    _inputOutputWrapper.WriteLine("That was an invalid choice, please try again");
                }
            }

            var computerGameMove          = computerPlayer.GetComputerMove();
            var computerGameMoveViewModel = _gameMoveViewModelHelper.GameMoveViewModels.FirstOrDefault(x => x.GameMove == computerGameMove);

            if (computerGameMoveViewModel == null)
            {
                throw new ApplicationException("Error Generating computer choice");
            }

            var result = _roundCalculator.CalculateRoundResult(chosenMove.GameMove, computerGameMove);

            _inputOutputWrapper.WriteLine($"Computer chose: {computerGameMoveViewModel.FriendlyName}");

            string resultString = null;

            switch (result)
            {
            case Result.Draw:
                resultString = "Draw!";
                break;

            case Result.Player1Wins:
                resultString = "You win!";
                IncrementWins(normalPlayer);
                break;

            case Result.Player2Wins:
                resultString = "Computer wins!";
                IncrementWins(computerPlayer);
                break;
            }

            _inputOutputWrapper.WriteLine(resultString);
        }