Пример #1
0
        public void Listen()
        {
            Thread listenThread = new Thread(() =>
            {
                while (true)
                {
                    Thread.Sleep(10);
                    try
                    {
                        SocketData Dataset = (SocketData)SOCKET.Receive();
                        //MessageBox.Show(message);
                        ConvertSocketDataReceived(Dataset);
                        Listen();
                        break;
                    }
                    catch (Exception)
                    {
                    }
                }
            });

            listenThread.IsBackground = true;
            listenThread.Start();
        }
Пример #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            SocketData Test_Data = new SocketData((int)SocketCommand.NOTIFY, new Point(), "ahaha");

            SOCKET.Send(Test_Data);
        }
Пример #3
0
        public void ConvertSocketDataReceived(SocketData Data)
        {
            switch (Data.command)
            {
            case (int)SocketCommand.FIRST_CONNECT:
                label_NameGuest.Text = Data.message.ToString();
                label_NameMain.Text  = form1.MainPlayer.Nickname.ToString();
                break;

            case (int)SocketCommand.SEND_POINT:
                this.Invoke((MethodInvoker)(() =>
                {
                    coolDownBar.Value = 0;
                    CHESSBOARD.GuestMark(Data.point);
                }));

                break;

            case (int)SocketCommand.NOTIFY:
                MessageBox.Show(Data.message.ToString());
                break;

            case (int)SocketCommand.NEW_GAME:
                this.Invoke((MethodInvoker)(() =>
                {
                    //CHESSBOARD.NewGame();
                    if (MessageBox.Show("Your partner want to make new match, Continue?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        SocketData data = new SocketData((int)SocketCommand.ACCEPT, new Point());
                        SOCKET.Send(data);
                        CHESSBOARD.NewGame();
                    }
                    else
                    {
                        SocketData data = new SocketData((int)SocketCommand.IGNORE, new Point());
                        SOCKET.Send(data);
                        MessageBox.Show("New match request is aborted.");
                    }
                }));
                break;

            case (int)SocketCommand.END_GAME:
                break;

            case (int)SocketCommand.QUIT:
                break;

            case (int)SocketCommand.ACCEPT:
                this.Invoke((MethodInvoker)(() =>
                {
                    MessageBox.Show("Your partner accept new match");
                    CHESSBOARD.NewGame();
                }));
                break;

            case (int)SocketCommand.IGNORE:
                this.Invoke((MethodInvoker)(() =>
                {
                    MessageBox.Show("Your partner ignore new match");
                }));
                break;
            }
        }