Beispiel #1
0
 /// <summary>
 /// Gets filed inside a specific rectangle inside the grid.
 /// </summary>
 /// <param name="window">The window rectangle</param>
 /// <returns>Set of field inside the window</returns>
 public IEnumerable <GridField> GetFields(Rectangle window)
 {
     GridField[] result = new GridField[window.Height * window.Width];
     for (int y = 0; y < window.Height; y++)
     {
         for (int x = 0; x < window.Width; x++)
         {
             result[y * window.Width + x] = fields[(window.Y + y) * width + (window.X + x)];
         }
     }
     return(result);
 }
Beispiel #2
0
 /// <summary>
 /// Creates a new grid of specifies size.
 /// </summary>
 /// <param name="width">Width of the whole grid</param>
 /// <param name="height">Height of the whole grid</param>
 /// <param name="fieldWidth">Width of one field</param>
 /// <param name="fieldHeight">Height of one field</param>
 public Grid(int width, int height, float fieldWidth, float fieldHeight)
 {
     fields = new GridField[width * height];
     for (int i = 0; i < fields.Length; i++)
     {
         fields[i] = new GridField();
     }
     this.width       = width;
     this.height      = height;
     this.fieldWidth  = fieldWidth;
     this.fieldHeight = fieldHeight;
     objects          = new HashSet <Quadrangle>();
     outside          = new GridField();
 }