private async void RestartButton_Click(object sender, RoutedEventArgs e) { var request = new CreateGame { Gamemode = new GamemodeDto { Width = Game.Board.Width, Height = Game.Board.Height, Bombs = Game.Board.Bombs, Name = GamemodeName } }; _timer.Stop(); TimeTextBlock.Text = 0.ToString(); var response = await _communication.SendAndRecieveAsync <GameDto>(request); if (response == null) { ConnectionLost = true; Close(); return; } UpdateWindow(response); UpdateFields(response.Board.Fields); }
private async void PlayButton_Click(object sender, RoutedEventArgs e) { var request = new CreateGame { Gamemode = new GamemodeDto { Width = (int)WidthSlider.Value, Height = (int)HeightSlider.Value, Bombs = (int)BombsSlider.Value, Name = ((GamemodeDto)LevelsList.SelectedItem).Name } }; var response = await _communication.SendAndRecieveAsync <GameDto>(request); if (response == null) { _provider.GetRequiredService <ServerSettings>().Show(); Close(); return; } using (var scope = _provider.CreateScope()) { var gameScreen = new GameScreen(this, _communication, ((GamemodeDto)LevelsList.SelectedItem).Name, response, _provider.GetRequiredService <IAssets>()); gameScreen.ShowDialog(); if (gameScreen.ConnectionLost) { _provider.GetRequiredService <ServerSettings>().Show(); Close(); } } }
private async void ConnectButton_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(HostTextBox.Text)) { StatusLabel.Content = "Invalid or empty hostname."; return; } if (string.IsNullOrWhiteSpace(PortTextBox.Text) || !int.TryParse(PortTextBox.Text, out int port)) { StatusLabel.Content = "Invalid or empty port."; return; } if (string.IsNullOrWhiteSpace(NickTextBox.Text)) { StatusLabel.Content = "Invalid or empty nickname."; return; } LockUI(); StatusLabel.Content = "Connecting..."; if (!await _communication.TryConnectAsync(HostTextBox.Text, port)) { StatusLabel.Content = "Can't connect to server."; UnlockUI(); return; } var response = await _communication.SendAndRecieveAsync <List <GamemodeDto> >(new Handshake { Nickname = NickTextBox.Text }); if (response == null) { StatusLabel.Content = "Can't recieve response from server."; UnlockUI(); return; } _saveConnection.Save(new LastConnectionSettings { Host = HostTextBox.Text, Port = PortTextBox.Text, Nickname = NickTextBox.Text }); _provider.GetRequiredService <Gamemodes>().List = response; _provider.GetRequiredService <GameSettings>().Show(); Close(); }