public void Player1_Always_Selects_Rock_Tests(GameAction player1Action, GameAction player2Action, GameResultTypes expectedCondition)
        {
            PlayerFactory factory = new PlayerFactory();

            var player1 = factory.CreatePlayer(player1Action);
            var player2 = factory.CreatePlayer(player2Action);

            var gameModel = new GameModel(player1, player2);
            var result    = _gameProcessor.Play(gameModel);

            Assert.True(result.Data.ResultType == expectedCondition);
        }
Beispiel #2
0
        public IActionResult Play([FromBody] PlayRequest playRequestModel)
        {
            try
            {
                if (playRequestModel.Player1Type == null && playRequestModel.Player1ChosenAction == null)
                {
                    return(BadRequest("No player or action has been chosen!"));
                }

                var gameModel = _gameModeBuilder.CreateFrom(playRequestModel);
                var response  = _gameProcessor.Play(gameModel);
                switch (response.StatusCode)
                {
                case HttpStatusCode.OK:
                    return(Ok(response));

                case HttpStatusCode.NotFound:
                    return(NotFound());

                case HttpStatusCode.BadRequest:
                    return(BadRequest(response.Message));

                default:
                    return(Ok(response));
                }
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error playing game: {ex.ToString()}");
                return(StatusCode(500, "Internal server error"));
            }
        }