private IEnumerator Setup(int level) { int difficulty = (int)Mathf.Log(level, 2f); MapGenerator mapGenerator = new MapGenerator(mapSize + difficulty); while (!mapGenerator.IsEnd()) { mapGenerator.Update(); yield return(null); } int[,] chip = mapGenerator.MapChip; //Creates the outer walls and floor. BoardSetup(chip); //Reset our list of gridpositions. InitialiseList(chip); //Instantiate a random number of wall tiles based on minimum and maximum, at randomized positions. LayoutObjectAtRandom(wallTiles, wallCount.minimum, wallCount.maximum); //Instantiate a random number of food tiles based on minimum and maximum, at randomized positions. LayoutObjectAtRandom(foodTiles, foodCount.minimum, foodCount.maximum); //Determine number of enemies based on current level number, based on a logarithmic progression int enemyCount = (int)(difficulty + mapSize / 5); //Instantiate a random number of enemies based on minimum and maximum, at randomized positions. LayoutObjectAtRandom(enemyTiles, enemyCount, enemyCount); //Instantiate the exit tile in the upper right hand corner of our game board //Instantiate (exit, new Vector3 (columns - 1, rows - 1, 0f), Quaternion.identity); isSetup = true; }