private async Task DoCreateGame() { await this.BattleshipsClient.CreateGame(); if (this.BattleshipsClient.CurrentResponse != null) { if (this.BattleshipsClient.CurrentResponse.IsSuccessStatusCode) { MessageBox.Show("Successfully created game."); string data = await this.BattleshipsClient.CurrentResponse.Content.ReadAsStringAsync(); this.BattleshipsClient.CurrentGameId = JsonConvert.DeserializeObject<string>(data).ToString(); JoinedGameWindow joinedGameWindow = new JoinedGameWindow(this.BattleshipsClient); joinedGameWindow.Show(); this.Close(); } else { string data = await this.BattleshipsClient.CurrentResponse.Content.ReadAsStringAsync(); MessageBox.Show(JsonConvert.DeserializeObject<dynamic>(data)["Message"].ToString()); } } }
private async Task DoJoinGame() { if (this.JoinGameField.Text == string.Empty) { MessageBox.Show("Field is empty."); } else { await this.BattleshipsClient.JoinGame(this.JoinGameField.Text); if (this.BattleshipsClient.CurrentResponse != null) { this.BattleshipsClient.CurrentGameId = this.JoinGameField.Text; if (this.BattleshipsClient.CurrentResponse.IsSuccessStatusCode) { JoinedGameWindow joinedGameWindow = new JoinedGameWindow(this.BattleshipsClient); joinedGameWindow.Show(); this.Close(); } else { string data = await this.BattleshipsClient.CurrentResponse.Content.ReadAsStringAsync(); string message = JsonConvert.DeserializeObject<dynamic>(data)["Message"].ToString(); if (message == "You can not join in your game!") { MessageBox.Show("Attention! You are not joining the game, you are entering in it, because it's game created by you."); JoinedGameWindow joinedGameWindow = new JoinedGameWindow(this.BattleshipsClient); joinedGameWindow.Show(); this.Close(); } else { MessageBox.Show(message); } } } } }