Exemplo n.º 1
0
        private void Form1_MouseClick(object sender, MouseEventArgs e)
        {
            ////move picture to right
            //this.archer_left.Location = new Point(this.archer_left.Location.X + 5, this.archer_left.Location.Y);
            ////send picture position to rival
            //Program.socket.Send(new SocketData((int)SocketCommand.SEND_POINT, "", this.archer_left.Location));
            //Listen();
            /////////////////////////


            //show picture at clicked position
            Trop trop = null;

            switch (currentTrop)
            {
            case CurrentTrop.Tank:
                trop = new Tank();
                break;

            case CurrentTrop.Archer:
                trop = new Archer();
                break;

            case CurrentTrop.Minion:
                trop = new Minion();
                break;
            }
            trop.Picture.Location = new Point(e.X, e.Y);
            //send current trop type and its position to rival
            Program.socket.Send(new SocketData((int)SocketCommand.SEND_POINT, currentTrop, new Point(e.X, e.Y)));
            //add trop to form
            listTrops.Add(trop);
            this.Controls.Add(trop.Picture);
            ///////////////////////////////////
        }
Exemplo n.º 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();
        }
Exemplo n.º 3
0
        private void Form1_MouseClick(object sender, MouseEventArgs e)
        {
            //drop spell
            if (currentItem == CurrentItem.SpellHeal)
            {
                Spell spell = null;
                switch (currentItem)
                {
                case CurrentItem.SpellHeal:
                    spell = new Heal(Const.currentTeam);
                    break;
                }
                if (availableMoney >= spell.Price)
                {
                    //decrease available money
                    availableMoney -= spell.Price;
                    UpdateMoney();
                    spell.CurrentLocation = new Point(e.X - 23, e.Y - 23);
                    //send current spell type and its position to rival
                    Program.socket.Send(new SocketData((int)SocketCommand.SEND_POINT, currentItem, spell.CurrentLocation));
                    //add spell to list spell
                    Const.listSpells.Add(spell);
                }
            }
            //drop trop
            else
            {
                //set curren trop type
                Trop trop = null;
                switch (currentItem)
                {
                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 trop location base on clicked point
                //only allow drop trop at specific location
                //and enough money
                try
                {
                    if (((e.Y >= 124 && e.Y <= 211) || (e.Y >= 307 && e.Y <= 374) || (e.Y >= 476 && e.Y <= 541)) &&
                        (Const.currentTeam ? e.X < 365 : e.X > 430) &&
                        availableMoney >= trop.Price)
                    {
                        //decrease available money
                        availableMoney -= trop.Price;
                        UpdateMoney();
                        //lane 1
                        if (e.Y >= 124 && e.Y <= 211)
                        {
                            trop.CurrentLocation = new Point(e.X, 111);
                        }
                        //lane 2
                        else if (e.Y >= 307 && e.Y <= 374)
                        {
                            trop.CurrentLocation = new Point(e.X, 275);
                        }
                        //lane 3
                        else if (e.Y >= 476 && e.Y <= 541)
                        {
                            trop.CurrentLocation = new Point(e.X, 444);
                        }
                        //send current trop type and its position to rival
                        Program.socket.Send(new SocketData((int)SocketCommand.SEND_POINT, currentItem, trop.CurrentLocation));
                        //add trop to listTrops
                        Const.listTrops.Add(trop);
                    }
                }
                catch { }
                //MessageBox.Show(e.X + "-" + e.Y);
            }
            //MessageBox.Show(e.X + "-" + e.Y);
        }