Ejemplo n.º 1
0
        public IActionResult Index([FromBody] int levelNumber = 1)
        {
            var stringCells = gameDataLoader.Load(levelNumber);
            var cells       = parsingService.Parse(stringCells);

            Game game = new Game(cells, stringCells[0].Length, stringCells.Length, levelNumber);

            GamesRepo.AddGame(game);

            return(new ObjectResult(game.GameField));
        }
Ejemplo n.º 2
0
        public IActionResult Moves(Guid gameId, [FromBody] UserInputForMovesPost userInput)
        {
            var game = GamesRepo.GetGame(gameId);

            game.MovePlayer(moveProvider.GetMovement(userInput));

            if (game.GameField.IsFinished)
            {
                GameDto gameField = game.GameField;
                try
                {
                    var stringCells = gameDataLoader.Load(game.GameField.Level + 1);
                    var cells       = parsingService.Parse(stringCells);
                    game.GameField = new GameDto(cells, true, true, game.GameField.Width, game.GameField.Height, gameId,
                                                 false, 0, game.GameField.Level + 1);
                }
                catch
                {
                    game.GameField = gameField;
                }
            }
            return(new ObjectResult(game.GameField));
        }