Beispiel #1
0
        //玩家开火
        public override void Fire()
        {
            if (this.Life > 0)
            {
                switch (ZDlev)
                {
                case 0:
                    SingleObject.GetSingle().AddGameObject(new PZiDan(this, 7, 10, 1));    //一级玩家子弹的属性:速度,生命,伤害
                    break;

                case 1:
                    SingleObject.GetSingle().AddGameObject(new PZiDan(this, 9, 10, 2));    //二级玩家子弹的属性:速度,生命,伤害
                    break;

                case 2:
                    SingleObject.GetSingle().AddGameObject(new PZiDan(this, 11, 10, 3));    //三级玩家子弹的属性:速度,生命,伤害
                    break;

                case 3:
                    SingleObject.GetSingle().AddGameObject(new PZiDan(this, 13, 10, 4));    //四级玩家子弹的属性:速度,生命,伤害
                    break;

                case 4:
                    SingleObject.GetSingle().AddGameObject(new PZiDan(this, 15, 10, 5));    //五级玩家子弹的属性:速度,生命,伤害
                    break;
                }
            }
        }
Beispiel #2
0
        Random r = new Random();//产生随机数

        //敌人设置
        public void SetEnemyTanks()
        {
            for (int i = 0; i < 12; i++)//设置敌人坦克初数量
            {
                SingleObject.GetSingle().AddGameObject(new EnemyTank(r.Next(0, this.Width), r.Next(0, this.Height), r.Next(0, 3), Direction.down));
            }
        }
Beispiel #3
0
        public override void Draw(Graphics g)
        {
            time++;
            for (int i = 0; i < imgs.Length; i++)
            {
                switch (time % 10)
                {
                case 1:
                    g.DrawImage(imgs[0], this.X, this.Y);
                    break;

                case 3:
                    g.DrawImage(imgs[1], this.X, this.Y);
                    break;

                case 5:
                    g.DrawImage(imgs[2], this.X, this.Y);
                    break;

                case 7:
                    g.DrawImage(imgs[3], this.X, this.Y);
                    break;
                }
            }
            //移除闪烁的图片
            if (time % 20 == 0)
            {
                SingleObject.GetSingle().RemoveGameObject(this);
            }
        }
Beispiel #4
0
 //玩家设置
 private void InitialGame()
 {
     //设置玩家初始位置,属性
     //对应:X,Y,速度,生命,方向
     SingleObject.GetSingle().AddGameObject(new PlayerTank(720, 924, 6, 10, Direction.up));
     SetEnemyTanks();
     InitialMap();
 }
Beispiel #5
0
 public static SingleObject GetSingle()
 {
     if (_singleObject == null)
     {
         _singleObject = new SingleObject();
     }
     return(_singleObject);
 }
Beispiel #6
0
 //判断玩家是否死亡
 public override void IsOver()
 {
     if (this.Life <= 0)
     {
         SingleObject.GetSingle().AddGameObject(new Boom(this.X - 25, this.Y - 25));
     }
     else
     {
         SoundPlayer sp = new SoundPlayer(Resources.hit);
         sp.Play();
     }
 }
Beispiel #7
0
        //初始化地图坐标
        public void InitialMap()
        {
            for (int i = 0; i < 10; i++)
            {
                SingleObject.GetSingle().AddGameObject(new Wall(i * 15 + 30, 100));
                SingleObject.GetSingle().AddGameObject(new Wall(95, 100 + 15 * i));

                SingleObject.GetSingle().AddGameObject(new Wall(245 - i * 7, 100 + 15 * i));
                SingleObject.GetSingle().AddGameObject(new Wall(245 + i * 7, 100 + 15 * i));
                SingleObject.GetSingle().AddGameObject(new Wall(215 + i * 15 / 2, 185));

                SingleObject.GetSingle().AddGameObject(new Wall(390 - i * 5, 100 + 15 * i));
                SingleObject.GetSingle().AddGameObject(new Wall(390 + i * 5, 100 + 15 * i));
                SingleObject.GetSingle().AddGameObject(new Wall(480 - i * 5, 100 + 15 * i));

                SingleObject.GetSingle().AddGameObject(new Wall(515, 100 + 15 * i));
                SingleObject.GetSingle().AddGameObject(new Wall(595 - i * 8, 100 + 15 * i / 2));
                SingleObject.GetSingle().AddGameObject(new Wall(530 + i * 8, 165 + 15 * i / 2));
            }
        }
