private void EnforceWallHeight(RandomDungeon dungeon) { // Add a bottom layer of walls for (int x = 0; x < dungeon.width; ++x) { for (int y = dungeon.height - 2; y >= 0; --y) { if (dungeon.TileType(x, y) == RandomDungeonTileData.WALL_TILE && dungeon.TileType(x, y + 1) == RandomDungeonTileData.EMPTY_TILE && (y - 1 < 0 || dungeon.TileType(x, y - 1) != RandomDungeonTileData.WALL_TILE)) { dungeon.ChangeTileType(x, y + 1, RandomDungeonTileData.WALL_TILE); } } } for (int x = 0; x < dungeon.width; ++x) { for (int y = dungeon.height - 2; y >= 0; --y) { if (dungeon.TileType(x, y) == RandomDungeonTileData.EMPTY_TILE && (y - 1 < 0 || dungeon.TileType(x, y - 1) == RandomDungeonTileData.WALL_TILE) && ((x - 1 >= 0 && dungeon.TileType(x - 1, y) == RandomDungeonTileData.WALL_TILE) || (x + 1 < dungeon.width && dungeon.TileType(x + 1, y) == RandomDungeonTileData.WALL_TILE))) { dungeon.ChangeTileType(x, y + 1, RandomDungeonTileData.WALL_TILE); } } } for (int x = 0; x < dungeon.width; ++x) { for (int y = 0; y < dungeon.height; ++y) { int tile = dungeon.TileType(x, y); bool wallBelow = (y < dungeon.height - 1 && dungeon.TileType(x, y + 1) == RandomDungeonTileData.WALL_TILE); if (tile == RandomDungeonTileData.EMPTY_TILE) { if (wallBelow) { dungeon.ChangeTileType(x, y, RandomDungeonTileData.WALL_TILE); } } } } }
/// <summary> /// After map generation is finished, this will close off all the exits that don't lead to /// another room. /// </summary> /// <param name="dungeon"></param> private void CloseExitsToNowhere(RandomDungeon dungeon) { if (stopCloseExitsToNowhere) { return; } int exitPasses = 2; // should be equal the wall height for (int exitPass = 0; exitPass < exitPasses; ++exitPass) { for (int x = 0; x < dungeon.width; ++x) { for (int y = 0; y < dungeon.height; ++y) { int tile = dungeon.TileType(x, y); if (tile == RandomDungeonTileData.EXIT_TILE) { if (dungeon.NumWalkableNeighbors(x, y) <= 1) { dungeon.ChangeTileType(x, y, RandomDungeonTileData.WALL_TILE); } } } } } for (int x = 0; x < dungeon.width; ++x) { for (int y = 0; y < dungeon.height; ++y) { int tile = dungeon.TileType(x, y); if (tile == RandomDungeonTileData.EMPTY_TILE) { if (dungeon.NumWalkableNeighbors(x, y) >= 1) { dungeon.ChangeTileType(x, y, RandomDungeonTileData.WALL_TILE); } } } } }
private void FillEmptyCellsWithWalls(RandomDungeon dungeon) { for (int x = 0; x < dungeon.width; ++x) { for (int y = 0; y < dungeon.height; ++y) { if (dungeon.TileType(x, y) == RandomDungeonTileData.EMPTY_TILE) { dungeon.ChangeTileType(x, y, RandomDungeonTileData.WALL_TILE); } } } }