Пример #1
0
        public MazeDrawer(Graphics graphics, Maze maze, int pathSize, int wallSize)
        {
            this.Graphics = graphics;
            this.Maze = maze;

            this.PathSize = pathSize;
            this.WallSize = wallSize;

            this.WallColor = Color.Black;
        }
Пример #2
0
        private void buttonNew_Click(object sender, EventArgs e)
        {
            timer.Stop();
            MazeDrawer.CalculateSize(this.panel1.CreateGraphics(), (int)numericUpDownPathSize.Value, (int)numericUpDownWallSize.Value, out this.mazeWidth, out this.mazeHeight);
            this.Maze = new Maze(this.mazeHeight, this.mazeWidth);
            this.MazeDrawer = new MazeDrawer(this.panel1.CreateGraphics(), this.Maze, (int)numericUpDownPathSize.Value, (int)numericUpDownWallSize.Value);
            this.MazeDrawer.BuildColor = this.buttonBuildColor.BackColor;
            this.MazeDrawer.BuildBackColor = this.buttonBuildBacktrackColor.BackColor;
            this.MazeDrawer.ExploreColor = Color.Red;
            this.MazeDrawer.ExploreBackColor = Color.Yellow;
            this.MazeDrawer.Draw(false, false);
            this.CurrentCell = null;

            this.panel1.BackColor = this.MazeDrawer.WallColor;
            this.labelSize.Text = string.Format("{0} x {1} maze", this.mazeHeight, this.mazeWidth);
            this.labelCells.Text = string.Format("{0} steps", this.mazeHeight * this.mazeWidth);
            this.buildCells = 0;
            this.backtrakBuildCells = 0;
            this.progressBarBuildCells.Maximum = this.mazeHeight * this.mazeWidth;
            this.progressBarBuildBacktrack.Maximum = this.buildCells;
            this.labelBuiltCells.Text = string.Format("{0} / {1} (0% / {2})", this.buildCells, this.mazeWidth * this.mazeHeight, this.buildCells - this.mazeWidth * this.mazeHeight);
            this.labelBacktrackBuiltCells.Text = string.Format("{0} / {1} (0% / {2})", this.backtrakBuildCells, this.buildCells, this.backtrakBuildCells - this.buildCells);
        }
Пример #3
0
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics graphicsObj = this.CreateGraphics();

            int WallWeight     = 26;
            int SemiWallWeight = 26 / 2;

            Pen myPen    = new Pen(System.Drawing.Color.Red, 2);
            Pen pathPen  = new Pen(System.Drawing.Color.Blue, 4);
            Pen startPen = new Pen(System.Drawing.Color.Yellow, 4);
            Pen endPen   = new Pen(System.Drawing.Color.Green, 4);

            int  size = 15;
            Maze laby = new Maze(size);

            Cell[,] CellTable = laby.Table;

            // for( int x = 0, i = )

            foreach (Cell cell in CellTable)
            {
                Corner TopLeftCorner;
                Corner BottomLeftCorner;
                Corner TopRightCorner;
                Corner BottomRightCorner;

                Console.WriteLine($"Cell {cell.x} {cell.y} : {cell}");

                TopLeftCorner     = new Corner((cell.x - 1) * WallWeight, (cell.y - 1) * WallWeight);
                BottomLeftCorner  = new Corner((cell.x - 1) * WallWeight, cell.y * WallWeight);
                TopRightCorner    = new Corner(cell.x * WallWeight, (cell.y - 1) * WallWeight);
                BottomRightCorner = new Corner(cell.x * WallWeight, cell.y * WallWeight);

                if (cell.isInPath)
                {
                    graphicsObj.DrawRectangle(pathPen, TopLeftCorner.X + 10, TopLeftCorner.Y + 10, 5, 5);
                }

                if (cell.top)
                {
                    graphicsObj.DrawLine(myPen, TopLeftCorner.X, TopLeftCorner.Y, TopRightCorner.X, TopRightCorner.Y);
                }

                if (cell.left)
                {
                    graphicsObj.DrawLine(myPen, TopLeftCorner.X, TopLeftCorner.Y, BottomLeftCorner.X, BottomLeftCorner.Y);
                }

                if (cell.right)
                {
                    graphicsObj.DrawLine(myPen, BottomRightCorner.X, BottomRightCorner.Y, TopRightCorner.X, TopRightCorner.Y);
                }

                if (cell.bottom)
                {
                    graphicsObj.DrawLine(myPen, BottomRightCorner.X, BottomRightCorner.Y, BottomLeftCorner.X, BottomLeftCorner.Y);
                }
            }


            graphicsObj.DrawRectangle(startPen, (laby.startCell.x - 1) * WallWeight + 50, (laby.startCell.y - 1) * WallWeight + 50, 5, 5);
            graphicsObj.DrawRectangle(endPen, (laby.endCell.x - 1) * WallWeight + 50, (laby.endCell.y - 1) * WallWeight + 50, 5, 5);
        }