Beispiel #1
0
        public override Room[,] GenerateRooms(int maxRooms)
        {
            int minX = 0;
            int maxX = 0;
            int minY = 0;
            int maxY = 0;

            Directions[]        directions = (Directions[])Enum.GetValues(typeof(Directions));
            List <WeightedRoom> rooms      = new List <WeightedRoom>();

            rooms.Add(new WeightedRoom(new Point(0, 0)));

            while (rooms.Count < maxRooms)
            {
                WeightedRoom targetRoom = (WeightedRoom)rooms[Randomizer.GetRandomNumber(rooms.Count)];

                if (!ShouldCreateNextRoom(targetRoom))
                {
                    continue;
                }


                Directions direction  = Randomizer.GetRandomDirection();
                Exit       targetExit = targetRoom.GetExit(direction);

                if (targetExit != null)
                {
                    continue;
                }

                targetExit = new Exit(direction);
                targetRoom.AddExit(direction);
                WeightedRoom neighbor          = GetRoomAtPoint(targetRoom.GetNeighborCoordinates(direction), rooms);
                Directions   neighborDirection = ReverseDirection(direction);

                if (neighbor != null)
                {
                    neighbor.AddExit(neighborDirection);
                }
                else
                {
                    WeightedRoom newRoom = new WeightedRoom(targetRoom.GetNeighborCoordinates(direction));
                    newRoom.AddExit(neighborDirection);
                    rooms.Add(newRoom);
                }
            }
            Room[,] roomArray = ConvertListToMap(MarkSpecialRooms(rooms));

            return(roomArray);
        }
        public override Room[,] GenerateRooms(int maxRooms)
        {
            Directions[] directions = (Directions[])Enum.GetValues(typeof(Directions));
            List <Room>  rooms      = new List <Room>();

            rooms.Add(new Room(new Point(0, 0)));

            while (rooms.Count < maxRooms)
            {
                int        index      = Randomizer.GetHighRandomNumber(rooms.Count);
                Room       targetRoom = rooms[index];
                Directions direction  = Randomizer.GetRandomDirection();
                Exit       targetExit = targetRoom.GetExit(direction);

                if (targetExit != null)
                {
                    continue;
                }

                targetExit = new Exit(direction);
                targetRoom.AddExit(direction);
                Room       neighbor          = GetRoomAtPoint(targetRoom.GetNeighborCoordinates(direction), rooms);
                Directions neighborDirection = ReverseDirection(direction);

                if (neighbor != null)
                {
                    neighbor.AddExit(neighborDirection);
                }
                else
                {
                    Room newRoom = new Room(targetRoom.GetNeighborCoordinates(direction));
                    newRoom.AddExit(neighborDirection);
                    rooms.Add(newRoom);
                }
            }
            Room[,] roomArray = ConvertListToMap(MarkSpecialRooms <Room>(rooms));

            return(roomArray);
        }