Ejemplo n.º 1
0
        //8.重写是否中弹的方法就是显示爆炸的的图像。播放音乐。敌人死亡
        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) > 30)
            {
                SingleObject.GetSingle().AddGameObject(new EnemyTank(r.Next(0, 700), r.Next(0, 600), r.Next(0, 3), Direction.Down));
            }
            //当敌人死亡的额时候有一定的几率,产生装备
            if (r.Next(0, 100) > 20)
            {
                SingleObject.GetSingle().AddGameObject(new Zhuangbei(this.X, this.Y, r.Next(0, 3)));
            }


            //}
            //else//敌人被击中了,但没死亡
            //{
            //     SoundPlayer sp = new SoundPlayer(Resources.hit );
            //      sp.Play();

            //}
        }
Ejemplo n.º 2
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;
                }
            }
            //当for循环结束之后,也就是闪烁图片播放完成之后
            //这个时候我们应该将图片消除

            if (time % 5 == 0)
            {
                SingleObject.GetSingle().RemoveGameObject(this);
                //结果闪烁太快。解决方法——向上看
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 6.初始化敌人坦克对象
 /// </summary>
 public void SetEnemyTank()
 {
     for (int i = 0; i < 8; i++)
     {
         SingleObject.GetSingle().AddGameObject(new EnemyTank(r.Next(0,
                                                                     this.Width), r.Next(0, this.Height), r.Next(0, 3), Direction.Down));
     }
 }
Ejemplo n.º 4
0
 //3.重写绘制图像的方法
 public override void Draw(Graphics g)
 {
     for (int i = 0; i < imgs.Length; i++)
     {
         g.DrawImage(imgs[i], this.X, this.Y);
     }
     //爆炸播放完成之后,就删除游戏对象
     SingleObject.GetSingle().RemoveGameObject(this);
 }
Ejemplo n.º 5
0
        //不绕了,直接在写一个方法初始化地图
        /// <summary>
        /// 初始化游戏地图
        /// </summary>
        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));
            }
        }
Ejemplo n.º 6
0
        //2.重写发射子弹
        public override void Fire()
        {
            //(6.位吃装备写代码{{
            switch (ZDLevel)
            {
            case 0:
                SingleObject.GetSingle().AddGameObject(new PlayerZD(this, 10, 10, 1));
                break;

            case 1:
                SingleObject.GetSingle().AddGameObject(new PlayerZD(this, 20, 10, 1));
                break;

            case 2:
                SingleObject.GetSingle().AddGameObject(new PlayerZD(this, 40, 10, 1));
                break;
            }

            //当执行这个方法时,我们创建子弹对象
            SingleObject.GetSingle().AddGameObject(new PlayerZD(this, 10, 10, 1));
        }
Ejemplo n.º 7
0
 //9.坦克出生重写
 public override void Born()
 {
     SingleObject.GetSingle().AddGameObject(new TankBorn(this.X, this.Y));
 }
Ejemplo n.º 8
0
 //7.发射子弹的重写
 /// <summary>
 /// 敌人发射子弹
 /// </summary>
 public override void Fire()
 {
     SingleObject.GetSingle().AddGameObject(new EnemyZD(this, 10, 10, 1));
 }
Ejemplo n.º 9
0
 /// <summary>
 /// 4.当键按下的时候会触发
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Form1_KeyDown(object sender, KeyEventArgs e)
 {
     //调用方法
     SingleObject.GetSingle().PT.KeyDown(e);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// 3..对窗体实时进行更新50ms
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void timer1_Tick(object sender, EventArgs e)
 {
     this.Invalidate();
     //调用碰撞检测方法
     SingleObject.GetSingle().PZJC();
 }
Ejemplo n.º 11
0
 /// <summary>
 /// 2.窗体的paint事件,确保重绘的时候不会擦掉
 /// </summary>
 /// <param name="sender">出发当前事件的对象</param>
 /// <param name="e">执行这个方法所需要的资源</param>
 private void Form1_Paint(object sender, PaintEventArgs e)
 {
     SingleObject.GetSingle().Draw(e.Graphics);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// 1.初始化游戏。包括初始化玩家坦克对象
 /// </summary>
 private void InitialGame()
 {
     SingleObject.GetSingle().AddGameObject(new PlayerTank(200, 200, 10, 10, Direction.Up));
     SetEnemyTank();
 }