Beispiel #8
0
        //判断敌人是否死亡
        public override void IsOver()
        {
            if (this.Life == 0)//敌人死亡
            {
                //调用爆炸方法
                SingleObject.GetSingle().AddGameObject(new Boom(this.X - 25, this.Y - 25));

                //清除此坦克
                SingleObject.GetSingle().RemoveGameObject(this);

                //播放爆炸声音
                SoundPlayer sp = new SoundPlayer(Resources.fire);
                sp.Play();

                //几率刷出新的敌人坦克
                if (r.Next(0, 100) >= 40)//刷新敌人概率:100-60
                {
                    SingleObject.GetSingle().AddGameObject(new EnemyTank(r.Next(0, 1360), r.Next(0, 924), r.Next(0, 3), Direction.down));
                }

                //几率刷出装备
                if (r.Next(0, 100) >= 95)//刷出装备概率:100-75
                {
                    SingleObject.GetSingle().AddGameObject(new ZhuangB(this.X, this.Y, 0));
                }
                if (r.Next(0, 100) >= 98)//刷出装备概率:100-75
                {
                    SingleObject.GetSingle().AddGameObject(new ZhuangB(this.X, this.Y, 1));
                }
                if (r.Next(0, 100) >= 85)//刷出装备概率:100-75
                {
                    SingleObject.GetSingle().AddGameObject(new ZhuangB(this.X, this.Y, 2));
                }
            }
            else//敌人未死亡
            {
                SoundPlayer sp = new SoundPlayer(Resources.hit);
                sp.Play();
            }
        }
Beispiel #9
0
        public override void Draw(Graphics g)
        {
            time++;
            switch (time % 15)
            {
            case 1:
                g.DrawImage(imgs[0], this.X, this.Y);
                break;

            case 3:
                g.DrawImage(imgs[1], this.X, this.Y);
                break;

            case 5:
                g.DrawImage(imgs[2], this.X, this.Y);
                break;

            case 7:
                g.DrawImage(imgs[3], this.X, this.Y);
                break;

            case 9:
                g.DrawImage(imgs[4], this.X, this.Y);
                break;

            case 11:
                g.DrawImage(imgs[5], this.X, this.Y);
                break;

            case 13:
                g.DrawImage(imgs[6], this.X, this.Y);
                break;

            case 15:
                g.DrawImage(imgs[7], this.X, this.Y);
                break;

            case 17:
                g.DrawImage(imgs[6], this.X, this.Y);
                break;

            case 19:
                g.DrawImage(imgs[5], this.X, this.Y);
                break;

            case 21:
                g.DrawImage(imgs[4], this.X, this.Y);
                break;

            case 23:
                g.DrawImage(imgs[3], this.X, this.Y);
                break;

            case 25:
                g.DrawImage(imgs[2], this.X, this.Y);
                break;

            case 27:
                g.DrawImage(imgs[1], this.X, this.Y);
                break;

            case 29:
                g.DrawImage(imgs[0], this.X, this.Y);
                break;
            }
            if (time % 40 == 0)
            {
                SingleObject.GetSingle().RemoveGameObject(this);
            }
        }
Beispiel #10
0
 //玩家坦克出生
 public override void Born()
 {
     SingleObject.GetSingle().AddGameObject(new TankBorn(this.X, this.Y));
 }
Beispiel #11
0
 //窗体更新
 private void timer1_Tick(object sender, EventArgs e)
 {
     this.Invalidate();
     SingleObject.GetSingle().PZJC();//碰撞检测
 }
Beispiel #12
0
 // 按下键盘触发
 private void Form1_KeyDown(object sender, KeyEventArgs e)
 {
     SingleObject.GetSingle().Player.KeyDown(e);
 }
Beispiel #13
0
 // 初始化游戏,绘制游戏画面
 private void Form1_Paint(object sender, PaintEventArgs e)//sender:触发事件的条件;e:该事件需要的资源。
 {
     SingleObject.GetSingle().Draw(e.Graphics);
 }
Beispiel #14
0
 //敌人开火
 public override void Fire()
 {
     SingleObject.GetSingle().AddGameObject(new CZiDan(this, 4, 10, 1));//敌人子弹属性:速度,生命,伤害
 }