/// <summary> /// Constructor /// </summary> /// <param name="coordinates"></param> public SurroundingView(Coordinates coordinates, MapTile[,] view) { // Set the center coordinate _centerOfView = coordinates; _view = new Map(Convert.ToInt16(view.GetUpperBound(0)), Convert.ToInt16(view.GetUpperBound(1))); _view.InitializeGrid(view); }
/// <summary> /// Populates the grid with MapTiles /// </summary> public void InitializeGrid() { // Create a square map of MapWidth / MapHeight size for (short col = 0; col < Width; col++) { for (short row = 0; row < Height; row++) { var tile = new MapTile(); tile.SetPositions(col, row); Grid[col, row] = tile; } } }
/// <summary> /// Extracts a sub array from the array passed as a parameter /// </summary> /// <param name="xMin">The "top left" x bound of the array to extract</param> /// <param name="xMax">The "top left" y bound of the array to extract</param> /// <param name="yMin">The "bottom right" x bound of the array to extract</param> /// <param name="yMax">The "bottom right" y bound of the array to extract</param> /// <returns>The sub 2D array</returns> private MapTile[,] GetSubArray(Int16 xMin, Int16 xMax, Int16 yMin, Int16 yMax) { Coordinates cMin = new Coordinates(xMin, yMin); Coordinates cMax = new Coordinates(xMax, yMax); if (CoordinatesAreValid(cMin) && CoordinatesAreValid(cMax)) { // Create a new map (add +1 to the dimention since it is a 0 based array) var newMap = new MapTile[(Int16)(xMax - xMin +1), (Int16)(yMax - yMin + 1)]; for (int i = xMin; i <= xMax; i++) for (int j = yMin; j <= yMax; j++) newMap[i - xMin, j - yMin] = Grid[i, j]; return newMap; } else throw new Exception(); }
/// <summary> /// Initializes the grid of the map with the grid passed as a reference /// </summary> /// <param name="view">The grid that is to become this map's grid</param> public void InitializeGrid(MapTile[,] view) { Grid = view; }