/// <summary> /// Handles the Loaded event of the MyMazeUserControl control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> private void MyMazeUserControl_Loaded(object sender, RoutedEventArgs e) { MyMazeBoard.Draw(); this.KeyDown += MyMazeBoard.OnKeyDownHandler; this.KeyDown += mpVM.OnMyMoveHandler; mpVM.MyMazeBoard = MyMazeBoard; }
/// <summary> /// Handles the Restart event of the Button_Click control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> private void Button_Click_Restart(object sender, RoutedEventArgs e) { MessageBoxResult result = MessageBox.Show("Are you sure you want to restart the game?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { MyMazeBoard.Restart(); } }
/// <summary> /// event for pressing the keys /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Window_KeyDown(object sender, KeyEventArgs e) { string move = e.Key.ToString().ToLower(); if (move.Equals("up") || move.Equals("down") || move.Equals("left") || move.Equals("right")) { vm.Move(move); MyMazeBoard.GridMazeBoard_KeyDown(sender, e); } }
/// <summary> /// Solves the messege. /// </summary> /// <param name="Solvefinish">if set to <c>true</c> [solvefinish].</param> public void SolveMessege(bool Solvefinish) { if (Solvefinish) { MessageBoxResult result = MessageBox.Show("Now that we solve the game for you, do you want to try again?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { MyMazeBoard.Restart(); } if (result == MessageBoxResult.No) { MessageBox.Show("press Ok to get back to the main menu", "Info", MessageBoxButton.OK, MessageBoxImage.Asterisk); MainWindow win = (MainWindow)Application.Current.MainWindow; win.Show(); this.Close(); } } }
/// <summary> /// Solves this instance. /// </summary> public void Solve() { Position p = spgVM.VM_InitPosition; Task t = Task.Run(() => { MyMazeBoard.Animation(p); foreach (char c in spgVM.VM_SolveString) { switch (c) { case '0': { p.Col -= 1; MyMazeBoard.Animation(p); break; } case '1': { p.Col += 1; MyMazeBoard.Animation(p); break; } case '2': { p.Row -= 1; MyMazeBoard.Animation(p); break; } case '3': { p.Row += 1; MyMazeBoard.Animation(p); break; } default: break; } } }); }