public void GenerateMaze() { for (int i = x1; i <= x2; ++i) { for (int j = y1; j <= y2; ++j) { map[i, j] = Terrain.Get("ground").Character; } } split(); }
private void initMap(int width, int height) { map = new Map(width, height); for (int i = 0; i < width; ++i) { for (int j = 0; j < height; ++j) { map[i, j] = Terrain.Get("wall").Character; } } }
public void GenerateTown() { for (int i = x1; i <= x2; ++i) { for (int j = y1; j <= y2; ++j) { map[i, j] = Terrain.Get("grass").Character; } } split(); makeHouses(); }
public override Position GenerateFeature(char feature) { int x; int y; do { x = Rng.Random.Next(map.Width); y = Rng.Random.Next(map.Height); } while (map[x, y] != Terrain.Get("grass").Character); map[x, y] = feature; return(new Position(x, y)); }
private void createPark() { for (int x = x1 + 1; x < x2; ++x) { for (int y = y1 + 1; y < y2; ++y) { if (Rng.Random.NextFloat() < 0.4) { map[x, y] = Terrain.Get("tree").Character; } } } }
public void GenerateDungeon() { for (int i = x1; i <= x2; ++i) { for (int j = y1; j <= y2; ++j) { map[i, j] = Terrain.Get("wall").Character; } } split(); makeRooms(); connectRooms(); }
private char getDoor() { if (Rng.Random.NextFloat() < HIDDEN_DOOR_RATE) { return(Terrain.Get("hidden-door").Character); } else if (Rng.Random.NextFloat() < OPEN_DOOR_RATE) { return(Terrain.Get("open-door").Character); } else { return(Terrain.Get("closed-door").Character); } }
public void create(Map map) { char terrain = Terrain.Get("ground").Character; if (Rng.Random.NextFloat() < DARK_ROOM_RATE) { terrain = Terrain.Get("dark-ground").Character; } for (int i = x1 + 1; i < x2; ++i) { for (int j = y1 + 1; j < y2; ++j) { map[i, j] = terrain; } } }
public void create(Map map) { for (int i = x1; i <= x2; ++i) { for (int j = y1; j <= y2; ++j) { if (i == x1 || i == x2 || j == y1 || j == y2) { map[i, j] = Terrain.Get("wall").Character; } else { map[i, j] = Terrain.Get("floor").Character; } } } int wall = Rng.Random.Next(4); int x = 0; int y = 0; switch (wall) { case 0: x = Rng.Random.Next(width - 2) + 1 + x1; y = y1; break; case 1: x = Rng.Random.Next(width - 2) + 1 + x1; y = y2; break; case 2: y = Rng.Random.Next(height - 2) + 1 + y1; x = x1; break; case 3: y = Rng.Random.Next(height - 2) + 1 + y1; x = x2; break; default: break; //does not happen } map[x, y] = Terrain.Get("closed-door").Character; }
private void createPond() { int cx = x1 + width / 2; int cy = y1 + height / 2; for (int x = x1 + 1; x < x2; ++x) { for (int y = y1 + 1; y < y2; ++y) { int distance = (x - cx) * (x - cx) + (y - cy) * (y - cy); int maxDistance = Math.Min(width, height) / 2; maxDistance *= maxDistance; if (distance < maxDistance) { map[x, y] = Terrain.Get("water").Character; } } } }
public void GenerateRiver(Map map) { int startPosition = Rng.Random.Next(map.Width - MIN_RIVER_WIDTH); int currentRiverWidth = MIN_RIVER_WIDTH; for (int j = 0; j < map.Height; ++j) { int r = Rng.Random.Next(10); if (r < 3) { startPosition++; } if (r > 7) { startPosition--; } r = Rng.Random.Next(10); if (r < 3) { currentRiverWidth++; } if (r > 7) { currentRiverWidth--; } if (currentRiverWidth > MAX_RIVER_WIDTH) { currentRiverWidth = MAX_RIVER_WIDTH; } if (currentRiverWidth < MIN_RIVER_WIDTH) { currentRiverWidth = MIN_RIVER_WIDTH; } for (int i = startPosition; i <= startPosition + currentRiverWidth; ++i) { if (i >= 0 && j >= 0 && i < map.Width && j < map.Height) { map[i, j] = Terrain.Get("water").Character; } } } }
public override Map Generate(int width, int height) { Map map = new Map(width, height); for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { if (Rng.Random.NextFloat() < 0.3) { map[x, y] = Terrain.Get("tree").Character; } else { map[x, y] = Terrain.Get("grass").Character; } } } this.map = map; new RiverGenerator().GenerateRiver(map); return(map); }
/// <summary> /// Enters the LevelStructure. /// Sets up or loads the Map. /// </summary> public void Enter() { if (Persistent && map != null) { map.Load(Name); } else { Map = mapGenerator.Generate(levelWidth, levelHeight); foreach (Passage passage in upPassages) { Position position = mapGenerator.GenerateFeature(Terrain.Get("upstair").Character); passage.Position = position; } foreach (Passage passage in downPassages) { Position position = mapGenerator.GenerateFeature(Terrain.Get("downstair").Character); passage.Position = position; } // TODO consider refactoring this to avoid circular reference to GameController GameController.Instance.ItemGenerator.Generate(this); GameController.Instance.MonsterGenerator.Generate(this); } }
/// <summary> /// Reimplement in subclass to change display colors /// </summary> /// <param name="c"></param> /// <returns></returns> public virtual ConsoleColor GetDisplayColor(char c) { return(Terrain.Get(c).Color); }
/// <summary> /// Indicates, whether light can pass a specified terrain feature. /// Useful for computing FoV /// </summary> /// <param name="c">a character reoresenting the terrain feature</param> /// <returns>true, if light can pass the terrain feature</returns> public static bool IsTransparent(char c) { return(Terrain.Get(c).Transparent); }
void split() { splitOrientation = chooseSplit(); if (splitOrientation == SplitOrientation.Horizontal) { int r = Rng.Random.Next(width - 2) + 1; child1 = new MazeCell(map, this); child1.x1 = x1; child1.y1 = y1; child1.x2 = x1 + r - 1; child1.y2 = y2; child2 = new MazeCell(map, this); child2.x1 = x1 + r + 1; child2.y1 = y1; child2.x2 = x2; child2.y2 = y2; for (int y = y1; y <= y2; ++y) { map[x1 + r, y] = Terrain.Get("wall").Character; } if (parent == null || splitOrientation == parent.splitOrientation) { } else { connection = Rng.Random.Next(height - 1); if (connection >= parent.connection) { connection++; } } connection = Rng.Random.Next(height); map[x1 + r, y1 + connection] = Terrain.Get("ground").Character; } if (splitOrientation == SplitOrientation.Vertical) { int r = Rng.Random.Next(height - 2) + 1; child1 = new MazeCell(map, this); child1.x1 = x1; child1.y1 = y1; child1.x2 = x2; child1.y2 = y1 + r - 1; child2 = new MazeCell(map, this); child2.x1 = x1; child2.y1 = y1 + r + 1; child2.x2 = x2; child2.y2 = y2; for (int x = x1; x <= x2; ++x) { map[x, y1 + r] = Terrain.Get("wall").Character; } connection = Rng.Random.Next(width); map[x1 + connection, y1 + r] = Terrain.Get("ground").Character; } if (child1.canSplit) { child1.split(); } if (child2.canSplit) { child2.split(); } }
public virtual char GetDisplayCharacter(char c) { return(Terrain.Get(c).Display); }
void connectRooms() { if (hasChildren) { if (splitOrientation == SplitOrientation.Horizontal) { int targetX = child1.x2; int targetY = Rng.Random.Next(child1.y2 - child1.y1) + child1.y1; Room room1 = child1.getClosestRoom(targetX, targetY); Room room2 = child2.getClosestRoom(targetX, targetY); int cx1 = room1.x2; int cy1 = Rng.Random.Next(room1.y2 - room1.y1 - 2) + room1.y1 + 1; map[cx1, cy1] = getDoor(); while (cx1 < child1.x2) { map[++cx1, cy1] = Terrain.Get("corridor").Character; } // int cx2 = room2.x1; int cy2 = Rng.Random.Next(room2.y2 - room2.y1 - 2) + room2.y1 + 1; map[cx2, cy2] = getDoor(); while (cx2 > child1.x2) { map[--cx2, cy2] = Terrain.Get("corridor").Character; } // while (cy1 != cy2) { if (cy1 > cy2) { cy1--; } else { cy1++; } map[cx1, cy1] = Terrain.Get("corridor").Character; } } else { int targetX = Rng.Random.Next(child1.x2 - child1.x1) + child1.x1; int targetY = child1.y2; Room room1 = child1.getClosestRoom(targetX, targetY); Room room2 = child2.getClosestRoom(targetX, targetY); int cx1 = Rng.Random.Next(room1.x2 - room1.x1 - 2) + room1.x1 + 1; int cy1 = room1.y2; map[cx1, cy1] = getDoor(); while (cy1 < child1.y2) { map[cx1, ++cy1] = Terrain.Get("corridor").Character; } // int cx2 = Rng.Random.Next(room2.x2 - room2.x1 - 1) + room2.x1 + 1; int cy2 = room2.y1; map[cx2, cy2] = getDoor(); while (cy2 > child1.y2) { map[cx2, --cy2] = Terrain.Get("corridor").Character; } // while (cx1 != cx2) { if (cx1 > cx2) { cx1--; } else { cx1++; } map[cx1, cy1] = Terrain.Get("corridor").Character; } } child1.connectRooms(); child2.connectRooms(); } }