Beispiel #1
0
        private bool TryAttachComponentInternal(Attachable comp, GridPoint pos, bool attach)
        {
            var end = pos + new GridPoint(comp.GridWidth, comp.GridHeight);

            if (pos.X < 0 || pos.Y < 0 ||
                end.X >= size.X || end.Y >= size.Y ||
                AreaHasComponent(pos, end))
            {
                return(false);
            }

            if (attach)
            {
                for (var x = pos.X; x < end.X; x++)
                {
                    for (var y = pos.Y; y < end.Y; y++)
                    {
                        grid[x, y] = comp;
                    }
                }
            }

            return(true);
        }
Beispiel #2
0
 public bool TryAttachComponent(Attachable comp, GridPoint pos)
 {
     return(TryAttachComponentInternal(comp, pos, true));
 }
Beispiel #3
0
 public bool CanAttachComponent(Attachable comp, GridPoint pos)
 {
     return(!TryAttachComponentInternal(comp, pos, false));
 }