예제 #1
0
        private void InitializeEmptyGrid(IEnumerable <LabeledGridElement> locations)
        {
            foreach (var loc in locations)
            {
                Width  = loc.X > Width ? loc.X : Width;
                Height = loc.Y > Height ? loc.Y : Height;
            }

            ++Width; ++Height;
            Array = new GridElement[Width, Height];

            for (int i = 0; i < Width; i++)
            {
                for (int j = 0; j < Height; j++)
                {
                    Array[i, j] = new GridElement(i, j);
                }
            }

            foreach (var loc in locations)
            {
                Array[loc.X, loc.Y] = new LabeledGridElement(loc.X, loc.Y, loc.Label);
            }
        }
예제 #2
0
 public int DistanceTo(GridElement other)
 {
     return(Math.Abs(X - other.X) + Math.Abs(Y - other.Y));
 }