コード例 #1
0
        public IActionResult Moves(Guid gameId, [FromBody] UserInputForMovesPost userInput)
        {
            if (!GamesRepo.Instance.ContainsGame(gameId))
            {
                return(new BadRequestObjectResult("game id is bad"));
            }
            var game = GamesRepo.Instance.GetGame(gameId);
            var dir  = InputParser.GetDirection(userInput, game);

            if (dir is Game.Direction direction)
            {
                game.Move(direction);
            }
            var gameDto = new GameDto(GameDtoBuilder.BuildCells(game).ToArray(),
                                      true, true,
                                      game.Width, game.Height,
                                      gameId,
                                      game.IsGameFinished,
                                      game.Moves);

            return(new ObjectResult(gameDto));
        }