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); } } } }
private bool ClusterCell(int row, int col, int index) { bool processed = false; if (maze.IsCellExists(row, col)) { if (clusters.IsNonclustered(row, col)) { clusters.SetClusterIndex(row, col, index); processed = true; } } return(processed); }
void WalkCluster(int row, int col, int cluster) { if (processedMaze.IsCellExists(row, col)) { if (clusters.IsNonclustered(row, col)) { MazeSide currentCell = processedMaze.GetCell(row, col); clusters.SetClusterIndex(row, col, cluster); if (processedMaze.IsCellExists(row - 1, col)) { if (!currentCell.HasFlag(MazeSide.Top)) { WalkCluster(row - 1, col, cluster); } } if (processedMaze.IsCellExists(row + 1, col)) { if (!currentCell.HasFlag(MazeSide.Bottom)) { WalkCluster(row + 1, col, cluster); } } if (processedMaze.IsCellExists(row, col - 1)) { if (!currentCell.HasFlag(MazeSide.Left)) { WalkCluster(row, col - 1, cluster); } } if (processedMaze.IsCellExists(row, col + 1)) { if (!currentCell.HasFlag(MazeSide.Right)) { WalkCluster(row, col + 1, cluster); } } } } }