Beispiel #1
0
        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)
            {
                Room targetRoom       = rooms[Randomizer.GetRandomNumber(rooms.Count)];
                var  newRoomDirection = GetNeighborWithNoAdditionalNeighbors(rooms, targetRoom);

                if (newRoomDirection == null)
                {
                    continue;
                }

                var newRoom = new Room(targetRoom.GetNeighborCoordinates(newRoomDirection.Value));
                newRoom.AddExit(ReverseDirection(newRoomDirection.Value));
                targetRoom.AddExit(newRoomDirection.Value);

                rooms.Add(newRoom);
            }
            Room[,] roomArray = ConvertListToMap(MarkSpecialRooms <Room>(rooms));

            return(roomArray);
        }
Beispiel #2
0
        /// <summary>
        /// Shuffles this array in place.
        /// </summary>
        public static void Shuffle <T>(T[] items)
        {
            int maxLength = items.Length;

            for (int i = 0; i < items.Length; i++)
            {
                Randomizer.Swap(items, Randomizer.GetRandomNumber(items.Length), Randomizer.GetRandomNumber(items.Length));
            }
        }
Beispiel #3
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);
        }