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

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

            listenThread.IsBackground = true;
            listenThread.Start();
        }
예제 #2
0
        private void ProcessData(SocketData data)
        {
            switch (data.Command)
            {
            case (int)SocketCommand.START_GAME:
                this.Invoke((MethodInvoker)(() =>
                {
                    btMegaman.Show();
                    btKnight.Show();
                    btHulk.Show();
                    btHealingSpell.Show();
                    timer1.Start();
                    timer_increase_money.Start();
                }));
                break;

            case (int)SocketCommand.NOTIFY:
                MessageBox.Show(data.Message);
                break;

            case (int)SocketCommand.NEW_GAME:
                break;

            case (int)SocketCommand.SEND_POINT:
                //use,no care
                this.Invoke((MethodInvoker)(() =>
                {
                    if (data.Current == CurrentItem.SpellHeal)
                    {
                        Spell spell = null;
                        switch (data.Current)
                        {
                        case CurrentItem.SpellHeal:
                            spell = new Heal(!Const.currentTeam);
                            break;
                        }
                        //set current location of spell received
                        spell.CurrentLocation = data.Point;
                        //add spell to list spell
                        Const.listSpells.Add(spell);
                    }
                    else
                    {
                        Trop trop = null;
                        switch (data.Current)
                        {
                        case CurrentItem.Knight:
                            trop = new Knight(!Const.currentTeam);
                            break;

                        case CurrentItem.Megaman:
                            trop = new Megaman(!Const.currentTeam);
                            break;

                        case CurrentItem.Hulk:
                            trop = new Hulk(!Const.currentTeam);
                            break;
                        }
                        //set current location of trop received
                        trop.CurrentLocation = data.Point;
                        //add trop to list trop
                        Const.listTrops.Add(trop);
                    }
                }));
                break;

            case (int)SocketCommand.UNDO:
                break;

            case (int)SocketCommand.END_GAME:
                this.Invoke((MethodInvoker)(() =>
                {
                    timer1.Stop();
                    timer_increase_money.Stop();
                    MessageBox.Show("You lose");
                    this.Close();
                    Program.login.Show();
                }));
                break;

            case (int)SocketCommand.QUIT:
                this.Invoke((MethodInvoker)(() =>
                {
                    MessageBox.Show("Đối thủ đã thoát");
                    //SocketManager.CloseConnection();
                    this.Close();
                    Program.login.Show();

                    //Program.main = null;
                }));
                break;

            default:
                break;
            }

            Listen();
        }