private void btnDrawPath_Click(object sender, EventArgs e) { if (_startPoint == null || _endPoint == null || pbMask.Image != null || _mode != MazeStyle.Square) { return; } if (cbAlgorithm.SelectedItem != null) { var colorGrid = new ColoredPathGrid(MazeSize, MazeSize); if (!CreateSelectedMaze(colorGrid)) { return; } var start = colorGrid[_startPoint.Value.Y, _startPoint.Value.X]; var end = colorGrid[_endPoint.Value.Y, _endPoint.Value.X]; colorGrid.Distances = start.Distances; colorGrid.Path = start.Distances.PathTo(end); tsslPathLength.Text = "Path Length: " + colorGrid.PathLength; colorGrid.BackColor = pbColor.BackColor; pbMaze.Image = colorGrid.ToImg(GridSize, (float)nudInset.Value); } }
private void btnLongestPath_Click(object sender, EventArgs e) { if (cbAlgorithm.SelectedItem != null) { IPathGrid colorGrid = new ColoredPathGrid(MazeSize, MazeSize); if (pbMask.Image != null) { var mask = Mask.FromBitmap((Bitmap)pbMask.Image); colorGrid = new MaskedColoredPathGrid(mask); } else if (_mode == MazeStyle.Polar) { colorGrid = new ColoredPathPolarGrid(MazeSize); } else if (_mode == MazeStyle.Hex) { colorGrid = new ColoredPathHexGrid(MazeSize, MazeSize * 3 / 2); } else if (_mode == MazeStyle.Triangle) { colorGrid = new ColoredPathTriangleGrid(MazeSize, MazeSize * 2); } else if (_mode == MazeStyle.Upsilon) { colorGrid = new ColoredPathUpsilonGrid(MazeSize, MazeSize); } if (!CreateSelectedMaze(colorGrid)) { return; } var start = colorGrid.RandomCell(); var distances = start.Distances; var(newStart, distance) = distances.Max; start = newStart; distances = start.Distances; var(end, distance2) = distances.Max; _startPoint = start.Location; tsslStartPoint.Text = "Start: " + _startPoint; _endPoint = end.Location; tsslEndPoint.Text = "End: " + _endPoint; colorGrid.Distances = start.Distances; colorGrid.Path = start.Distances.PathTo(end); tsslPathLength.Text = "Path Length: " + colorGrid.PathLength; colorGrid.BackColor = pbColor.BackColor; pbMaze.Image = colorGrid.ToImg(GridSize, (float)nudInset.Value); } }