private bool MoveEntity(Entity entity, Direction direction, GameTime gameTime, List <Entity> controlledEntities) { if (entity.Coordinates == null) { return(false); } if (!entity.Coordinates.TryAdd(direction, out var nextCellCoordinates)) { return(false); } if (!_grid.IsMoveAllowed(entity, nextCellCoordinates)) { return(false); } var controlledEntitesCell = _grid.GetEntities(nextCellCoordinates, e => e.IsControlled); foreach (var controlledEntity in controlledEntitesCell) { MoveControlledEntity(controlledEntity, direction, gameTime, controlledEntities); } var pushableEntitiesCell = _grid.GetEntities(nextCellCoordinates, e => e.IsPushable); foreach (var pushableEntity in pushableEntitiesCell) { MoveEntity(pushableEntity, direction, gameTime, controlledEntities); } if (_grid.GetEntities(nextCellCoordinates, e => e.IsStoping).Any()) { return(false); } var command = new MoveInGridCommand(entity, nextCellCoordinates); _currentTurn.Push(command); _doCommandsHandler.Apply(command, gameTime); return(true); }
private void Apply(MoveInGridCommand command, GameTime gameTime) { _grid.Move(command.Entity, command.FromCoordinates); command.Entity.SetCoordinates(command.FromCoordinates, gameTime); }