示例#1
0
        void Listen()
        {
            Thread listenThread = new Thread(() =>
            {
                try
                {
                    SocketData data = (SocketData)socket.Receive();

                    ProcessData(data);
                }
                catch (Exception e)
                {
                }
            });

            listenThread.IsBackground = true;
            listenThread.Start();
        }
示例#2
0
        void Listen()
        {
            //Tránh bị lỗi khi 1 bên thoát đột ngột
            try
            {
                Thread listenThread = new Thread(() =>
                {
                    SocketData data = (SocketData)socket.Receive();

                    ProcessData(data);
                });
                listenThread.IsBackground = true;
                listenThread.Start();
            }
            catch
            {
            }
        }
示例#3
0
        private void ProcessData(SocketData data)
        {
            switch (data.Command)
            {
            case (int)SocketCommand.NOTIFY:
                MessageBox.Show(data.Message);
                break;

            case (int)SocketCommand.NEW_GAME:
                this.Invoke((MethodInvoker)(() =>
                {
                    NewGame();
                    pnlChessBoard.Enabled = false;
                }));
                break;

            case (int)SocketCommand.QUIT:
                tmCoolDown.Stop();
                MessageBox.Show("Người chơi đã thoát!");
                caroChess.Ready = false;
                break;

            case (int)SocketCommand.SEND_POINT:
                this.Invoke((MethodInvoker)(() =>
                {
                    prcbCoolDown.Value = 0;
                    tmCoolDown.Start();
                    OtherPlayerMark(data.Point);
                }));

                break;

            case (int)SocketCommand.END_GAME:
                break;

            default:
                break;
            }
            Listen();
        }
示例#4
0
        private void ProcessData(SocketData data)
        {
            switch (data.Command)
            {
            case (int)SocketCommand.NOTIFY:
                MessageBox.Show(data.Message);
                break;

            case (int)SocketCommand.NEW_GAME:
                break;

            case (int)SocketCommand.SEND_POINT:
                this.Invoke((MethodInvoker)(() =>
                {
                    prcbCoolDown.Value = 0;
                    pnlChessBoard.Enabled = true;
                    tmCoolDown.Start();
                    ChessBoard.OtherPlayerMark(data.Point);
                }));
                break;

            case (int)SocketCommand.UNDO:
                break;

            case (int)SocketCommand.END_GAME:
                break;

            case (int)SocketCommand.QUIT:
                break;

            default:
                break;
            }

            Listen();
        }
示例#5
0
        private void ProcessData(SocketData data)
        {
            switch (data.Command)
            {
            case (int)SocketCommand.NOTIFY:
                MessageBox.Show(data.Message);
                break;

            case (int)SocketCommand.NEW_GAME:
                break;

            case (int)SocketCommand.SEND_POINT:
                break;

            case (int)SocketCommand.QUIT:
                break;

            case (int)SocketCommand.UNDO:
                break;

            default:
                break;
            }
        }
示例#6
0
        private void ProcessData(SocketData data)
        {
            switch (data.Command)
            {
            case (int)SocketCommand.NOTIFY:
                MessageBox.Show(data.Message);
                break;

            case (int)SocketCommand.NEW_GAME:
                this.Invoke((MethodInvoker)(() =>
                {
                    NewGame();
                    pnlChessBoard.Enabled = false;
                }));
                break;

            case (int)SocketCommand.SEND_POINT:
                this.Invoke((MethodInvoker)(() =>
                {
                    prcbCoolDown.Value = 0;
                    pnlChessBoard.Enabled = true;
                    tmCoolDown.Start();
                    ChessBoard.OtherPlayerMark(data.Point);
                    undoToolStripMenuItem.Enabled = true;
                }));

                break;

            case (int)SocketCommand.UNDO:
                Undo();
                prcbCoolDown.Value = 0;
                break;

            case (int)SocketCommand.REDO:
                Redo();
                prcbCoolDown.Value = 0;
                break;

            case (int)SocketCommand.END_GAME:
                this.Invoke((MethodInvoker)(() =>
                {
                    //newGameToolStripMenuItem.Enabled = false;
                    txbPlayerName.Text = ChessBoard.PlayerName.Text;
                    MessageBox.Show(txbPlayerName.Text + " thắng!");
                }));

                break;

            case (int)SocketCommand.TIME_OUT:
                MessageBox.Show("Hết giờ");
                break;

            case (int)SocketCommand.QUIT:
                tmCoolDown.Stop();
                MessageBox.Show("Người chơi đã thoát");
                break;

            default:
                break;
            }

            Listen();
        }
示例#7
0
        private void ProcessData(SocketData data)
        {
            switch (data.Command)
            {
            case (int)SocketCommand.NOTIFY:
                MessageBox.Show(data.Message);
                break;

            case (int)SocketCommand.NEW_GAME:
                this.Invoke((MethodInvoker)(() =>
                {
                    NewGame();
                    pnlChessBoard.Enabled = false;
                }));
                break;

            case (int)SocketCommand.SEND_POINT:
                //vì timer chạy thread khác với main nên phải đưa vào invoke
                this.Invoke((MethodInvoker)(() =>
                {
                    prcbCoolDown.Value = 0;
                    pnlChessBoard.Enabled = true;
                    tmCoolDown.Start();
                    ChessBoard.OtherPlayerMark(data.Point);
                    undoToolStripMenuItem.Enabled = true;
                }));
                break;

            case (int)SocketCommand.UNDO:
                this.Invoke((MethodInvoker)(() =>
                {
                    Undo();
                    prcbCoolDown.Value = 0;
                }));
                break;

            case (int)SocketCommand.END_GAME:
                this.Invoke((MethodInvoker)(() =>
                {
                    if (ChessBoard.NumberPlayerWin == 0)
                    {
                        MessageBox.Show("Người chơi 1 thắng");
                    }
                    else if (ChessBoard.NumberPlayerWin == 1)
                    {
                        MessageBox.Show("Người chơi 2 thắng");
                    }
                }));
                break;

            case (int)SocketCommand.TIME_OUT:
                MessageBox.Show("Hết giờ");
                break;

            case (int)SocketCommand.QUIT:
                this.Invoke((MethodInvoker)(() =>
                {
                    tmCoolDown.Stop();
                    MessageBox.Show("Người chơi đã thoát");
                }));
                break;

            default:
                break;
            }

            Listen();
        }