示例#1
0
        /// <summary>
        /// Generate a Maze
        /// </summary>
        /// <param name="width">Width of the maze</param>
        /// <param name="height">Height of the maze</param>
        /// <param name="innerMapType">The type which is used to store a map</param>
        /// <param name="seed">The seed that is used to generate a maze</param>
        /// <param name="pixelChangedCallback">When a pixel is changed you can define a callback here to for example draw the maze while its being generated, add null if you don't want this. Last 2 longs are for the current step and the total steps (can be used to calculate how far the maze is done being generated)</param>
        /// <returns>A maze</returns>
        public Maze Generate(int width, int height, InnerMapType innerMapType, int seed, Action <int, int, long, long> pixelChangedCallback)
        {
            var map = GoGenerate(new FastRandom(seed), width, height);

            InnerMap innerMap = new BooleanInnerMap(width, height, map);
            var      maze     = new Maze(innerMap);

            return(maze);
        }
示例#2
0
        public void TestInnerMaps()
        {
            Random r = new Random(5);

            int width  = 32 * 8;
            int height = 32 * 12;

            List <InnerMap> maps = new List <InnerMap>();

            var subtypes = GetSubtypes(Assembly.GetAssembly(typeof(InnerMap)), typeof(InnerMap));

            Assert.AreNotEqual(0, subtypes.Count());

            foreach (var brrr in subtypes)
            {
                if (brrr != typeof(InnerMap))
                {
                    var      ctors       = brrr.GetConstructors();
                    var      obj         = ctors[0].Invoke(new object[] { width, height });
                    InnerMap curInnerMap = (InnerMap)obj;
                    maps.Add(curInnerMap);
                }
            }

            Assert.AreNotEqual(0, maps.Count());

            InnerMap refferenceMap = new BooleanInnerMap(width, height);

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    Boolean randombool = r.Next(2) == 0;
                    refferenceMap[x, y] = randombool;
                    foreach (InnerMap curmap in maps)
                    {
                        curmap[x, y] = randombool;
                    }
                }
            }

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    Boolean curbool = refferenceMap[x, y];
                    foreach (InnerMap curmap in maps)
                    {
                        Assert.AreEqual(curbool, curmap[x, y]);
                    }
                }
            }
        }