Exemplo n.º 1
0
        private void GenerateButton_Click(object sender, EventArgs e)
        {
            if (!Loaded)
            {
                return;
            }
            var map = new FiniteMap2D(49, 49);
            var growingTreeGenerator = new GrowingTreeMazeGenerator(map);
            var activeGenerator      = new ActiveCellsMazeGeneratorDecorator(growingTreeGenerator);
            var renderer             = new GLControlMapRenderer(MainGLControl, map);
            var runner = new MazeGenerationRunner(activeGenerator, renderer);

            runner.Start();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            User32Imports.Maximize();
            var track = false;

            Console.CursorVisible = false;

            var map = new FiniteMap2D(15, 25);
            //var map = new FiniteMap3D(15, 25, 5);
            //var map = new InfiniteMap(2);
            //var map = new NonCreatingInfiniteMap(2);

            var  finiteMap  = new AsFiniteMapDecorator(map, map.Size ?? new Point(55, 75));
            var  map2D      = new AsSmallerDimensionMapDecorator(map, new int[] {});
            IMap displayMap = finiteMap;
            //displayMap = new TransposeMapDecorator(displayMap);

            //var innerGenerator = new TestMazeGenerator(map);
            //var innerGenerator = new KruskalMazeGenerator(map);
            //var innerGenerator = new AldousBroderMazeGenerator(map);
            //var innerGenerator = new GameOfLifeGenerator(map);
            //var innerGenerator = new BinaryTreeMazeGenerator(map);
            var innerGenerator = new GrowingTreeMazeGenerator(map);

            var generator = new ActiveCellsMazeGeneratorDecorator(innerGenerator);
            //var generator = innerGenerator;

            var renderer           = new ConsoleMapRenderer(displayMap, true, false);
            var fullRenderer       = new InstantAsFullMapRendererDecorator(renderer, true);
            var generatorDelay     = 100d;
            var rendererDelay      = 1000d / 60d;
            var generatorDelaySpan = TimeSpan.FromTicks((long)(generatorDelay * TimeSpan.TicksPerMillisecond));
            var rendererDelaySpan  = TimeSpan.FromTicks((long)(rendererDelay * TimeSpan.TicksPerMillisecond));
            var runner             = new MazeGenerationRunner(generator, fullRenderer, generatorDelaySpan, rendererDelaySpan);

            var generatorSteps = 0;
            var rendererSteps  = 0;

            runner.AfterGenerate += results =>
            {
                generatorSteps++;
            };
            runner.BeforeRender += results =>
            {
                if (track && results.Results.Count > 0)
                {
                    finiteMap.Offset = displayMap.Size / 2 - results.Results[0].Point;
                }
            };
            runner.AfterRender += results =>
            {
                rendererSteps++;
                Console.WriteLine("Generated steps: " + generatorSteps);
                Console.WriteLine("Rendered steps: " + rendererSteps);
                if (results.ResultsType == GenerationResultsType.GenerationCompleted)
                {
                    Console.WriteLine("Completed!");
                }
            };

            runner.Start();

            while (true)
            {
                var key = Console.ReadKey(true);
                switch (key.Key)
                {
                case ConsoleKey.NumPad8:
                case ConsoleKey.UpArrow:
                    finiteMap.Offset[0]++;
                    break;

                case ConsoleKey.NumPad2:
                case ConsoleKey.DownArrow:
                    finiteMap.Offset[0]--;
                    break;

                case ConsoleKey.NumPad6:
                case ConsoleKey.RightArrow:
                    finiteMap.Offset[1]--;
                    break;

                case ConsoleKey.NumPad4:
                case ConsoleKey.LeftArrow:
                    finiteMap.Offset[1]++;
                    break;

                case ConsoleKey.NumPad5:
                    track = !track;
                    break;

                case ConsoleKey.NumPad7:
                    finiteMap.Size -= 1;
                    break;

                case ConsoleKey.NumPad9:
                    finiteMap.Size += 1;
                    break;

                case ConsoleKey.NumPad3:
                    map2D.ExtraLayers[0] += 1;
                    break;

                case ConsoleKey.NumPad1:
                    map2D.ExtraLayers[0] -= 1;
                    break;

                case ConsoleKey.X:
                    runner.Stop();
                    return;
                }
            }
        }
Exemplo n.º 3
0
        private void GenerateButton_Click(object sender, EventArgs e)
        {
            StopRunner();
            var width  = Convert.ToInt32(WidthTextBox.Text);
            var height = Convert.ToInt32(HeightTextBox.Text);

            if (InfiniteMapCheckBox.Checked)
            {
                Map = new InfiniteMap(2);
            }
            else
            {
                Map = new FiniteMap2D(width, height);
            }
            var rng = new Random();

            switch (CurrentAlgorithm)
            {
            case MazeGenerationAlgorithm.GrowingTree:
                GrowingTreeMazeGenerator = new GrowingTreeMazeGenerator(Map, rng);
                MazeGenerator            = GrowingTreeMazeGenerator;
                break;

            case MazeGenerationAlgorithm.Kruskal:
                KruskalMazeGenerator = new KruskalMazeGenerator(Map, rng);
                MazeGenerator        = KruskalMazeGenerator;
                break;

            case MazeGenerationAlgorithm.RecursiveDivision:
                RecursiveDivisionMazeGenerator = new RecursiveDivisionMazeGenerator(Map, rng);
                MazeGenerator = RecursiveDivisionMazeGenerator;
                break;

            case MazeGenerationAlgorithm.BinaryTree:
                BinaryTreeMazeGenerator = new BinaryTreeMazeGenerator(Map, rng);
                MazeGenerator           = BinaryTreeMazeGenerator;
                break;

            case MazeGenerationAlgorithm.AldousBroder:
                AldousBroderMazeGenerator = new AldousBroderMazeGenerator(Map, rng);
                MazeGenerator             = AldousBroderMazeGenerator;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            SyncAllGeneratorParameters();
            var activeCellsGenerator = new ActiveCellsMazeGeneratorDecorator(MazeGenerator);
            var displayMap           = new AsFiniteMapDecorator(Map, Map.Size ?? new Point(width, height));

            MapRenderer = new PictureBoxMapRenderer(displayMap, MainPictureBox);
            Runner      = new MazeGenerationRunner(activeCellsGenerator, MapRenderer, CurrentGeneratorDelay, CurrentRendererDelay, true);
            var generatorSteps = 0;
            var rendererSteps  = 0;

            Runner.AfterGenerate += results => { generatorSteps++; };
            Runner.BeforeRender  += results =>
            {
                if (TrackChanges && results.Results.Count > 0)
                {
                    displayMap.Offset = displayMap.Size / 2 - results.Results[0].Point;
                }
            };
            Runner.AfterRender += results => { rendererSteps++; };
            Runner.Start();
        }