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); } }
public int DistanceTo(GridElement other) { return(Math.Abs(X - other.X) + Math.Abs(Y - other.Y)); }