Exemplo n.º 1
0
Arquivo: Grid.cs Projeto: jussik/swarm
        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);
        }
Exemplo n.º 2
0
Arquivo: Grid.cs Projeto: jussik/swarm
 public bool TryAttachComponent(Attachable comp, GridPoint pos)
 {
     return(TryAttachComponentInternal(comp, pos, true));
 }
Exemplo n.º 3
0
Arquivo: Grid.cs Projeto: jussik/swarm
 public bool CanAttachComponent(Attachable comp, GridPoint pos)
 {
     return(!TryAttachComponentInternal(comp, pos, false));
 }