Ejemplo n.º 1
0
 /// <summary>
 /// This method initializes the room's design by randomly selecting
 /// from a list of valid room designs (e.g. a list of all TRIADs facing UP)
 /// </summary>
 /// <param name="rdb">The database that contains all room designs</param>
 private void initRoomDesign(RoomDatabase rdb)
 {
     int[,] roomDesign = rdb.getRoomDesign(roomType, rotation);
     if (roomDesign != null)
     {
         setRoomDesign(roomDesign);
     }
     else
     {
         throw new Exception("Null Room Design Exception! No room design for type: " + Room.getRoomTypeString(roomType) + " and rotation: " + Room.getRoomRotationString(rotation));
     }
 }
Ejemplo n.º 2
0
        // DFS Maze creation, fixed.
        // TODONT: Add corners for map generation.
        // Deprecated

        /**
         * 22, 22, 22, 22, 12% (deadend) chance.
         */
        private void generateMaze(int x, int y, Room prev)
        {
            int  roomType, roomRotation;
            Room current = getRoom(x, y);

            /**
             * BASE CASE END OF RECURSIVE ALGORITHM
             *
             * This checks if the room has already been
             * explored or if the room is out of bounds
             * from the map.
             */
            if (exploredRooms.Contains(current))
            {
                return;
            }

            if (current == null)
            {
                return;
            }

            /**
             * ROOM TYPE, ROTATION, DESIGN
             *
             * This handles the room generation with
             * regards to room type, rotation, and design
             */

            do
            {
                if (prev == null)
                {
                    roomRotation = random.Next(4);
                }
                else
                {
                    roomRotation = (prev.getRotation() + 2) % 4;
                }
                current.setRotation(roomRotation);
                roomType = random.Next(4) + 2;
                current.setRoomType(roomType);
            } while (!areRoomsConnected(isToTheDirectionOf(current, prev), prev, current) || getAccessibleRooms(current).Count <= 0);

            int[,] roomDesign = roomDatabaseReference.getRoomDesign(roomType, roomRotation);
            if (roomDesign != null)
            {
                current.setRoomDesign(roomDesign);
                current.Initialize();
            }
            else
            {
                // TODONT: Must use room designer java application to create corners.
                // Deprecated. Corner rooms are done already.
                throw new Exception("Undefined Room Design Exception!");
            }


            /**
             * MAZE CREATION
             *
             * Start the DFS creation of the maze
             */

            // Add the current room to list of explored rooms
            exploredRooms.Add(current);

            List <Room> roomsAvailable = getAccessibleRooms(current);

            do
            {
                // Get a random room from the list and remove it from the list
                int  index         = random.Next(roomsAvailable.Count);
                Room roomToVenture = roomsAvailable.ElementAt(index);
                roomsAvailable.RemoveAt(index);

                // The room is already explored, don't go set it anymore
                if (exploredRooms.Contains(roomToVenture))
                {
                    continue;
                }

                // There is no room to venture to, don't go there
                if (roomToVenture == null)
                {
                    continue;
                }

                // Determine the direction to take and the coordinate of the target room
                int     directionToTake       = isToTheDirectionOf(current, roomToVenture);
                Vector2 destinationCoordinate = getPointAt(current, directionToTake);

                // Recurse -- DEPRECATED
                generateMaze((int)destinationCoordinate.X, (int)destinationCoordinate.Y, current);
            } while (roomsAvailable.Count > 0);
        }