コード例 #1
0
 public Gridspace(SizeXY size, GridspaceItemType acceptedType)
 {
     Size             = size;
     grid             = new bool[size.X, size.Y];
     itemsInGrid      = new Dictionary <GridspaceItem, GridPosition>();
     AcceptedItemType = acceptedType;
 }
コード例 #2
0
 /// <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;
     }
 }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
 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));
         }
     }
 }