Beispiel #1
0
        private void button20_Click(object sender, EventArgs e)
        {
            int size = int.Parse(comboBox3.Text);

            Task.Run(() =>
            {
                var g = this.CreateGraphics();

                int width = (this.Width / size - 12 / size) / 2 * 2;
                int height = (this.Height / size - 40 / size) / 2 * 2;

                g.FillRectangle(Brushes.Black, 0, 0, this.Width + 1, this.Height + 1);

                Algorithm curalg;
                if (r.Next(2) == 0)
                {
                    curalg = new AlgorithmBacktrack();
                }
                else
                {
                    curalg = new AlgorithmKruskal();
                }

                Maze m = curalg.Generate(width, height, InnerMapType.BitArreintjeFast, r.Next(), (x, y, cur, tot) =>
                {
                    curXInMaze = x;
                    curYInMaze = y;
                    currentStepsToCalcPercentage = cur;
                    totalStepsToCalcPercentage = tot;
                    g.FillRectangle(Brushes.White, x * size, y * size, size, size);
                    //Thread.Sleep(200);
                });

                var path = PathFinderDepthFirstSmart.GoFind(m.InnerMap, (x, y, pathThing) =>
                {
                    if (pathThing)
                    {
                        g.FillRectangle(Brushes.Green, x * size, y * size, size, size);
                    }
                    else
                    {
                        g.FillRectangle(Brushes.Gray, x * size, y * size, size, size);
                    }

                });

            });
        }
Beispiel #2
0
        private void button33_Click(object sender, EventArgs e)
        {
            Task.Run(() =>
            {
                var g = panel1.CreateGraphics();

                int sizemodifier = 20;

                int width = panel1.Width;
                int height = panel1.Height;

                int mazeWidth = 12;
                int mazeHeight = 12;

                //int width = 100;
                //int height = 150;

                g.FillRectangle(Brushes.Black, 0, 0, width + 1, height + 1);

                int randomnow = r.Next();
                Maze m = new AlgorithmKruskal().Generate(mazeWidth, mazeHeight, InnerMapType.BitArreintjeFast, randomnow, (x, y, cur, tot) =>
                {

                    //Thread.Sleep(curDelay);

                    g.FillRectangle(Brushes.White, x * sizemodifier, y * sizemodifier, sizemodifier, sizemodifier);

                    curXInMaze = x;
                    curYInMaze = y;

                    this.currentStepsToCalcPercentage = cur;
                    this.totalStepsToCalcPercentage = tot;

                    //Thread.Sleep(200);
                });

                var path = PathFinderDepthFirstSmart.GoFind(m.InnerMap, (x, y, pathThing) =>
                {

                    Thread.Sleep(curDelay);

                    if (pathThing)
                    {
                        g.FillRectangle(Brushes.Green, x * sizemodifier, y * sizemodifier, sizemodifier, sizemodifier);
                    }
                    else
                    {
                        g.FillRectangle(Brushes.Gray, x * sizemodifier, y * sizemodifier, sizemodifier, sizemodifier);
                    }

                });

                foreach (var pathnode in path)
                {
                    g.FillRectangle(Brushes.Red, pathnode.X * sizemodifier, pathnode.Y * sizemodifier, sizemodifier, sizemodifier);
                }
            });
        }
