public override Bitmap Draw(IMazeView maze, MazeClusters clusters = null)
        {
            Bitmap mazeImage = base.Draw(maze, clusters);

            switch (rotateMaze)
            {
            case MazeRotateEnum.Rotate90:
                mazeImage.RotateFlip(RotateFlipType.Rotate90FlipNone);
                break;

            case MazeRotateEnum.Rotate180:
                mazeImage.RotateFlip(RotateFlipType.Rotate180FlipNone);
                break;

            case MazeRotateEnum.Rotate270:
                mazeImage.RotateFlip(RotateFlipType.Rotate270FlipNone);
                break;

            case MazeRotateEnum.Rotate0:
                break;

            default:
                throw new MazeException("Неопределенный уровень поворота");
            }

            return(mazeImage);
        }
Пример #2
0
        public MazeClusters Cluster(IMazeView maze)
        {
            processedMaze = maze;
            rowCount      = maze.RowCount;
            colCount      = maze.ColCount;
            clusters      = new MazeClusters(processedMaze);

            threadException = null;

            // Создаем поток с единственной целью - увеличение стека.
            // Это нужно чтобы простой рекурсивный алгоритм мог выполниться для
            // достаточно больших лабиринтов.
            // Текущий поток ждет завершения выполнения созданного потока,
            // не выполняется одновременно с созданным потоком.
            // Одновременного доступа к переменным из разных потоков тут не происходит.
            Thread clusterThread = new Thread(FindClusters, recursionStackSize);

            clusterThread.Start();
            Thread.Yield();
            clusterThread.Join();

            if (threadException != null)
            {
                throw new MazeException("Ошибка при рекурсивном поиске областей лабиринта",
                                        threadException);
            }

            return(clusters);
        }
Пример #3
0
        private void DrawClusters(Graphics painter, IMazeView maze, MazeClusters clusters)
        {
            int clustersNumber = clusters.Count();

            Brush[] brushes = new Brush[clustersNumber];
            for (int i = 0; i < brushes.Length; i++)
            {
                brushes[i] = new SolidBrush(Palette.GetColor(i + 1));
            }

            for (int row = 0; row < maze.RowCount; row++)
            {
                for (int col = 0; col < maze.ColCount; col++)
                {
                    int BaseX = col * cellSize;
                    int BaseY = row * cellSize;

                    if (!clusters.IsNonclustered(row, col))
                    {
                        int circleShift = cellSize / 2 - circleSize / 2;
                        int brushIndex  = clusters.GetClusterIndex(row, col) - 1;
                        painter.FillEllipse(brushes[brushIndex],
                                            BaseX + circleShift,
                                            BaseY + circleShift,
                                            circleSize, circleSize);
                    }
                }
            }
        }
Пример #4
0
        protected virtual void DrawClusters(Graphics graphics, MazeClusters clusters)
        {
            int clustersNumber = clusters.Count();

            Brush[] brushes = new Brush[clustersNumber];
            for (int i = 0; i < brushes.Length; i++)
            {
                brushes[i] = new SolidBrush(Palette.GetColor(i + 1));
            }

            int cellWidth  = drawingSettings.CellWidth;
            int cellHeight = drawingSettings.CellHeight;

            for (int row = 0; row < rowCount; row++)
            {
                for (int col = 0; col < colCount; col++)
                {
                    int index = clusters.GetClusterIndex(row, col);
                    if (index > 0)
                    {
                        Rectangle cellRect = new Rectangle(col * cellWidth, row * cellHeight,
                                                           cellWidth, cellHeight);

                        graphics.FillRectangle(brushes[index - 1], cellRect);
                    }
                }
            }
        }
Пример #5
0
        public Bitmap Draw(IMazeView maze, MazeClusters clusters = null)
        {
            CreateBrushes();

            rowCount = maze.RowCount;
            colCount = maze.ColCount;

            int width = drawingSettings.CellWidth * (colCount + (colCount - 1)) +
                        (2 * drawingSettings.CellWidth);

            int height = drawingSettings.CellHeight * (rowCount + (rowCount - 1)) +
                         (2 * drawingSettings.CellHeight);

            Bitmap bitmap = new Bitmap(width, height);

            using (Graphics gr = Graphics.FromImage(bitmap))
            {
                DrawBackground(gr);

                if (clusters != null)
                {
                    DrawClusters(gr, maze, clusters);
                }

                DrawMaze(gr, maze);

                DrawBorders(gr);
            }

            return(bitmap);
        }
