private void ProcessData(DataSender data) { switch (data.Mode) { case ((int)Mode.NEW_GAME): this.Invoke((MethodInvoker)(() => { _isWinner = false; _gamePlay.LuotDi = 2; _plnGrap.Clear(panel_ChessBoard.BackColor); _gamePlay.NguoiVsNguoi(_plnGrap); panel_ChessBoard.Enabled = _isServer; })); break; case ((int)Mode.PLAYER_MARK): this.Invoke((MethodInvoker)(() => { _gamePlay.danhCo(_plnGrap, data.Point); panel_ChessBoard.Enabled = true; })); break; case ((int)Mode.END_GAME): this.Invoke((MethodInvoker)(() => { _gamePlay.danhCo(_plnGrap, data.Point); MessageBox.Show("Đối thủ thắng"); panel_ChessBoard.Enabled = false; })); break; case ((int)Mode.QUIT): this.Invoke((MethodInvoker)(() => { MessageBox.Show("Đối thủ đã thoát"); panel_ChessBoard.Enabled = false; _Socket.Client = null; _Socket.Server.Close(); _Socket.CreateServer(); })); break; default: break; } }
private void Listen() { _threadListen = new Thread(() => { while (true) { try { _data = (DataSender)_Socket.Receive(); if (_data != null) { ProcessData(_data); } } catch { } } }); _threadListen.IsBackground = true; _threadListen.Start(); }