private void btnHostGame_Click(object sender, EventArgs e) { this.ActiveListener = false; this.tListenForRequest.Abort(); timerSendBroadcast.Stop(); timerUpdateHost.Stop(); frmMain.localpc.DisconnectUDP(); frmMain.localpc.Function = 1; this.Hide(); this.AlHost = new ArrayList(); lstHost.Items.Clear(); ///Join Game frmLanGame frmlangame = new frmLanGame(); frmlangame.ShowDialog(); ///Escape Game this.Show(); timerSendBroadcast.Start(); timerUpdateHost.Start(); this.ActiveListener = true; tListenForRequest = new Thread(new ThreadStart(ListenForRequest)); tListenForRequest.IsBackground = true; tListenForRequest.Start(); }
private void btnJoinGame_Click(object sender, EventArgs e) { if (lstHost.SelectedItems.Count > 0) { tListenForRequest.Abort(); this.ActiveListener = false; timerSendBroadcast.Stop(); timerUpdateHost.Stop(); frmMain.localpc.DisconnectUDP(); frmMain.localpc.ConnectState = 1; frmMain.localpc.Function = 2; ListViewItem li = lstHost.SelectedItems[0]; string strHost = li.Text; string[] arrHostEntry = strHost.Split(':'); frmMain.localpc.ParnerIP = arrHostEntry[1]; frmMain.localpc.ParnerName = arrHostEntry[0]; clsProfile profile = new clsProfile(frmMain.localpc.Profile); string a = profile.TotalWin.ToString(); string b = profile.TotalDraw.ToString(); string c = profile.TotalLose.ToString(); string d = profile.Rating.ToString(); frmMain.localpc.SendUDPData(frmMain.localpc.ParnerIP, "JOIN", a + ":" + b + ":" + c + ":" + d); this.Hide(); this.AlHost = new ArrayList(); lstHost.Items.Clear(); ///Join Game frmLanGame frmlangame = new frmLanGame(); frmlangame.ShowDialog(); ///Escape Game this.Show(); this.ActiveListener = true; timerSendBroadcast.Start(); timerUpdateHost.Start(); tListenForRequest = new Thread(new ThreadStart(ListenForRequest)); tListenForRequest.IsBackground = true; tListenForRequest.Start(); } else { MessageBox.Show("Vui lòng chọn máy ...", "Join Game"); } }