private void Border_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { try { proxy.AddClient(id); menuPlay = false; menu.Stop(); howl.Stop(); grStart.Visibility = Visibility.Collapsed; stWait.Visibility = Visibility.Visible; Thread thd = new Thread(new ThreadStart(() => { while (true) { if (proxy.CheckCl()) { gamePlay = true; Dispatcher.Invoke(new Action(() => { stWait.Visibility = Visibility.Collapsed; game.Play(); grGame.Visibility = Visibility.Visible; }), DispatcherPriority.Normal); FillBoard(); while (true) { try { Dispatcher.Invoke(new Action(() => imDice.IsEnabled = proxy.CheckMove(id))); Dispatcher.Invoke(new Action(() => { ServiceRef.GameGrid tmp = proxy.OponentPos(id); Grid.SetColumn(imOponent, tmp.CrdCol); Grid.SetRow(imOponent, tmp.CrdRow); }), DispatcherPriority.Normal); Thread.Sleep(100); } catch { gamePlay = false; game.Stop(); proxy.Abort(); } } } /*else * { * if (stWait.Visibility == Visibility.Collapsed) * { * try * { * gamePlay = false; * * Dispatcher.Invoke(new Action(() => * { * grGame.Visibility = Visibility.Collapsed; * game.Stop(); * stWait.Visibility = Visibility.Visible; * }), DispatcherPriority.Normal); * } * catch * { * proxy.Abort(); * Application.Current.Shutdown(); * } * } * }*/ Thread.Sleep(500); } })); thd.Start(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private void Image_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { Random rnd = new Random(); Thread thd = new Thread(new ThreadStart(() => { int num = 0; for (int i = 1; i < rnd.Next(5, 12); i++) { num = rnd.Next(1, 7); Dispatcher.Invoke(new Action(() => (sender as Image).Source = new BitmapImage(new Uri($"pack://application:,,,/Images/{num}.png")))); Thread.Sleep(350); } try { Dispatcher.Invoke(new Action(() => { ServiceRef.GameGrid tmp = proxy.Move(id, num); if (tmp.MoveType == ServiceRef.GridType.Red) { MessageBox.Show("You can move again!", "Bonus", MessageBoxButton.OK, MessageBoxImage.Information); } else if (tmp.Num == 8 || tmp.Num == 17 || tmp.Num == 20 || tmp.Num == 32 || tmp.Num == 40 || tmp.Num == 51) { MessageBox.Show("You can go further!", "Bonus", MessageBoxButton.OK, MessageBoxImage.Information); } else if (tmp.MoveType == ServiceRef.GridType.BrownStart) { MessageBox.Show("You should return!", "Trap", MessageBoxButton.OK, MessageBoxImage.Warning); } else if (tmp.MoveType == ServiceRef.GridType.StartEnd) { if (proxy.CheckIfWon(id)) { MessageBox.Show("You won!", "Game is over.", MessageBoxButton.OK, MessageBoxImage.Information); } else { MessageBox.Show("Try again!", "Game is over.", MessageBoxButton.OK, MessageBoxImage.Hand); } gamePlay = false; grGame.Visibility = Visibility.Collapsed; game.Stop(); stWait.Visibility = Visibility.Visible; } Grid.SetColumn(imHero, tmp.CrdCol); Grid.SetRow(imHero, tmp.CrdRow); })); } catch (Exception ex) { MessageBox.Show(ex.Message); } })); thd.Start(); }