예제 #1
0
        public async Task <IActionResult> Simulate([FromBody] SimulateApiRequestModel request)
        {
            var tank1 = await _dataApiClient.GetTank(request.Tanks[0]);

            var tank2 = await _dataApiClient.GetTank(request.Tanks[1]);

            var map = await _dataApiClient.GetMap(request.MapId);

            if (tank1 == null || tank2 == null || map == null)
            {
                return(NotFound(new { error = "Wrong tank or map id provided." }));
            }

            var gameData = await _resultsApiClient.CreateAsync(new GameDataModel
            {
                Tank1Id = request.Tanks[0],
                Tank2Id = request.Tanks[1],
                MapId   = request.MapId,
                Status  = GameStatus.InQueue
            });

            var result = await _gameSimulator.SimulateAsync(gameData.Id, tank1, tank2, map);

            return(Ok(new GameDataApiResponseModel(result)));
        }
예제 #2
0
        public async Task <IActionResult> GetById(string id)
        {
            var result = await _dataApiClient.GetTank(id);

            if (result == null)
            {
                return(NotFound(new { error = "Could not find tank." }));
            }

            return(Ok(result));
        }