Esempio n. 1
0
        /// <summary>
        /// Executes the command as many times the command demands.  If
        /// the command unsuccessfully adds rooms too many times in a row,
        /// it will terminate early.
        /// </summary>
        /// <returns>
        /// True if the command executed successfully otherwise false if
        /// it was terminated early because it reached the max number of
        /// failed generations.
        /// </returns>
        private bool ExecuteCommandLoop()
        {
            int failedRoomGenerationAttempts = 0;

            while (currentCommand.RoomsLeft > 0 && roomsToGenerate > roomsBuilt && failedRoomGenerationAttempts < MAXIMUM_GENERATION_FAILS_BEFORE_COMMAND_IS_SKIPPED)
            {
                if (activeFloorSprawler.NumberOfRooms == 0)
                {
                    TryToRepopulateSprawler();
                    if (activeFloorSprawler.NumberOfRooms == 0)
                    {
                        throw new NoRoomsToGenerateFromException();
                    }
                }

                int roomsGenerated = ExecuteCommandOnce();
                roomsBuilt += roomsGenerated;

                if (currentCommand.ShouldShuffleAfterPass)
                {
                    activeFloorSprawler.shuffleRooms();
                    activeFloorSprawler.shuffleRooms();
                    activeFloorSprawler.shuffleRooms();
                    activeFloorSprawler.shuffleRooms();
                    activeFloorSprawler.shuffleRooms();
                }

                if (currentCommand.ShouldFlipDepthOrBreadthFirstAfterPass)
                {
                    activeFloorSprawler.IsDepthFirst = !activeFloorSprawler.IsDepthFirst;
                }

                if (roomsGenerated == 0)
                {
                    failedRoomGenerationAttempts++;
                }
            }

            return(failedRoomGenerationAttempts < MAXIMUM_GENERATION_FAILS_BEFORE_COMMAND_IS_SKIPPED);
        }
Esempio n. 2
0
        /// <summary>
        /// Changes the order of input by adding the Room
        /// objects to a temporary FloorSprawler and using
        /// the shuffleRooms method of that class.  Returns
        /// as a new object.
        /// </summary>
        /// <param name="input"></param>
        /// <returns>A List of type Room where the order is
        /// different than the order within input.</returns>
        private List <Room> GetShuffledRoomArray(List <Room> input)
        {
            FloorSprawler tempSprawler = new FloorSprawler();

            foreach (Room r in input)
            {
                if (r != null)
                {
                    tempSprawler.addRoom(r);
                }
            }
            tempSprawler.shuffleRooms();
            List <Room> toReturn = new List <Room>();

            while (tempSprawler.HasNextRoom)
            {
                toReturn.Add(tempSprawler.removeNextRoom());
            }
            return(toReturn);
        }