public void convertAdjToMatrix() { matrix = new BitArray[adj.Count]; for (int i = 0; i < matrix.Length; i++) { matrix[i] = new BitArray(columns * rows); } int k = 0, l = 0; for (int i = 0; i < adj.Count(); i++) { for (int j = 0; j < adj.Count(); j++) { if (l < adj[k].Count()) { if (i == k && j == adj[k][l] - 1) { matrix[i][j] = true; l++; } else { matrix[i][j] = false; } } else { matrix[i][j] = false; } } k++; l = 0; } recalculateNodes(columns, rows); grid = new NodeGrid(columns, rows, nodes); grid.setWalls(matrix); matrixUpToDate = true; }
private void NewFile(object sender, RoutedEventArgs e) { if (simInProgress) { MessageBox.Show("Nie można wykonać operacji w trakcie symulacji.", "Trwa symulacja", MessageBoxButton.OK, MessageBoxImage.Warning); return; } NewLabyrinth dlg = new NewLabyrinth(); dlg.Owner = this; if (dlg.ShowDialog() == true) { columns = dlg.columns; rows = dlg.rows; bool random = dlg.random; if ((columns <= 0 || rows <= 0) || (columns <= 1 && rows <= 1)) { MessageBox.Show("Labirynt jest zbyt mały.", "Błąd dodawania", MessageBoxButton.OK, MessageBoxImage.Error); return; } if ((columns * rows > sizeLimit && sizeLimit > 0) || rows > 9999 || columns > 9999) { MessageBox.Show("Labirynt jest zbyt duży.", "Błąd dodawania", MessageBoxButton.OK, MessageBoxImage.Error); return; } int prog = 0; double progmax = columns * rows; startNode = 1; endNode = columns * rows; nodes = new List <List <Node> >(); recalculateNodes(columns, rows); grid = new NodeGrid(columns, rows, nodes); matrix = new BitArray[columns * rows]; for (int i = 0; i < matrix.Length; i++) { matrix[i] = new BitArray(columns * rows); } BarStatus.Value = 0; if (random) { BarKroki.Text = "1/3"; } else { BarKroki.Text = "1/2"; } BarOperacja.Text = "Generowanie macierzy"; PopupBar.IsOpen = true; for (int i = 0; i < rows * columns; i++) { for (int j = 0; j < rows * columns; j++) { if (grid.areNeighbours(i + 1, j + 1)) { matrix[i][j] = true; } else { matrix[i][j] = false; } } prog = (int)(((i + 1) / progmax) * 100); BarStatus.Dispatcher.Invoke(() => BarStatus.Value = prog, DispatcherPriority.Background); } PopupBar.IsOpen = false; if (random) { BarStatus.Value = 0; BarKroki.Text = "2/3"; BarOperacja.Text = "Losowanie ścian"; PopupBar.IsOpen = true; makeRandomMatrix(); PopupBar.IsOpen = false; BarKroki.Text = "3/3"; } else { BarKroki.Text = "2/2"; } grid.setWalls(matrix); convertMatrixToAdj(); selectedNode = null; noData = false; matrixUpToDate = false; simInProgress = false; lblColumns.Content = columns.ToString(); lblRows.Content = rows.ToString(); canvas1.Width = columns * 20; canvas1.Height = rows * 20; drawLabyrinth(); } }