Esempio n. 1
0
 /// <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;
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="coordinates"></param>
        public SurroundingView(ICoordinates coordinates, MapTile[,] view)
        {
            // Set the center coordinate
            CellPositionInWorld = coordinates;
            
            viewSizeX = Convert.ToInt16(view.GetUpperBound(0));
            viewSizeY = Convert.ToInt16(view.GetUpperBound(1));

            CellPositionInView = new Coordinates((Int16)(viewSizeX / 2), (Int16)(viewSizeY / 2));

            View = new Map(viewSizeX, viewSizeY);
            View.InitializeGrid(view);
        }
Esempio n. 3
0
 /// <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;
 }
Esempio n. 4
0
        /// <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)
        {
            ICoordinates cMin = new Coordinates();
            cMin.SetCoordinates(xMin, yMin);
            ICoordinates cMax = new Coordinates();
            cMax.SetCoordinates(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();
        }