Beispiel #1
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);
                }));
                break;

            case (int)SocketCommand.END_GAME:
                MessageBox.Show("Đã 5 con trên 1 hà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();
        }
Beispiel #2
0
        void Listen()
        {
            Thread listenThread = new Thread(() =>
            {
                try
                {
                    SocketData data = (SocketData)socket.Receive();

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

            listenThread.IsBackground = true;
            listenThread.Start();
        }