public Game(Server serverIn, Client clientIn) { InitializeComponent(); this.Closing += new System.ComponentModel.CancelEventHandler(Game_Closing); this.server = serverIn; this.client = clientIn; if (this.server != null) { this.map = this.server.map; this.server.UpdateChat += this.UpdateChat; this.server.UpdateProgressBar += this.UpdateProgressBar; this.server.UpdateStatusBar += this.UpdateStatusBar; this.server.PlayerLost += this.PlayerLost; this.BuildPlayerNames(this.server.playerNames); this.BuildMap(this.server.playerNames.IndexOf(this.server.name)); this.BuildStatusBar(this.server); } else { this.map = this.client.map; this.client.UpdateChat += this.UpdateChat; this.client.UpdateProgressBar += this.UpdateProgressBar; this.client.UpdateStatusBar += this.UpdateStatusBar; this.client.PlayerLost += this.PlayerLost; this.BuildPlayerNames(this.client.playerNames); this.BuildMap(this.client.playerNames.IndexOf(this.client.name)); this.BuildStatusBar(this.client); } this.ChatInputTextBox.TextChanged += new TextChangedEventHandler(chatText_TextChanged); this.ChatInputTextBox.AcceptsReturn = true; this.ChatOutputTextBlock.TextWrapping = TextWrapping.Wrap; this.gameOver = false; }
public void CreateServer() { if (this.numberOfPlayers != 0 && this.avatarName != null && IPAddress.TryParse(this.IPBox.Text, out iPAdress) && Int32.TryParse(this.PortBox.Text, out port)) { try { this.server = new Server(this.avatarName, this.numberOfPlayers, this.iPAdress, this.port); this.server.UpdateConnectingText += this.UpdateConnectingText; this.server.CreateBattleField += this.CreateBattleGround; this.BattleGround.Children.Clear(); this.backGroundTextBlock.Text = "Connecting...\n" + "[" + this.server.playerNames.Count + "/" + this.numberOfPlayers + "]"; this.BattleGround.Children.Add(this.backGroundTextBlock); } catch { MessageBox.Show("Al parecer hubo un error con los datos ingresados. Inténtelo nuevamente."); this.ResetData(); } } else { this.ResetData(); } }