public static CMap Create(IMapLoader loader) { Int32 width = loader.GetWidth(); Int32 height = loader.GetHeight(); var map = new CMap(width, height); for (var x = 0; x < map.Width; x++) { for (var y = 0; y < map.Height; y++) { var position = new SPoint(x, y); ICell cell = loader.GetCell(position); map.SetCell(cell); IPositionable unit = loader.GetUnit(position); if (unit != null) { unit.SetMap(map); unit.SetPosition(new SPoint(x, y)); //map.Spawn(unit, position.X, position.Y); } } } return(map); }
public Boolean Spawn(IPositionable unit, Int32 x, Int32 y) { if (unit is null) { throw new ArgumentNullException(nameof(unit)); } unit.SetMap(_map); var position = new SPoint(x, y); Boolean cellLocked = _lockContainer.TryLock(position); if (cellLocked) { try { unit.SetPosition(position); } finally { _lockContainer.Unlock(position); } } return(cellLocked); }