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); }
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); }
protected virtual void DrawMaze(Graphics graphics, IMazeView maze) { Pen sizePen = new Pen(drawingSettings.SideColor, 1); int cellWidth = drawingSettings.CellWidth; int cellHeight = drawingSettings.CellHeight; for (int row = 0; row < rowCount; row++) { for (int col = 0; col < colCount; col++) { if (maze.GetCell(row, col).HasFlag(MazeSide.Right)) { if (col < colCount - 1) { graphics.DrawLine(sizePen, new Point((col + 1) * cellWidth, (row) * cellHeight), new Point((col + 1) * cellWidth, (row + 1) * cellHeight)); } } if (maze.GetCell(row, col).HasFlag(MazeSide.Bottom)) { if (row < rowCount - 1) { graphics.DrawLine(sizePen, new Point((col) * cellWidth, (row + 1) * cellHeight), new Point((col + 1) * cellWidth, (row + 1) * cellHeight)); } } } } }
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); } } } }
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); }
// Start is called before the first frame update void Start() { try { int rowCount = 35; int colCount = 35; CreateRightWall(0, colCount - 1, null, true); for (int row = 1; row < rowCount; row++) { CreateLeftWall(row, 0, true); CreateRightWall(row, colCount - 1, null, true); } for (int col = 0; col < colCount; col++) { CreateTopWall(0, col, true); CreateBottomWall(rowCount - 1, col, null, true); } IMazeGenerator generator = new EllerModMazeGenerator(); IMazeView maze = generator.Generate(rowCount, colCount); for (int row = 0; row < rowCount; row++) { for (int col = 0; col < colCount; col++) { MazeSide cell = maze.GetCell(row, col); if (cell.HasFlag(MazeSide.Bottom)) { CreateBottomWall(row, col); } if (cell.HasFlag(MazeSide.Right)) { CreateRightWall(row, col); } } } player.transform.position = new Vector3((colCount - 1) * 5f, 2.5f, 2.5f); } catch (Exception ex) { Debug.Log(ex); } }
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); }
protected override void DrawMaze(Graphics graphics, IMazeView maze) { const int borderShift = 2; Pen sizePen = new Pen(drawingSettings.SideColor, 1); int cellWidth = drawingSettings.CellWidth; int cellHeight = drawingSettings.CellHeight; for (int row = 0; row < rowCount; row++) { for (int col = 0; col < colCount; col++) { if (maze.GetCell(row, col).HasFlag(MazeSide.Right)) { graphics.DrawLine(sizePen, new Point((col + 1) * cellWidth - borderShift, (row) * cellHeight), new Point((col + 1) * cellWidth - borderShift, (row + 1) * cellHeight)); } if (maze.GetCell(row, col).HasFlag(MazeSide.Left)) { graphics.DrawLine(sizePen, new Point((col) * cellWidth + borderShift, (row) * cellHeight), new Point((col) * cellWidth + borderShift, (row + 1) * cellHeight)); } if (maze.GetCell(row, col).HasFlag(MazeSide.Bottom)) { graphics.DrawLine(sizePen, new Point((col) * cellWidth, (row + 1) * cellHeight - borderShift), new Point((col + 1) * cellWidth, (row + 1) * cellHeight - borderShift)); } if (maze.GetCell(row, col).HasFlag(MazeSide.Top)) { graphics.DrawLine(sizePen, new Point((col) * cellWidth, (row) * cellHeight + borderShift), new Point((col + 1) * cellWidth, (row) * cellHeight + borderShift)); } } } }
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); } } } } }
private void DrawMaze(Graphics painter, IMazeView maze) { for (int row = 0; row < rowCount; row++) { for (int col = 0; col < colCount; col++) { MazeSide cell = maze.GetCell(row, col); int drawRow = row * 2 + 1; int drawCol = col * 2 + 1; if (cell.HasFlag(MazeSide.Right)) { DrawCell(painter, sideBrush, drawRow - 1, drawCol + 1); DrawCell(painter, sideBrush, drawRow, drawCol + 1); DrawCell(painter, sideBrush, drawRow + 1, drawCol + 1); } if (cell.HasFlag(MazeSide.Bottom)) { DrawCell(painter, sideBrush, drawRow + 1, drawCol - 1); DrawCell(painter, sideBrush, drawRow + 1, drawCol); DrawCell(painter, sideBrush, drawRow + 1, drawCol + 1); } if (cell.HasFlag(MazeSide.Left)) { DrawCell(painter, sideBrush, drawRow - 1, drawCol - 1); DrawCell(painter, sideBrush, drawRow, drawCol - 1); DrawCell(painter, sideBrush, drawRow + 1, drawCol - 1); } if (cell.HasFlag(MazeSide.Top)) { DrawCell(painter, sideBrush, drawRow - 1, drawCol - 1); DrawCell(painter, sideBrush, drawRow - 1, drawCol); DrawCell(painter, sideBrush, drawRow - 1, drawCol + 1); } } } }
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); }
void CreateMazeButtonClick(object sender, EventArgs e) { try { int generationAlgoComboboxIndex = mazeGenerationAlgoCombobox.SelectedIndex; if (generationAlgoComboboxIndex >= 0) { IMazeGenerator selectedGenerator = MazeGeneratorsFactory.Instance.Create( generatorsComboboxValues.ValueByIndex(generationAlgoComboboxIndex)); ClearClusters(); Stopwatch methodTime = Stopwatch.StartNew(); maze = selectedGenerator.Generate( mazeRowsTrackbar.Value, mazeColumnsTrackbar.Value); ShowMaze(); methodTime.Stop(); DebugConsole.Instance.Info( string.Format("Лабиринт ({0} x {1}) создан и нарисован за {2} мс", maze.RowCount, maze.ColCount, methodTime.ElapsedMilliseconds)); } else { MessageBox.Show("Не выбран алгоритм генерации лабиринта"); } } catch (MazeException ex) { DebugConsole.Instance.Error( string.Format("При создании лабиринта произошла ошибка: {0}", ex.ToString())); } }
private void DrawMaze(Graphics painter, IMazeView maze) { using (Pen bluePen = new Pen(Color.Blue, 1)) { for (int row = 0; row < maze.RowCount; row++) { for (int col = 0; col < maze.ColCount; col++) { Single BaseX = col * cellSize; Single BaseY = row * cellSize; MazeSide currentCell = maze.GetCell(row, col); if (currentCell.HasFlag(MazeSide.Top)) { painter.DrawLine(bluePen, BaseX, BaseY, BaseX + cellSize, BaseY); } if (currentCell.HasFlag(MazeSide.Bottom)) { painter.DrawLine(bluePen, BaseX, BaseY + cellSize, BaseX + cellSize, BaseY + cellSize); } if (currentCell.HasFlag(MazeSide.Right)) { painter.DrawLine(bluePen, BaseX + cellSize, BaseY, BaseX + cellSize, BaseY + cellSize); } if (currentCell.HasFlag(MazeSide.Left)) { painter.DrawLine(bluePen, BaseX, BaseY, BaseX, BaseY + cellSize); } } } } }
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); }
public virtual Bitmap Draw(IMazeView maze, MazeClusters clusters = null) { return(mazeDrawer.Draw(maze, clusters)); }
public Bitmap Draw(IMazeView maze, MazeClusters clusters = null) { return(new Bitmap(1, 1)); }
public MazeClusters(IMazeView maze) : this(maze.RowCount, maze.ColCount) { }