public void CreateCityRooms <T>(CityMapGenerator <T> mapGenerator, int maxLeafSize, int roomMaxSize, int roomMinSize) where T : class, IMap, new() { if (childLeafLeft != null || childLeafRight != null) { //# recursively search for children until you hit the end of the branch if (childLeafLeft != null) { childLeafLeft.CreateCityRooms(mapGenerator, maxLeafSize, roomMaxSize, roomMinSize); } if (childLeafRight != null) { childLeafRight.CreateCityRooms(mapGenerator, maxLeafSize, roomMaxSize, roomMinSize); } if (childLeafLeft != null && childLeafRight != null) { mapGenerator.createHall(childLeafLeft.GetRoom(), childLeafRight.GetRoom()); } } else { int w = _random.Next(roomMinSize, Math.Min(roomMaxSize, leafWidth - 1)); int h = _random.Next(roomMinSize, Math.Min(roomMaxSize, leafHeight - 1)); int x = _random.Next(_x, _x + (leafWidth - 1) - w); int y = _random.Next(_y, _y + (leafHeight - 1) - h); _room = new Rect(x, y, w, h); mapGenerator.createRoom(_room); } }
// Start is called before the first frame update private void Start() { System.Random random = new System.Random(DateTime.Now.Millisecond); IMapGenerator <Map> mapGenerator; switch (generator) { case Generators.BorderOnlyMapGenerator: { mapGenerator = new BorderOnlyMapGenerator <Map>(mapWidth, mapHeight); _map = Map.Create(mapGenerator); break; } case Generators.BSPTreeMapGenerator: { mapGenerator = new BSPTreeMapGenerator <Map>(mapWidth, mapHeight, maxLeafSize, minLeafSize, roomMaxSize, roomMinSize, random); _map = Map.Create(mapGenerator); break; } case Generators.CaveMapGenerator: { mapGenerator = new CaveMapGenerator <Map>(mapWidth, mapHeight, neighbours, iterations, closeTileProb, lowerLimit, upperLimit, emptyNeighbours, emptyTileNeighbours, corridorSpace, corridorMaxTurns, corridorMin, corridorMax, breakOut, random); _map = Map.Create(mapGenerator); break; } case Generators.CellularAutomataMapGenerator: { mapGenerator = new CellularAutomataMapGenerator <Map>(mapWidth, mapHeight, fillProbability, totalIterations, cutoffOfBigAreaFill, random); _map = Map.Create(mapGenerator); break; } case Generators.CityMapGenerator: { mapGenerator = new CityMapGenerator <Map>(mapWidth, mapHeight, maxCityLeafSize, minCityLeafSize, roomMaxCitySize, roomMinCitySize, random); _map = Map.Create(mapGenerator); break; } case Generators.DFSMazeMapGenerator: { mapGenerator = new DFSMazeMapGenerator <Map>(mapWidth, mapHeight, random); _map = Map.Create(mapGenerator); break; } case Generators.DrunkardsWalkMapGenerator: { mapGenerator = new DrunkardsWalkMapGenerator <Map>(mapWidth, mapHeight, percentGoal, walkIterations, weightedTowardCenter, weightedTowardPreviousDirection, random); _map = Map.Create(mapGenerator); break; } case Generators.TunnelingMazeMapGenerator: { mapGenerator = new TunnelingMazeMapGenerator <Map>(mapWidth, mapHeight, magicNumber, random); _map = Map.Create(mapGenerator); break; } case Generators.TunnelingWithRoomsMapGenerator: { mapGenerator = new TunnelingWithRoomsMapGenerator <Map>(mapWidth, mapHeight, maxTunnelingRooms, roomMaxTunnelingSize, roomMinTunnelingSize, random); _map = Map.Create(mapGenerator); break; } } Camera.main.transform.localPosition = new Vector3(_map.Width / 2, _map.Height / 2, -10); RenderMap(); }