示例#1
0
        public void GeneratePathToEnd(Map map, int maxIterations, Room startRoom)
        {
            Room room = startRoom;

            int counter = 2;
            int iteration = 0;
            while (iteration < maxIterations) {
                IEnumerable<Room> neighbours = map.GetNeighbours(room);
                if (neighbours.Any(n => n.X == map.EndX && n.Y == map.EndY)) {
                    room.Id = 99;
                    map.ReachedEnd = true;
                    break;
                }
                foreach (Room neighbour in neighbours.OrderBy(x => _rand.Next())) {
                    if (neighbour.Id == 0 && map.CountNeighbours(neighbour) == 1) {
                        neighbour.Id = counter;
                        room = neighbour;
                        counter++;
                        break;
                    }
                }
                iteration++;
            }
            map.RoomsInPath = counter - 2;
        }
 private Map CreateRandomStartDungeon(int width, int height)
 {
     var map = new Map(width, height);
     map.SetEnd(6, 5);
     map.SetStart(_rand.Next(width), _rand.Next(height));
     return map;
 }
 private void AddSideRooms(Map map, int probability)
 {
     for (int y = 0;y < map.Height;y++) {
         for (int x = 0;x < map.Width;x++) {
             if (map[x, y].Id == 0 && _rand.Next(100) < probability)
                 map[x, y].Id = 88;
         }
     }
 }
 private void AddMulitpleSideRooms(Map map, int probability)
 {
     for (int y = 0; y < map.Height; y++){
         for (int x = 0; x < map.Width; x++){
             if (map[x, y].Id > 1 && map[x, y].Id != 99 && map[x, y].Id != 88) {
                 if(_rand.Next(100) < probability)
                     AddSideRooms(map[x, y], map);
             }
         }
     }
 }
 private void AddSideRooms(Room room, Map map)
 {
     if (room.X - 1 >= 0 && map[room.X - 1, room.Y].Id == 0){
         map[room.X - 1, room.Y].Id = 88;
     }
     if (room.X + 1 < map.Width && map[room.X + 1, room.Y].Id == 0) {
         map[room.X + 1, room.Y].Id = 88;
     }
     if (room.Y - 1 >= 0 && map[room.X, room.Y - 1].Id == 0){
         map[room.X, room.Y - 1].Id = 88;
     }
     if (room.Y + 1 < map.Height && map[room.X, room.Y + 1].Id == 0){
         map[room.X, room.Y + 1].Id = 88;
     }
 }
示例#6
0
 public static void Draw(Map map)
 {
     Console.WriteLine(
         "--------------------------------------------------------\n");
     Console.ForegroundColor = ConsoleColor.White;
     for (int y = 0;y < map.Height;y++) {
         for (int x = 0;x < map.Width;x++) {
             if (map[x, y].Id == 1) {
                 Console.ForegroundColor = ConsoleColor.Red;
             }
             else if (map[x, y].HasDoors){
                 if (map[x, y].Id == 88)
                     Console.ForegroundColor = ConsoleColor.Blue;
                 else
                     Console.ForegroundColor = ConsoleColor.Green;
             }
             Console.Write(map[x, y].Id.ToString().PadLeft(4));
             Console.ForegroundColor = ConsoleColor.White;
         }
         Console.Write(Environment.NewLine);
     }
 }
示例#7
0
 public void GeneratePathToEnd(Map map, int maxIterations)
 {
     GeneratePathToEnd(map, maxIterations, map[map.StartX, map.StartY]);
 }
 private void RemoveUnconnectedRooms(Map map)
 {
     for (int y = 0; y < map.Height; y++) {
         for (int x = 0; x < map.Width; x++) {
             if (map.CountNeighbours(map[x, y]) == 0)
                 map[x, y] = new Room { X = x, Y = y };
             else if (RoomHasOnlySideRoomConnections(map, map[x, y]))
                 map[x, y] = new Room { X = x, Y = y };
         }
     }
 }
 private void AddSideRooms(Map map)
 {
     AddSideRooms(map, 30);
 }
示例#10
0
        private bool RoomHasOnlySideRoomConnections(Map map, Room room)
        {
            var neighbours = map.GetNeighbours(room);
            if (room.Id == 88 && neighbours.All(n => n.Id == 88 || n.Id == 0))
                return true;

            return false;
        }