public Gridspace(SizeXY size, GridspaceItemType acceptedType) { Size = size; grid = new bool[size.X, size.Y]; itemsInGrid = new Dictionary <GridspaceItem, GridPosition>(); AcceptedItemType = acceptedType; }
/// <summary> /// Sets selected cells of grid to value. /// </summary> /// <param name="position"></param> /// <param name="size"></param> /// <param name="value"></param> private void SetGridValues(GridPosition position, SizeXY size, bool value) { foreach (var pair in EnumerateGridRectangle(position, size)) { grid[pair.Item1, pair.Item2] = value; } }
/// <summary> /// Checks that on this position item with given size present or abscent. /// </summary> /// <param name="position"></param> /// <param name="size"></param> /// <param name="valueToValidate"></param> /// <returns></returns> private bool ValidateGridValues(GridPosition position, SizeXY size, bool valueToValidate) { foreach (var pair in EnumerateGridRectangle(position, size)) { if (grid[pair.Item1, pair.Item2] != valueToValidate) { return(false); } } return(true); }
private IEnumerable <Tuple <int, int> > EnumerateGridRectangle(GridPosition position, SizeXY size) { for (int i = position.X; i < size.X; i++) { for (int j = position.Y; j < size.Y; j++) { yield return(Tuple.Create(i, j)); } } }