Ejemplo n.º 1
0
        public IActionResult Post([FromBody] Simulation server)
        {
            if (server == null)
            {
                return(BadRequest());
            }

            repo.Add(server);

            return(CreatedAtRoute("Get", new { id = server.Id }, server));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <GameSimulationDto> > GenerateSimulation(int gameId)
        {
            var gameDb = _gameRepository.GetFullGame(gameId);

            if (gameDb == null)
            {
                return(NotFound());
            }
            var blueTank = new Engine.TankModel
            {
                ModelName  = gameDb.BlueTankModel.TankModelName,
                GunPower   = gameDb.BlueTankModel.GunPower,
                ShieldLife = gameDb.BlueTankModel.ShieldLife,
                GunRange   = gameDb.BlueTankModel.GunRange,
                Speed      = gameDb.BlueTankModel.Speed
            };
            var redTank = new Engine.TankModel
            {
                ModelName  = gameDb.RedTankModel.TankModelName,
                GunPower   = gameDb.RedTankModel.GunPower,
                ShieldLife = gameDb.RedTankModel.ShieldLife,
                GunRange   = gameDb.RedTankModel.GunRange,
                Speed      = gameDb.RedTankModel.Speed
            };
            var map  = gameDb.GameMap.Map.ToMatrix();
            var game = new TankBattleGame(map,
                                          blueTank, new int[2] {
                gameDb.BlueTankX, gameDb.BlueTankY
            },
                                          redTank, new int[2] {
                gameDb.RedTankX, gameDb.RedTankY
            });

            var simulation = game.SimulateBattle();

            var gameSimulation = new GameSimulation
            {
                GameBattleId = gameId,
                Simulation   = JsonSerializer.Serialize(simulation),
                IsActive     = true,
                CreatedTime  = DateTime.Now
            };
            var newSimulation = await _simulationRepository.Add(gameSimulation);

            if (newSimulation == null)
            {
                return(BadRequest("Unable to generate simulation"));
            }
            var dbGame = _gameRepository.GetFullGame(gameId);

            newSimulation.GameBattle = dbGame;
            return(CreatedAtRoute("GetSimulationForGame", new { gameId = gameId, simulationId = newSimulation.GameSimulationId }
                                  , newSimulation));
        }
Ejemplo n.º 3
0
        public ActionResult <SimulationResource> Post([FromBody] JObject json)
        {
            var simulations = simulationRepo.GetAll();

            var simulation = new Model.Simulation
            {
                Name        = json["name"].Value <string>(),
                Description = json["description"].Value <string>(),
                AuthorId    = userManager.Users.First().Id,
            };

            foreach (var reference in json["references"].Select(t => simulations.Single(s => s.Name == t.Value <string>())))
            {
                simulation.AddReference(reference);
            }

            simulationRepo.Add(simulation);

            return(Get(simulation.Id));
        }
Ejemplo n.º 4
0
        public ActionResult <SimulationResource> Post([FromBody] JObject json)
        {
            var simulations = simulationRepo.GetAll();

            var simulation = new Simulation
            {
                Name        = json["name"].Value <string>(),
                Description = json["description"].Value <string>(),
                Author      = userManager.Users.First(),
                References  = json["references"].Select(token => simulations.Single(s => s.Name == token.Value <string>())).ToList()
            };

            simulationRepo.Add(simulation);

            foreach (var reference in simulation.References)
            {
                reference.AddConsumer(simulation);
            }

            return(Get(simulation.Id));
        }