private void DrawWay(PaintEventArgs e) { Rcv r1 = new Rcv(lg.w), r2 = new Rcv(lg.w); r1.SetRC(selectedCell.GetR(), selectedCell.GetC()); int start = r1.Val; r2.SetRC(finCell.GetR(), finCell.GetC()); int wayTo = r2.Val; if (wayTo > -1 && start > -1 && dr.dist[wayTo] != int.MaxValue) { int now = wayTo; int next; while (now != start) { next = dr.parent[now]; //Pen p = new Pen(Color.Red, 4); r1.Val = now; r2.Val = next; e.Graphics.DrawLine(WayPen, r1.Col * cellWidth + cellWidth / 2, r1.Row * cellWidth + cellWidth / 2, r2.Col * cellWidth + cellWidth / 2, r2.Row * cellWidth + cellWidth / 2); now = next; } } }
private void panel1_MouseClick(object sender, MouseEventArgs e) { if (cellWidth == 0) { return; } if (selectedCell == null) { selectedCell = new CellData(e.Y / cellWidth, e.X / cellWidth); Dijkstra t = new Dijkstra(mas); rcv.SetRC(selectedCell.GetR(), selectedCell.GetC()); dr = t.GetDijkstraRez(rcv.Val); } else { finCell = new CellData(e.Y / cellWidth, e.X / cellWidth); } panel1.Refresh(); this.Text = selectedCell.ToString(); }
public static int[][] Converct(LabGen lg) { int[][] mass; int n = lg.h * lg.w; Rcv rcv = new Rcv(lg.w); Rcv rcv2 = new Rcv(lg.w); mass = new int[n][]; for (int i = 0; i < n; i++) { mass[i] = new int[n]; for (int j = 0; j < n; j++) { if (i != j) { mass[i][j] = int.MaxValue; } else { mass[i][j] = 0; // каждый связан с самим собой } } } for (int i = 0; i < n; i++) { rcv.Val = i; for (int j = 0; j < n; j++) { if (EmumMedods.HasFlag(lg.map[rcv.Row][rcv.Col], CellOptions.EXIT_NORTH) && LabGen.InMazeBorders(rcv.Row - 1, rcv.Col, lg.h, lg.w)) { rcv2.SetRC(rcv.Row - 1, rcv.Col); mass[i][rcv2.Val] = 1; } if (EmumMedods.HasFlag(lg.map[rcv.Row][rcv.Col], CellOptions.EXIT_SOUTH) && LabGen.InMazeBorders(rcv.Row + 1, rcv.Col, lg.h, lg.w)) { rcv2.SetRC(rcv.Row + 1, rcv.Col); mass[i][rcv2.Val] = 1; } if (EmumMedods.HasFlag(lg.map[rcv.Row][rcv.Col], CellOptions.EXIT_EAST) && LabGen.InMazeBorders(rcv.Row, rcv.Col + 1, lg.h, lg.w)) { rcv2.SetRC(rcv.Row, rcv.Col + 1); mass[i][rcv2.Val] = 1; } if (EmumMedods.HasFlag(lg.map[rcv.Row][rcv.Col], CellOptions.EXIT_WEST) && LabGen.InMazeBorders(rcv.Row, rcv.Col - 1, lg.h, lg.w)) { rcv2.SetRC(rcv.Row, rcv.Col - 1); mass[i][rcv2.Val] = 1; } } } return(mass); }