示例#1
0
        /// <summary>
        /// Generate a map according the configuration received.
        /// </summary>
        /// <param name="config">The configuration used to generate the map.</param>
        /// <param name="seed">A seed to be used for the generation. If null a random seed will be generated.</param>
        /// <returns>The generated map.</returns>
        public virtual Map <T> Generate(DungeonConfiguration config, int?seed = null)
        {
            var randomizer = new Randomizer();

            if (!seed.HasValue)
            {
                seed = Guid.NewGuid().GetHashCode();
            }
            randomizer.SetSeed(seed.Value);
            var halfHeight = config.Height / 2;
            var halfWidth  = config.Width / 2;
            var map        = new Map <BinaryCell>(halfWidth, halfHeight);

            //pre processing
            foreach (var preProcessor in mPreProcessors)
            {
                preProcessor.ProcessMap(map, config, randomizer);
            }

            //double map
            var postMap = mMapConverter.ConvertMap(map, config, randomizer);

            //post processing
            foreach (var postProcessor in mPostProcessors)
            {
                postProcessor.ProcessMap(postMap, config, randomizer);
            }

            return(postMap);
        }