private void NextExit_OnClick(object sender, RoutedEventArgs e) { if (LongestPathToggle.IsChecked == true) { MazeSolverLongestPath.RefreshMazeToBeShowed(); } else if (ShortestPathToggle.IsChecked == true) { MazeSolverShortestPath.RefreshMazeToBeShowed(); } ReinitializeMaze(); NextExit.Visibility = Visibility.Collapsed; SolveButton.IsEnabled = true; }
private void SolveButton_Click(object sender, RoutedEventArgs e) { MediaPlayer player = new MediaPlayer(); #region LongestPath if (LongestPathToggle.IsChecked == true) { DisableMazeControl(); if (_firstPass) { MazeSolverLongestPath.CreateMazeArray(CreateMazeArrayFromMazeCanvas(MazeCanvas.Children)); if (MazeSolverLongestPath.MouseChecker == false || MazeSolverLongestPath.ExitChecker == false) { EnableMazeControl(); return; } var solvedPath = MazeSolverLongestPath.GetLongestPath(MazeSolverLongestPath.MazeArray); if (solvedPath != null) { MazeSolverLongestPath.GetPathForVisualization(solvedPath); var solveTimer = new DispatcherTimer(); var counter = 0; solveTimer.Tick += delegate { counter++; MazeSolverLongestPath.StepMazeSolution(solvedPath); RevertSolvedMazeToCanvas(MazeSolverLongestPath.MazeToBeShowed); if (counter == MazeSolverLongestPath.CellsInMazePath) { solveTimer.Stop(); if (MazeSolverLongestPath.ExitCells.Count > 0) { BlinkExit(MazeSolverLongestPath.ExitCell, MazeSolverLongestPath.MazeToBeShowed, MazeSolverLongestPath.ExitCells.Count); MessageBox.Show("An exit has been found!", "Notification", MessageBoxButton.OK, MessageBoxImage.Information); SolveButton.IsEnabled = false; _firstPass = false; } else { player.Stop(); MediaPlayer soundBite = new MediaPlayer(); soundBite.Open(new Uri(@"..\..\SoundBit\Sound.mp3", UriKind.Relative)); soundBite.Play(); BlinkExit(MazeSolverLongestPath.ExitCell, MazeSolverLongestPath.MazeToBeShowed, 0); MessageBox.Show("All exits found!", "Notification", MessageBoxButton.OK, MessageBoxImage.Information); SolveButton.Visibility = Visibility.Collapsed; ResetButton.Visibility = Visibility.Visible; SolveButton.IsEnabled = false; _firstPass = true; } } }; if (MazeSolverLongestPath.ExitCells.Count == 0) { player.Open(new Uri(@"..\..\SoundBit\Sound 3.wav", UriKind.Relative)); player.Play(); } solveTimer.Interval = TimeSpan.FromMilliseconds(100); solveTimer.Start(); SolveButton.IsEnabled = false; } else { MazeSolverLongestPath.GetPathForVisualization(solvedPath); RevertSolvedMazeToCanvas(MazeSolverLongestPath.MazeToBeShowed); if (MazeSolverLongestPath.ExitCells.Count > 0) { MediaPlayer soundBite = new MediaPlayer(); soundBite.Open(new Uri(@"..\..\SoundBit\Sound 4.wav", UriKind.Relative)); soundBite.Play(); BlinkExit(MazeSolverLongestPath.ExitCell, MazeSolverLongestPath.MazeToBeShowed, MazeSolverLongestPath.ExitCells.Count); MessageBox.Show($"There is no path to {MazeSolverLongestPath.ExitCell.Y - 1},{MazeSolverLongestPath.ExitCell.X - 1}.", "Notification", MessageBoxButton.OK, MessageBoxImage.Information); SolveButton.IsEnabled = false; _firstPass = false; } else { MediaPlayer soundBite = new MediaPlayer(); soundBite.Open(new Uri(@"..\..\SoundBit\Sound 2.mp3", UriKind.Relative)); soundBite.Play(); BlinkExit(MazeSolverLongestPath.ExitCell, MazeSolverLongestPath.MazeToBeShowed, 0); MessageBox.Show("Last exit unreachable.", "Notification", MessageBoxButton.OK, MessageBoxImage.Information); SolveButton.Visibility = Visibility.Collapsed; ResetButton.Visibility = Visibility.Visible; SolveButton.IsEnabled = false; _firstPass = true; } } } else { var solvedPath = MazeSolverLongestPath.GetLongestPath(MazeSolverLongestPath.MazeArray); if (solvedPath != null) { MazeSolverLongestPath.GetPathForVisualization(solvedPath); var solveTimer = new DispatcherTimer(); var counter = 0; solveTimer.Tick += delegate { counter++; MazeSolverLongestPath.StepMazeSolution(solvedPath); RevertSolvedMazeToCanvas(MazeSolverLongestPath.MazeToBeShowed); if (counter == MazeSolverLongestPath.CellsInMazePath) { solveTimer.Stop(); if (MazeSolverLongestPath.ExitCells.Count > 0) { BlinkExit(MazeSolverLongestPath.ExitCell, MazeSolverLongestPath.MazeToBeShowed, MazeSolverLongestPath.ExitCells.Count); MessageBox.Show("An exit has been found!", "Notification", MessageBoxButton.OK, MessageBoxImage.Information); _firstPass = false; } else { player.Stop(); MediaPlayer soundBite = new MediaPlayer(); soundBite.Open(new Uri(@"..\..\SoundBit\Sound.mp3", UriKind.Relative)); soundBite.Play(); BlinkExit(MazeSolverLongestPath.ExitCell, MazeSolverLongestPath.MazeToBeShowed, 0); MessageBox.Show("All exits found!", "Notification", MessageBoxButton.OK, MessageBoxImage.Information); SolveButton.Visibility = Visibility.Collapsed; ResetButton.Visibility = Visibility.Visible; SolveButton.IsEnabled = true; _firstPass = true; } } }; if (MazeSolverLongestPath.ExitCells.Count == 0) { player.Open(new Uri(@"..\..\SoundBit\Sound 3.wav", UriKind.Relative)); player.Play(); } solveTimer.Interval = TimeSpan.FromMilliseconds(100); solveTimer.Start(); SolveButton.IsEnabled = false; } else { MazeSolverLongestPath.GetPathForVisualization(solvedPath); RevertSolvedMazeToCanvas(MazeSolverLongestPath.MazeToBeShowed); if (MazeSolverLongestPath.ExitCells.Count > 0) { MediaPlayer soundBite = new MediaPlayer(); soundBite.Open(new Uri(@"..\..\SoundBit\Sound 4.wav", UriKind.Relative)); soundBite.Play(); BlinkExit(MazeSolverLongestPath.ExitCell, MazeSolverLongestPath.MazeToBeShowed, MazeSolverLongestPath.ExitCells.Count); MessageBox.Show($"There is no path to {MazeSolverLongestPath.ExitCell.Y - 1},{MazeSolverLongestPath.ExitCell.X - 1}.", "Notification", MessageBoxButton.OK, MessageBoxImage.Information); SolveButton.IsEnabled = false; _firstPass = false; } else { MediaPlayer soundBite = new MediaPlayer(); soundBite.Open(new Uri(@"..\..\SoundBit\Sound 2.mp3", UriKind.Relative)); soundBite.Play(); BlinkExit(MazeSolverLongestPath.ExitCell, MazeSolverLongestPath.MazeToBeShowed, 0); MessageBox.Show("Last exit unreachable.", "Notification", MessageBoxButton.OK, MessageBoxImage.Information); SolveButton.Visibility = Visibility.Collapsed; ResetButton.Visibility = Visibility.Visible; SolveButton.IsEnabled = false; _firstPass = true; } } } } #endregion #region ShortestPath else if (ShortestPathToggle.IsChecked == true) { DisableMazeControl(); if (_firstPass) { MazeSolverShortestPath.CreateMazeArray(CreateMazeArrayFromMazeCanvas(MazeCanvas.Children)); if (MazeSolverShortestPath.MouseChecker == false || MazeSolverShortestPath.ExitChecker == false) { EnableMazeControl(); return; } var solvedPath = MazeSolverShortestPath.GetShortestPath(MazeSolverShortestPath.MazeArray); if (solvedPath != null) { MazeSolverShortestPath.GetPathForVisualization(solvedPath); var solveTimer = new DispatcherTimer(); var counter = 0; solveTimer.Tick += delegate { counter++; MazeSolverShortestPath.StepMazeSolution(solvedPath); RevertSolvedMazeToCanvas(MazeSolverShortestPath.MazeToBeShowed); if (counter == MazeSolverShortestPath.CellsInMazePath) { solveTimer.Stop(); if (MazeSolverShortestPath.ExitCells.Count > 0) { BlinkExit(MazeSolverShortestPath.ExitCell, MazeSolverShortestPath.MazeToBeShowed, MazeSolverShortestPath.ExitCells.Count); MessageBox.Show("An exit has been found!", "Notification", MessageBoxButton.OK, MessageBoxImage.Information); SolveButton.IsEnabled = false; _firstPass = false; } else { player.Stop(); MediaPlayer soundBite = new MediaPlayer(); soundBite.Open(new Uri(@"..\..\SoundBit\Sound.mp3", UriKind.Relative)); soundBite.Play(); BlinkExit(MazeSolverShortestPath.ExitCell, MazeSolverShortestPath.MazeToBeShowed, 0); MessageBox.Show("All exits found!", "Notification", MessageBoxButton.OK, MessageBoxImage.Information); SolveButton.Visibility = Visibility.Collapsed; ResetButton.Visibility = Visibility.Visible; SolveButton.IsEnabled = false; _firstPass = true; } } }; if (MazeSolverShortestPath.ExitCells.Count == 0) { player.Open(new Uri(@"..\..\SoundBit\Sound 3.wav", UriKind.Relative)); player.Play(); } solveTimer.Interval = TimeSpan.FromMilliseconds(100); solveTimer.Start(); SolveButton.IsEnabled = false; } else { MazeSolverShortestPath.GetPathForVisualization(solvedPath); RevertSolvedMazeToCanvas(MazeSolverShortestPath.MazeToBeShowed); if (MazeSolverShortestPath.ExitCells.Count > 0) { MediaPlayer soundBite = new MediaPlayer(); soundBite.Open(new Uri(@"..\..\SoundBit\Sound 4.wav", UriKind.Relative)); soundBite.Play(); BlinkExit(MazeSolverShortestPath.ExitCell, MazeSolverShortestPath.MazeToBeShowed, MazeSolverShortestPath.ExitCells.Count); MessageBox.Show($"There is no path to {MazeSolverShortestPath.ExitCell.Y - 1},{MazeSolverShortestPath.ExitCell.X - 1}.", "Notification", MessageBoxButton.OK, MessageBoxImage.Information); SolveButton.IsEnabled = false; _firstPass = false; } else { MediaPlayer soundBite = new MediaPlayer(); soundBite.Open(new Uri(@"..\..\SoundBit\Sound 2.mp3", UriKind.Relative)); soundBite.Play(); BlinkExit(MazeSolverShortestPath.ExitCell, MazeSolverShortestPath.MazeToBeShowed, 0); MessageBox.Show("Last exit unreachable.", "Notification", MessageBoxButton.OK, MessageBoxImage.Information); SolveButton.Visibility = Visibility.Collapsed; ResetButton.Visibility = Visibility.Visible; SolveButton.IsEnabled = false; _firstPass = true; } } } else { var solvedPath = MazeSolverShortestPath.GetShortestPath(MazeSolverShortestPath.MazeArray); if (solvedPath != null) { MazeSolverShortestPath.GetPathForVisualization(solvedPath); var solveTimer = new DispatcherTimer(); var counter = 0; solveTimer.Tick += delegate { counter++; MazeSolverShortestPath.StepMazeSolution(solvedPath); RevertSolvedMazeToCanvas(MazeSolverShortestPath.MazeToBeShowed); if (counter == MazeSolverShortestPath.CellsInMazePath) { solveTimer.Stop(); if (MazeSolverShortestPath.ExitCells.Count > 0) { BlinkExit(MazeSolverShortestPath.ExitCell, MazeSolverShortestPath.MazeToBeShowed, MazeSolverShortestPath.ExitCells.Count); MessageBox.Show("An exit has been found!", "Notification", MessageBoxButton.OK, MessageBoxImage.Information); SolveButton.IsEnabled = false; _firstPass = false; } else { player.Stop(); MediaPlayer soundBite = new MediaPlayer(); soundBite.Open(new Uri(@"..\..\SoundBit\Sound.mp3", UriKind.Relative)); soundBite.Play(); BlinkExit(MazeSolverShortestPath.ExitCell, MazeSolverShortestPath.MazeToBeShowed, 0); MessageBox.Show("All exits found!", "Notification", MessageBoxButton.OK, MessageBoxImage.Information); SolveButton.Visibility = Visibility.Collapsed; ResetButton.Visibility = Visibility.Visible; SolveButton.IsEnabled = false; _firstPass = true; } } }; if (MazeSolverShortestPath.ExitCells.Count == 0) { player.Open(new Uri(@"..\..\SoundBit\Sound 3.wav", UriKind.Relative)); player.Play(); } solveTimer.Interval = TimeSpan.FromMilliseconds(100); solveTimer.Start(); SolveButton.IsEnabled = false; } else { MazeSolverShortestPath.GetPathForVisualization(solvedPath); RevertSolvedMazeToCanvas(MazeSolverShortestPath.MazeToBeShowed); if (MazeSolverShortestPath.ExitCells.Count > 0) { MediaPlayer soundBite = new MediaPlayer(); soundBite.Open(new Uri(@"..\..\SoundBit\Sound 4.wav", UriKind.Relative)); soundBite.Play(); BlinkExit(MazeSolverShortestPath.ExitCell, MazeSolverShortestPath.MazeToBeShowed, MazeSolverShortestPath.ExitCells.Count); MessageBox.Show($"There is no path to {MazeSolverShortestPath.ExitCell.Y - 1},{MazeSolverShortestPath.ExitCell.X - 1}.", "Notification", MessageBoxButton.OK, MessageBoxImage.Information); SolveButton.IsEnabled = false; _firstPass = false; } else { MediaPlayer soundBite = new MediaPlayer(); soundBite.Open(new Uri(@"..\..\SoundBit\Sound 2.mp3", UriKind.Relative)); soundBite.Play(); BlinkExit(MazeSolverShortestPath.ExitCell, MazeSolverShortestPath.MazeToBeShowed, 0); MessageBox.Show("Last exit unreachable.", "Notification", MessageBoxButton.OK, MessageBoxImage.Information); SolveButton.Visibility = Visibility.Collapsed; ResetButton.Visibility = Visibility.Visible; SolveButton.IsEnabled = false; _firstPass = true; } } } } #endregion }