private void ButtonNext_Click(object sender, RoutedEventArgs e) { try { OnlineGame = new OnlineGame(PlayerRole.Client, _placement, ServerUtils.StringToIP(KeyTextBox.Text)); Thread.Sleep(2000); if (_placement != PlacementState.Manualy) { OnlineGame.CreateGame(_shipArrangement); PlayPage window = new PlayPage(OnlineGame); WindowConfig.MainPage.NavigationService.Navigate(window, UriKind.Relative); } else { PlacingPage window = new PlacingPage(OnlineGame); WindowConfig.MainPage.NavigationService.Navigate(window, UriKind.Relative); } Close(); } catch (IndexOutOfRangeException exception) { LogService.Trace($"Невозможно подключиться: {exception.Message}"); MessageBox.Show("Вы ввели неправильный ключ. Повторите попытку", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Warning); } catch (Exception exception) { LogService.Trace($"Невозможно подключиться: {exception.Message}"); MessageBox.Show($"Ошибка подключения к серверу", "Предупреждение", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void ButtonNext_Click(object sender, RoutedEventArgs e) { OnlineGame.SetGameSettings(new GameConfig(PlayerRole.Server, "", _gameSpeed)); if (OnlineGame.Connect.Server.IsClientConnected) { // OnlineGame.GoToGameWindow(_placement, _shipArrangement, Owner); if (_placement != PlacementState.Manualy) { OnlineGame.CreateGame(_shipArrangement); PlayPage window = new PlayPage(OnlineGame); WindowConfig.MainPage.NavigationService.Navigate(window, UriKind.Relative); } else { PlacingPage window = new PlacingPage(OnlineGame); WindowConfig.MainPage.NavigationService.Navigate(window, UriKind.Relative); } Close(); } else { WaitingWindow window = new WaitingWindow(OnlineGame, _shipArrangement, _placement); window.Show(); window.Wait(); Close(); } }
private void SaveButton_Click(object sender, RoutedEventArgs e) { ShipArrangement arr = FileSystem.LoadArrangement(((Button)sender).Content.ToString()); WindowConfig.game = new Game(arr, _arrangementClient, _gameConfig); if (WindowConfig.GameState == WindowConfig.State.Offline) { PlayPage playPage = new PlayPage(WindowConfig.game); WindowConfig.NavigationService.Navigate(playPage, UriKind.Relative); } else { _onlineGame.CreateGame(arr); PlayPage page = new PlayPage(_onlineGame); WindowConfig.NavigationService.Navigate(page, UriKind.Relative); } Close(); }
private void NewGame_MouseLeftButtonDown(object sender, RoutedEventArgs e)// { WindowConfig.NavigationService = NavigationService; WindowConfig.GameState = WindowConfig.State.Offline; ConfigOfflineWindow window = new ConfigOfflineWindow(); if (window.ShowDialog() == true) { if (WindowConfig.game == null) { PlacingPage placingPage = new PlacingPage(window.ArrangementClient, window.Game); NavigationService.Navigate(placingPage, UriKind.Relative); } else { PlayPage playPage = new PlayPage(WindowConfig.game); NavigationService.Navigate(playPage, UriKind.Relative); } } }
private void Button_Click(object sender, RoutedEventArgs e) { Game game = FileSystem.LoadGame(((Button)sender).Content.ToString()); if (game.GameConfig.IsOnline) { OnlineGame onlineGame = new OnlineGame(PlayerRole.Server, PlacementState.Loaded); onlineGame.Game = game; WindowConfig.IsLoaded = true; WaitingWindow window = new WaitingWindow(onlineGame, null, PlacementState.Loaded); window.SetNavigationService(NavigationService); window.Show(); window.Wait(); } else { WindowConfig.game = game; WindowConfig.IsLoaded = true; PlayPage playPage = new PlayPage(WindowConfig.game); NavigationService.Navigate(playPage, UriKind.Relative); } }
public void Wait() { while (!OnlineGame.Connect.Server.IsClientConnected) { } if (Placement == PlacementState.Manualy) { PlacingPage window = new PlacingPage(OnlineGame); WindowConfig.MainPage.NavigationService.Navigate(window, UriKind.Relative); } else if (Placement == PlacementState.Loaded) { OnlineGame.LoadGame(OnlineGame.Game); PlayPage window = new PlayPage(OnlineGame); _nService.Navigate(window, UriKind.Relative); } else { OnlineGame.CreateGame(Arrangment); PlayPage window = new PlayPage(OnlineGame); WindowConfig.MainPage.NavigationService.Navigate(window, UriKind.Relative); } Close(); }