Beispiel #3
0
        private void button41_Click(object sender, EventArgs e)
        {
            comboBox1.SelectedIndex = 19;
            Task.Run(() =>
            {
                var g = panel1.CreateGraphics();

                int sizemodifier = 1;

                this.Invoke(new Action(() =>
                {
                    sizemodifier = int.Parse(comboBox1.SelectedItem.ToString());
                }));

                int width = panel1.Width;
                int height = panel1.Height;

                int mazeWidth = width / sizemodifier / 2 * 2;
                int mazeHeight = height / sizemodifier / 2 * 2;

                //int width = 100;
                //int height = 150;

                g.FillRectangle(Brushes.Black, 0, 0, width + 1, height + 1);

                var intrandomvalue = 284434191;
                DebugMSG("Random: " + intrandomvalue);

                Maze m = new AlgorithmKruskal().Generate(mazeWidth, mazeHeight, InnerMapType.BitArreintjeFast, intrandomvalue, (x, y, cur, tot) =>
                {

                    //Thread.Sleep(curDelay);

                    g.FillRectangle(Brushes.White, x * sizemodifier, y * sizemodifier, sizemodifier, sizemodifier);

                    curXInMaze = x;
                    curYInMaze = y;

                    this.currentStepsToCalcPercentage = cur;
                    this.totalStepsToCalcPercentage = tot;

                    //Thread.Sleep(200);
                });

                var directions = PathFinderDepthFirstSmartAndSmartMemory.GoFind(m.InnerMap, (x, y, pathFinderAction) =>
                {

                    int sleepTime = 25;

                    Thread.Sleep(sleepTime);

                    Brush colorToUse = Brushes.Pink;
                    g.FillRectangle(colorToUse, x * sizemodifier, y * sizemodifier, sizemodifier, sizemodifier);

                    Thread.Sleep(sleepTime);

                    switch (pathFinderAction)
                    {
                        case PathFinderAction.Step:
                            colorToUse = Brushes.Green;
                            break;
                        case PathFinderAction.Backtrack:
                            colorToUse = Brushes.Gray;
                            break;
                        case PathFinderAction.Junction:
                            colorToUse = Brushes.Blue;
                            break;
                        case PathFinderAction.RemovingJunction:
                            colorToUse = Brushes.Red;
                            break;
                        case PathFinderAction.RefoundJunction:
                            colorToUse = Brushes.Purple;
                            break;
                        default:
                            break;
                    }

                    g.FillRectangle(colorToUse, x * sizemodifier, y * sizemodifier, sizemodifier, sizemodifier);

                });

                //PrintQuatroList(path);

                var path = PathFinderDepthFirstSmartAndSmartMemory.DeterminePathFromDirections(directions, m.InnerMap);

                foreach (var pathnode in path)
                {
                    g.FillRectangle(Brushes.DarkBlue, pathnode.X * sizemodifier, pathnode.Y * sizemodifier, sizemodifier, sizemodifier);
                    Thread.Sleep(50);
                }
            });
        }
Beispiel #4
0
        public void GenerateMaze()
        {
            if (indexBuffer != null)
                indexBuffer.Dispose();
            if (vertexBuffer != null)
                vertexBuffer.Dispose();

            Algorithm alg;
            int randomnumber = curMazeWidth < 2048 ? random.Next(3) : random.Next(2);
            if (randomnumber == 0)
                alg = new AlgorithmBacktrack();
            else if (randomnumber == 1)
                alg = new AlgorithmDivision();
            else
                alg = new AlgorithmKruskal();

            lastAlgorithm = alg.GetType().Name;

            currentMaze = alg.Generate(curMazeWidth, curMazeHeight, InnerMapType.BitArreintjeFast, null);
            var walls = currentMaze.GenerateListOfMazeWalls();
            currentPath = PathFinderDepthFirst.GoFind(currentMaze.InnerMap, null);

            determiner = new LineOfSightDeterminer(currentMaze.InnerMap, currentPath);
            curChaseCameraPoint = null;

            VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[walls.Count * 8];
            int[] indices = new int[walls.Count * 12];

            int curVertice = 0;
            int curIndice = 0;

            foreach (var wall in walls)
            {
                //int factorHeight = 10;
                //int factorWidth = 10;

                WallModel model = new WallModel(wall);

                model.GoGenerateVertices(vertices, indices, ref curVertice, ref curIndice);

            }

            wallsCount = walls.Count;

            vertexBuffer = new VertexBuffer(GraphicsDevice, VertexPositionNormalTexture.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly);
            indexBuffer = new IndexBuffer(GraphicsDevice, IndexElementSize.ThirtyTwoBits, indices.Length, BufferUsage.WriteOnly);

            vertexBuffer.SetData(vertices);
            indexBuffer.SetData(indices);

            GeneratePath(currentPath);
        }