//----------------------------------------------------------------------------- // Constructor //----------------------------------------------------------------------------- public DungeonMapFloor(DungeonFloor dungeonFloor) { this.dungeonFloor = dungeonFloor; this.floorNumber = dungeonFloor.FloorNumber; this.isDiscovered = dungeonFloor.IsDiscovered; this.size = new Point2I(8, 8); // Create rooms. rooms = new DungeonMapRoom[size.X, size.Y]; isBossFloor = false; if (dungeonFloor.Level != null) { for (int x = 0; x < size.X; x++) { for (int y = 0; y < size.Y; y++) { Point2I loc = new Point2I(x, y); if (dungeonFloor.Level.ContainsRoom(loc)) { Room room = dungeonFloor.Level.GetRoomAt(loc); if (!room.IsHiddenFromMap) { rooms[x, y] = DungeonMapRoom.Create(room, this); if (rooms[x, y] != null && rooms[x, y].IsBossRoom) isBossFloor = true; } } else rooms[x, y] = null; } } } }
//----------------------------------------------------------------------------- // Accessors //----------------------------------------------------------------------------- // Return a sorted list of all the floors in the dungeon. public DungeonFloor[] GetFloors() { int lowestFloorNumber = Int32.MaxValue; int highestFloorNumber = Int32.MinValue; bool foundAny = false; foreach (Level level in world.Levels) { if (level.Dungeon == this) { foundAny = true; if (level.DungeonFloor < lowestFloorNumber) { lowestFloorNumber = level.DungeonFloor; } if (level.DungeonFloor > highestFloorNumber) { highestFloorNumber = level.DungeonFloor; } } } if (!foundAny) { return(new DungeonFloor[0]); } int floorNumberCount = (highestFloorNumber - lowestFloorNumber) + 1; DungeonFloor[] floors = new DungeonFloor[floorNumberCount]; for (int i = 0; i < floorNumberCount; i++) { floors[i] = new DungeonFloor(null, lowestFloorNumber + i); } foreach (Level level in world.Levels) { if (level.Dungeon == this) { floors[level.DungeonFloor - lowestFloorNumber] = new DungeonFloor(level, level.DungeonFloor); } } return(floors); /* * * List<Level> floors = new List<Level>(); * foreach (Level level in world.Levels) { * if (level.Dungeon == this) * floors.Add(level); * } * floors.Sort(delegate(Level a, Level b) { * int floorA = a.DungeonFloor; * int floorB = b.DungeonFloor; * * if (floorA > floorB) * return 1; * else if (floorA < floorB) * return -1; * else * return 0; * }); * * if (floors.Count == 0) * return new Level[0]; * * int minFloorNumber = floors[0].DungeonFloor; * int maxFloorNumber = floors[floors.Count - 1].DungeonFloor; * int floorNumberCount = maxFloorNumber - minFloorNumber; * Level[] floors2 = new Level[floorNumberCount]; * * foreach (Level floor in floors) { * int index = floor.DungeonFloor - minFloorNumber; * floors2[index] = floor; * } * * return floors.ToArray(); */ }
//----------------------------------------------------------------------------- // Accessors //----------------------------------------------------------------------------- // Return a sorted list of all the floors in the dungeon. public DungeonFloor[] GetFloors() { int lowestFloorNumber = Int32.MaxValue; int highestFloorNumber = Int32.MinValue; bool foundAny = false; foreach (Level level in world.Levels) { if (level.Dungeon == this) { foundAny = true; if (level.DungeonFloor < lowestFloorNumber) lowestFloorNumber = level.DungeonFloor; if (level.DungeonFloor > highestFloorNumber) highestFloorNumber = level.DungeonFloor; } } if (!foundAny) return new DungeonFloor[0]; int floorNumberCount = (highestFloorNumber - lowestFloorNumber) + 1; DungeonFloor[] floors = new DungeonFloor[floorNumberCount]; for (int i = 0; i < floorNumberCount; i++) floors[i] = new DungeonFloor(null, lowestFloorNumber + i); foreach (Level level in world.Levels) { if (level.Dungeon == this) floors[level.DungeonFloor - lowestFloorNumber] = new DungeonFloor(level, level.DungeonFloor); } return floors; /* List<Level> floors = new List<Level>(); foreach (Level level in world.Levels) { if (level.Dungeon == this) floors.Add(level); } floors.Sort(delegate(Level a, Level b) { int floorA = a.DungeonFloor; int floorB = b.DungeonFloor; if (floorA > floorB) return 1; else if (floorA < floorB) return -1; else return 0; }); if (floors.Count == 0) return new Level[0]; int minFloorNumber = floors[0].DungeonFloor; int maxFloorNumber = floors[floors.Count - 1].DungeonFloor; int floorNumberCount = maxFloorNumber - minFloorNumber; Level[] floors2 = new Level[floorNumberCount]; foreach (Level floor in floors) { int index = floor.DungeonFloor - minFloorNumber; floors2[index] = floor; } return floors.ToArray(); */ }