Exemple #1
0
        public override void Move()
        {
            switch (this.Dir)
            {
            case Diretion.Up:
                this.Y -= this.Speed;
                break;

            case Diretion.Down:
                this.Y += this.Speed;
                break;

            case Diretion.Left:
                this.X -= this.Speed;
                break;

            case Diretion.Right:
                this.X += this.Speed;
                break;
            }
            if (this.X <= 0)
            {
                this.X = 0;
            }
            if (this.X >= 400)
            {
                this.X = 400;
            }
            if (this.Y <= 0)
            {
                this.Y = 0;
            }
            if (this.Y >= 700)
            {
                this.Y = 1400;//到达窗体底端  离开窗体
                SingleObject.GetSingle().RemoveGameObject(this);
            }
            //敌人飞机类型为0
            if (this.EnemyType == 0 && this.Y >= 200)
            {
                if (this.X >= 0 && this.X <= 220)
                {
                    //飞机在左边
                    this.X += r.Next(0, 50);
                }
                else
                {
                    this.X -= r.Next(0, 50);
                }
            }
            else
            {
                //如果是大飞机
                this.Speed += 1;
            }
            if (r.Next(0, 100) > 90)
            {//随机飞机发射子弹
                Fire();
            }
        }
Exemple #2
0
        public override void Draw(Graphics g)
        {
            switch (this.Type)
            {
            case 0:
                for (int i = 0; i < imgs1.Length; i++)
                {
                    g.DrawImage(imgs1[i], this.X, this.Y);
                }
                break;

            case 1:
                for (int i = 0; i < imgs2.Length; i++)
                {
                    g.DrawImage(imgs2[i], this.X, this.Y);
                }
                break;

            case 2:
                for (int i = 0; i < imgs3.Length; i++)
                {
                    g.DrawImage(imgs3[i], this.X, this.Y);
                }
                break;
            }
            //爆炸后销毁
            SingleObject.GetSingle().RemoveGameObject(this);
        }
Exemple #3
0
 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);
 }
Exemple #4
0
 public static SingleObject GetSingle()
 {
     if (_singte == null)
     {
         _singte = new SingleObject();
     }
     return(_singte);
 }
Exemple #5
0
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            SingleObject.GetSingle().PH.Fire();
        }
Exemple #6
0
        /// <summary>
        /// 初始化游戏
        /// </summary>
        public void InitialGame()
        {
            //初始化背景
            SingleObject.GetSingle().AddGameObject(new BackGround(0, -850, 5));

            //初始化玩家飞机
            SingleObject.GetSingle().AddGameObject(new PlaneHero(100, 100, 5, 3, Diretion.Up));
            InitialPlaneEnemy();
        }
Exemple #7
0
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            //窗体重新绘制,重新绘制背景
            SingleObject.GetSingle().Draw(e.Graphics);
            //显示分数
            string score = SingleObject.GetSingle().Score.ToString();

            e.Graphics.DrawString(score, new Font("宋体", 20, FontStyle.Bold), Brushes.Red, new Point(0, 0));
            //绘制到缓存区
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint, true);
        }
Exemple #8
0
 //增加敌人飞机
 void InitialPlaneEnemy()
 {
     for (int i = 0; i < 4; i++)
     {
         //初始化敌人飞机
         SingleObject.GetSingle().AddGameObject(new PlaneEnemy(r.Next(0, this.Width), -400, r.Next(0, 1)));
     }
     if (r.Next(0, 100) > 80)
     {
         //大飞机出现概率
         SingleObject.GetSingle().AddGameObject(new PlaneEnemy(r.Next(0, this.Width), -400, 1));
     }
 }
Exemple #9
0
        private void timerBG_Tick(object sender, EventArgs e)
        {
            this.Invalidate();
            //判断敌人飞机数量
            int count = SingleObject.GetSingle().listPlaneEnemy.Count;

            if (count < 1)
            {
                //重新初始化敌人飞机
                InitialPlaneEnemy();
            }
            //碰撞检测
            SingleObject.GetSingle().PZJC();
        }
Exemple #10
0
        public override void IsOver()
        {
            if (this.Life <= 0)
            {
                //敌人飞机坠毁
                SingleObject.GetSingle().RemoveGameObject(this);
                SingleObject.GetSingle().AddGameObject(new EnemyBoom(this.X, this.Y, EnemyType));
                //给玩家加分
                switch (this.EnemyType)
                {
                case 0:
                    SingleObject.GetSingle().Score += 100;
                    break;

                case 1:
                    SingleObject.GetSingle().Score += 200; break;

                case 2:
                    SingleObject.GetSingle().Score += 300; break;
                }
            }
        }
Exemple #11
0
 public void Fire()
 {
     SingleObject.GetSingle().AddGameObject(new EnemyZiDan(this, 20, 1));
 }
Exemple #12
0
 public override void IsOver()
 {
     SingleObject.GetSingle().AddGameObject(new HeroBoom(this.X, this.Y));
 }
Exemple #13
0
 //提供一个开炮的函数
 public void Fire()
 {
     //初始化玩家子弹到游戏中
     SingleObject.GetSingle().AddGameObject(new HeroZiDan(this, 10, 1));
 }
Exemple #14
0
 private void Form1_MouseMove(object sender, MouseEventArgs e)
 {
     //移动飞机
     SingleObject.GetSingle().PH.MouseMove(e);
 }