public string ValidateGame(ValidateGameRequest request)
        {
            GameModel game = _gameRepository.GetGame(request.Id).Result;

            if (game == null)
            {
                _logger.LogInformation("Game not found {@Id}", request.Id);
                throw new NotFoundException("Partida não encontrada");
            }
            if (game.StateGame != CrossCutting.Enum.StateGame.InProgress)
            {
                _logger.LogInformation("This match is already over {@Id}", request.Id);
                throw new BusinessException("Esta partida já acabou");
            }
            if (game.NextPlayer != request.Player)
            {
                _logger.LogInformation("It's not player turn {@Player}", request.Player);
                throw new BusinessException("Não é turno do jogador");
            }

            bool validatePositionFilled     = ValidatePositionFilled(game.Board, request.Position);
            bool validateAllPositionsFilled = ValidateAllPositionsFilled(game.Board);
            bool validateMaxPosition        = ValidateMaxPosition(request.Position);

            if (validatePositionFilled || validateAllPositionsFilled || validateMaxPosition)
            {
                _logger.LogInformation("Invalid movement {@Id}", request.Id);
                throw new BusinessException("Movimento inválido");
            }

            return(string.Empty);
        }
示例#2
0
        public ExecuteMovementResponse ExecuteMovement(ExecuteMovementRequest request)
        {
            ValidateGameRequest validateRequest = _objectConverter.Map <ValidateGameRequest>(request);
            string validate = _validateGameService.ValidateGame(validateRequest);

            if (!string.IsNullOrEmpty(validate))
            {
                return(new ExecuteMovementResponse
                {
                    Msg = validate
                });
            }
            CompileGameResponse compileResponse = _compileGameService.CompileGame(_objectConverter.Map <CompileGameRequest>(request));

            return(_objectConverter.Map <ExecuteMovementResponse>(compileResponse));
        }