Пример #6
0
        private void CreateClusterBrushes(MazeClusters clusters)
        {
            int count = clusters.Count();

            clustersBrushes = new Brush[count];
            for (int i = 0; i < count; i++)
            {
                clustersBrushes[i] = new SolidBrush(Palette.GetColor(i + 1));
            }
        }
Пример #7
0
        public Bitmap Draw(IMazeView maze, MazeClusters clusters = null)
        {
            Bitmap imageBitmap = new Bitmap(maze.ColCount * cellSize + 1, maze.RowCount * cellSize + 1);

            using (Graphics painter = Graphics.FromImage(imageBitmap))
            {
                painter.Clear(backgroundColor);

                DrawMaze(painter, maze);

                if (clusters != null)
                {
                    DrawClusters(painter, maze, clusters);
                }
            }

            return(imageBitmap);
        }
Пример #8
0
        private void DrawClusters(Graphics painter, IMazeView maze, MazeClusters clusters)
        {
            CreateClusterBrushes(clusters);
            for (int row = 0; row < rowCount; row++)
            {
                for (int col = 0; col < colCount; col++)
                {
                    int index = clusters.GetClusterIndex(row, col);

                    if (index != 0)
                    {
                        int drawRow = row * 2 + 1;
                        int drawCol = col * 2 + 1;

                        DrawCell(painter, clustersBrushes[index - 1],
                                 drawRow, drawCol);

                        MazeSide cell = maze.GetCell(row, col);

                        if (!cell.HasFlag(MazeSide.Bottom))
                        {
                            DrawCell(painter, clustersBrushes[index - 1],
                                     drawRow + 1, drawCol);
                        }

                        if (!cell.HasFlag(MazeSide.Right))
                        {
                            DrawCell(painter, clustersBrushes[index - 1],
                                     drawRow, drawCol + 1);
                        }

                        if (!cell.HasFlag(MazeSide.Bottom) && !cell.HasFlag(MazeSide.Right))
                        {
                            DrawCell(painter, clustersBrushes[index - 1],
                                     drawRow + 1, drawCol + 1);
                        }
                    }
                }
            }
        }
Пример #9
0
        public MazeClusters Cluster(IMazeView maze)
        {
            this.maze = maze;
            clusters  = new MazeClusters(maze);
            int index = 0;

            while (clusters.GetNextNonClusteredCell(out int row, out int col))
            {
                List <MazePoint> foundPoints = Walk(new MazePoint(row, col), ++index);
                while (foundPoints.Count > 0)
                {
                    List <MazePoint> nextPoints = new List <MazePoint>(foundPoints);
                    foundPoints.Clear();
                    foreach (MazePoint point in nextPoints)
                    {
                        foundPoints.AddRange(Walk(point, index));
                    }
                }
                ;
            }
            return(clusters);
        }
Пример #10
0
        public Bitmap Draw(IMazeView maze, MazeClusters clusters = null)
        {
            rowCount = maze.RowCount;
            colCount = maze.ColCount;

            Bitmap imageBitmap = new Bitmap(colCount * drawingSettings.CellWidth + 1,
                                            rowCount * drawingSettings.CellHeight + 1);

            using (Graphics painter = Graphics.FromImage(imageBitmap))
            {
                painter.Clear(drawingSettings.BackgroundColor);

                if (clusters != null)
                {
                    DrawClusters(painter, clusters);
                }

                DrawMaze(painter, maze);
                DrawBorder(painter);
            }

            return(imageBitmap);
        }
Пример #11
0
 public Bitmap Draw(IMazeView maze, MazeClusters clusters = null)
 {
     return(new Bitmap(1, 1));
 }
Пример #12
0
 public virtual Bitmap Draw(IMazeView maze, MazeClusters clusters = null)
 {
     return(mazeDrawer.Draw(maze, clusters));
 }