Example #1
0
        private void InitializeEnemyPlanes(SingleObject singleObject)
        {
            for (int i = 0; i < 4; i++)
            {
                singleObject.AddGameObject(new PlaneEnemy(random.Next(0, this.Width), -400, random.Next(0, 2)));
            }

            if (random.Next(0, 100) > 80)
            {
                // 20%的机会出现大飞机
                singleObject.AddGameObject(new PlaneEnemy(random.Next(0, this.Width - 80), -400, 2));
            }
        }
        // 重写IsOver方法:判断敌人是否阵亡
        public override void IsOver()
        {
            if (this.Life <= 0)
            {
                SingleObject singleObject = SingleObject.GetInstance();
                // 1.首先移除自身
                singleObject.RemoveGameObject(this);
                // 2.播放敌人爆炸图片
                singleObject.AddGameObject(new BoomEnemy(this.X, this.Y, this.EnemyType));
                // 3.播放敌人爆炸声音
                SoundPlayer sp = new SoundPlayer(Resources.enemy0_down1);
                sp.Play();
                // 4.根据不同的敌人类型添加不同的分数
                switch (this.EnemyType)
                {
                case 0:
                    singleObject.Score += 100;
                    break;

                case 1:
                    singleObject.Score += 200;
                    break;

                case 2:
                    singleObject.Score += 300;
                    break;
                }
            }
        }
Example #3
0
        // 初始化游戏对象
        private void InitializeGameObjects()
        {
            SingleObject singleObject = SingleObject.GetInstance();

            // 1.1 初始化游戏背景
            singleObject.AddGameObject(new GameBackground(0, -850, 5));
            // 1.2 初始化游戏标题
            singleObject.AddGameObject(new GameTitle(20, 50, 10));
            // 1.3 初始化玩家飞机
            singleObject.AddGameObject(new PlanePlayer(this.Width / 2 - 50, this.Height * 3 / 4, 5, 3, Direction.Up));
            // 2.初始化Timer组件
            this.timerBackground.Interval = 50;
            this.timerBackground.Enabled  = true;
            this.timerPlayTime.Interval   = 1000;
            this.timerPlayTime.Enabled    = true;
            // 3.初始化敌人飞机
            //InitializeEnemyPlanes(singleObject);
        }
        // 重写IsOver方法:判断玩家是否阵亡
        public override void IsOver()
        {
            SingleObject singleObject = SingleObject.GetInstance();

            singleObject.AddGameObject(new BoomPlayer(this.X, this.Y));
            if (singleObject.Score >= 100)
            {
                singleObject.Score -= 50;
            }
        }