private SimulationEntry Tick() { var simulationEntry = new SimulationEntry(); var tasks = new List <Task>(); foreach (var car in _cars.Where(c => c.InUse)) { var carEntry = new CarEntry(); tasks.Add(Task.Factory.StartNew(() => { carEntry.Id = car.Id; carEntry.Position = _moveService.Move(car); carEntry.VisibleElements = car.GetVisibleElements(_map); if (carEntry.VisibleElements.Count > 0) { Console.WriteLine("found"); } carEntry.Collisions = car.CheckCollision(_cars.Where(c => c.Id != car.Id).ToList()); carEntry.Direction = car.UpdateDirection(); })); simulationEntry.Cars.Add(carEntry); } Task.WaitAll(tasks.ToArray()); if (_cars.All(c => !c.InUse)) { _simulationEnabled = false; } return(simulationEntry); }
public IActionResult Post([FromBody] MoveInput input, string id) { if (input.isValid() == false) { return(StatusCode(400)); } var bot = _storage.GetBot(input.botToken); if (bot == null) { return(StatusCode(403)); } var board = _storage.GetBoard(id); if (board == null) { return(StatusCode(404)); } if (board.HasBot(bot) == false) { return(StatusCode(403)); } if (board.CanMove(bot) == false) { return(StatusCode(403)); } var moveResult = _moveService.Move(id, bot.Name, input.direction); if (moveResult != MoveResultCode.Ok) { return(StatusCode(409)); } return(GetBoard(id)); }
public void Move(Vector2 direction) { _moveService.Move(this, direction); }