/// <summary> /// Constructs a new Map model from a matrix of tiles. /// </summary> /// <param name="map">The matrix of tiles that will form the map</param> public Map(Tile[,] map) { this.map = map; this.width = map.GetLength(0); this.height = map.GetLength(1); }
/// <summary> /// This is a recurisve method that each call creates a new tile for the /// specific terrain type to spread. It will call itself until the number of /// tiles to spread is zero or less. The spread works by randomly choose /// a direction as seen futher down. /// </summary> /// <param name="tileMatrix"></param> /// <param name="xCoord"></param> /// <param name="yCoord"></param> /// <param name="numberOfTiles"></param> /// <param name="type"></param> /// <param name="randomer"></param> private static void SpreadTiles(Tile[,] tileMatrix, int xCoord, int yCoord, int numberOfTiles, Globals.TerrainTypes type, Random randomer) { tileMatrix[xCoord, yCoord] = new Tile(xCoord, yCoord, type); //X represents the adjecent tiles, O is the current tile // X = 1 //2 = X O X = 3 // 4 = X // if (numberOfTiles<=0 || !(xCoord > 1 && xCoord < tileMatrix.GetLength(0)-1 && yCoord > 1 && yCoord < tileMatrix.GetLength(1)-1)) { return; } switch (randomer.Next(4)) { case 0: SpreadTiles(tileMatrix, xCoord, yCoord - 1, numberOfTiles - 1, type, randomer); break; case 1: SpreadTiles(tileMatrix, xCoord - 1, yCoord, numberOfTiles - 1, type, randomer); break; case 2: SpreadTiles(tileMatrix, xCoord + 1, yCoord, numberOfTiles - 1, type, randomer); break; case 3: SpreadTiles(tileMatrix, xCoord, yCoord + 1, numberOfTiles - 1, type, randomer); break; } }