Beispiel #1
0
        public override void Draw(Graphics g)
        {
            timer++;
            for (int i = 0; i < imgs.Length; i++)
            {
                switch (timer % 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 (timer % 20 == 0)
            {
                SingleObject.GetSingle().RemoveGameObject(this);
            }
        }
Beispiel #2
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            //强制窗口刷新
            this.Invalidate();

            SingleObject.GetSingle().IsCrash();
        }
Beispiel #3
0
        public override void Move()
        {
            switch (this.Dir)
            {
            case Direction.Up:
                this.Y -= this.Speed;
                break;

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

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

            case Direction.Right:
                this.X += this.Speed;
                break;
            }

            //将子弹移除边界
            if (this.X <= 0 || this.Y <= 0 || this.X >= 800 || this.Y >= 600)
            {
                SingleObject.GetSingle().RemoveGameObject(this);
            }
        }
Beispiel #4
0
 /// <summary>
 /// 初始化敌人坦克对象
 /// </summary>
 public void SetEnemyTank()
 {
     for (int i = 0; i < 8; i++)
     {
         SingleObject.GetSingle().AddGameObject(new EnemyTank
                                                    (rdm.Next(0, this.Width), rdm.Next(0, this.Height), rdm.Next(0, 3), Direction.Down));
     }
 }
Beispiel #5
0
        public override void IsOver()
        {
            SoundPlayer sp = new SoundPlayer(Resources.hit);

            sp.Play();

            SingleObject.GetSingle().AddGameObject(new Boom(this.X, this.Y));
            //SingleObject.GetSingle().RemoveGameObject(this);
        }
Beispiel #6
0
        public override void Draw(Graphics g)
        {
            for (int i = 0; i < imgs.Length; i++)
            {
                g.DrawImage(imgs[i], this.X - 50, this.Y - 50);
            }

            //爆炸完成就去除你
            SingleObject.GetSingle().RemoveGameObject(this);
        }
Beispiel #7
0
 public override void Fire()
 {
     //检查是否创建成功
     if (SingleObject.GetSingle().AddGameObject(new PlayerBullet(this, 20, 10, 1)))
     {
         //开火前播放开火的声音
         SoundPlayer sp = new SoundPlayer(Resources.fire);
         sp.Play();
     }
 }
Beispiel #8
0
        private void SetEnemyTank()
        {
            Random rdm = new Random();

            for (int i = 0; i < 4; i++)
            {
                SingleObject.GetSingle().AddGameObject(new EnemyTank(rdm.Next(0, 750), rdm.Next(0, 550),
                                                                     rdm.Next(5, 7), rdm.Next(1, 3), rdm.Next(0, 2), Direction.Down));
            }
        }
Beispiel #9
0
        //当坦克死亡后,让其有一定几率复活
        public override void IsOver()
        {
            //表示已死
            if (this.Life == 0)
            {
                //击中后播放爆炸后就移除你
                SingleObject.GetSingle().AddGameObject(new Boom(this.X, this.Y));
                SingleObject.GetSingle().RemoveGameObject(this);
                //SingleObject.GetSingle().RemoveGameObject(Blood);
                //播放爆炸的声音
                SoundPlayer sp = new SoundPlayer(Resources.boom);
                sp.Play();

                deadTankNum++;
                currentTankNum--;

                //先用一定概率出生,后再判断剩余坦克数
                if (rdm.Next(0, 100) >= 50)
                {
                    SingleObject.GetSingle().AddGameObject(new EnemyTank(rdm.Next(0, 800),
                                                                         rdm.Next(0, 550), rdm.Next(0, 2), Direction.Down));

                    currentTankNum++;
                }

                //当屏幕上坦克少于2个的时候,随机增加几个坦克
                if (currentTankNum < 2)
                {
                    //MessageBox.Show("almost none ");
                    for (int i = 0; i < rdm.Next(1, 3); i++)
                    {
                        SingleObject.GetSingle().AddGameObject(new EnemyTank(rdm.Next(0, 800),
                                                                             rdm.Next(0, 550), rdm.Next(0, 2), Direction.Down));

                        currentTankNum++;
                    }
                }

                //当打死坦克数大于15,提示可以进入下一关
                //新的BUG 当加上MessageBox,就会引发越界错误!
                //尚未解决!!!
                if (deadTankNum >= 3)
                {
                    //MessageBox.Show("You Win!!!");
                }
            }
            else//击中但是未死
            {
                SoundPlayer sp = new SoundPlayer(Resources.hit);
                sp.Play();
            }
        }
Beispiel #10
0
        public void InitialGame()
        {
            this.Size      = new Size(800, 600);
            this.BackColor = Color.Black;

            //控制窗口大小不可改变
            this.MaximumSize = new Size(800, 600);
            this.MinimumSize = new Size(800, 600);

            SingleObject.GetSingle().AddGameObject(new PlayerTank(200, 200, 15, 10, Direction.Down));
            SetEnemyTank();

            InitialMap();
        }
Beispiel #11
0
        public override void BeHit()
        {
            //如果子弹击中物体
            //播放小爆炸图片
            //播放击中物体小爆炸声音
            //移除子弹对象

            SingleObject.GetSingle().AddGameObject(new SmallBoom(this.X, this.Y));

            SoundPlayer sp = new SoundPlayer(Resources.hit);

            sp.Play();

            SingleObject.GetSingle().RemoveGameObject(this);
        }
Beispiel #12
0
        /// <summary>
        /// 根据坦克类型以及剩余血量,画不同的血条
        /// </summary>
        /// <param name="g"></param>
        public override void Draw(Graphics g)
        {
            switch (type)
            {
            case 0:
                g.DrawImage(imgs[0], this.x, this.y);
                break;

            case 1:
            {
                switch (life)
                {
                case 2:
                    g.DrawImage(imgs[0], this.x, this.y);
                    break;

                case 1:
                    g.DrawImage(imgs[3], this.x, this.y);
                    break;
                }
            }
            break;

            case 2:
            {
                switch (life)
                {
                case 3:
                    g.DrawImage(imgs[0], this.x, this.y);
                    break;

                case 2:
                    g.DrawImage(imgs[2], this.x, this.y);
                    break;

                case 1:
                    g.DrawImage(imgs[1], this.x, this.y);
                    break;
                }
            }
            break;
            }
            //画完成就移除
            SingleObject.GetSingle().RemoveGameObject(this);
        }
Beispiel #13
0
        public void InitialGame()
        {
            //窗口的大小
            this.Size = new Size(GameWidth, GameHeight);

            //使窗口不可拖动大小
            this.MaximumSize = new Size(GameWidth, GameHeight);
            this.MinimumSize = new Size(GameWidth, GameHeight);

            //不显示窗口最大化及最小化按钮
            this.MaximizeBox = false;
            this.MinimizeBox = false;

            this.Text = "TankGame";

            this.BackColor = Color.Black;

            SingleObject.GetSingle().AddGameObject(new PlayerTank(200, 200, 1, 10, Direction.Down));
        }
Beispiel #14
0
 private void Form1_KeyUp(object sender, KeyEventArgs e)
 {
     SingleObject.GetSingle().PT.KeyUp(e);
 }
Beispiel #15
0
        public void InitialMap()
        {
            #region 画砖头
            for (int i = 0; i < 10; i++)
            {
                SingleObject.GetSingle().AddGameObject(new Wall(30 + i * 15, 100));          //T 的一横
                SingleObject.GetSingle().AddGameObject(new Wall(97, 100 + i * 15));          //T 的一竖

                SingleObject.GetSingle().AddGameObject(new Wall(195 + i * 7, 235 - i * 15)); //A 的一撇
                SingleObject.GetSingle().AddGameObject(new Wall(258 + i * 7, 100 + i * 15)); //A 的一捺
            }

            for (int i = 0; i < 6; i++)
            {
                SingleObject.GetSingle().AddGameObject(new Wall(225 + i * 15, 190));//A 的一横
            }

            for (int i = 0; i < 10; i++)
            {
                SingleObject.GetSingle().AddGameObject(new Wall(351 + i * 7, 235 - i * 15));//N 的三笔
                SingleObject.GetSingle().AddGameObject(new Wall(414 + i * 7, 100 + i * 15));
                SingleObject.GetSingle().AddGameObject(new Wall(477 + i * 7, 235 - i * 15));

                SingleObject.GetSingle().AddGameObject(new Wall(570, 100 + i * 15));//K的三笔
                SingleObject.GetSingle().AddGameObject(new Wall(570 + i * 8, 160 - i * 8));
                SingleObject.GetSingle().AddGameObject(new Wall(570 + i * 9, 160 + i * 9));
            }

            #endregion

            #region 画草地
            SingleObject.GetSingle().AddGameObject(new Grass(0, 441));
            for (int i = 0; i < 2; i++)
            {
                SingleObject.GetSingle().AddGameObject(new Grass(i * 30, 471));
                SingleObject.GetSingle().AddGameObject(new Grass(30 + i * 30, 501));
                SingleObject.GetSingle().AddGameObject(new Grass(60 + i * 30, 531));

                SingleObject.GetSingle().AddGameObject(new Grass(664 + i * 30, 535));
                SingleObject.GetSingle().AddGameObject(new Grass(694 + i * 30, 505));
                SingleObject.GetSingle().AddGameObject(new Grass(724 + i * 30, 475));
            }
            SingleObject.GetSingle().AddGameObject(new Grass(754, 445));
            #endregion

            #region 画钢铁墙
            for (int i = 0; i < 4; i++)
            {
                SingleObject.GetSingle().AddGameObject(new SteelWall(i * 15, 547));
                SingleObject.GetSingle().AddGameObject(new SteelWall(i * 15, 532));

                SingleObject.GetSingle().AddGameObject(new SteelWall(769 - i * 15, 550));
                SingleObject.GetSingle().AddGameObject(new SteelWall(769 - i * 15, 535));
            }
            for (int i = 0; i < 2; i++)
            {
                SingleObject.GetSingle().AddGameObject(new SteelWall(i * 15, 517));
                SingleObject.GetSingle().AddGameObject(new SteelWall(i * 15, 502));

                SingleObject.GetSingle().AddGameObject(new SteelWall(769 - i * 15, 520));
                SingleObject.GetSingle().AddGameObject(new SteelWall(769 - i * 15, 505));
            }
            #endregion

            #region 画水
            SingleObject.GetSingle().AddGameObject(new Water(500, 300));
            SingleObject.GetSingle().AddGameObject(new Water(530, 300));
            SingleObject.GetSingle().AddGameObject(new Water(500, 330));
            SingleObject.GetSingle().AddGameObject(new Water(530, 330));
            #endregion

            #region 鹰

            SingleObject.GetSingle().AddGameObject(new Symbol(362, 515));

            int tmp = 332;
            for (int i = 0; i < 8; i++)
            {
                tmp++;
                SingleObject.GetSingle().AddGameObject(new Wall(tmp + i * 15, 485));
                SingleObject.GetSingle().AddGameObject(new Wall(tmp + i * 15, 501));
            }
            tmp = 516;
            for (int i = 0; i < 3; i++)
            {
                tmp++;
                SingleObject.GetSingle().AddGameObject(new Wall(333, tmp + i * 15));
                SingleObject.GetSingle().AddGameObject(new Wall(349, tmp + i * 15));
            }
            for (int i = 0; i < 3; i++)
            {
                SingleObject.GetSingle().AddGameObject(new Wall(429, 517 + i * 16));
                SingleObject.GetSingle().AddGameObject(new Wall(445, 517 + i * 16));
            }
            #endregion
        }
Beispiel #16
0
 /// <summary>
 /// 用于开火
 /// </summary>
 public override void Fire()
 {
     SingleObject.GetSingle().AddGameObject(new EnemyBullet(this, 10, 10, 1));
 }
Beispiel #17
0
 public override void DrawBlood()
 {
     SingleObject.GetSingle().AddGameObject(new Blood(this.X, this.Y - 20, this.Life, this.EnemyTankType));
 }
Beispiel #18
0
 public override void DrawBlood()
 {
     SingleObject.GetSingle().AddGameObject(new Blood(this.X, this.Y - 20, this.Life, 3));//默认可以挨三炮
 }
Beispiel #19
0
 public override void Born()
 {
     SingleObject.GetSingle().AddGameObject(new TankBorn(this.X, this.Y));
 }
Beispiel #20
0
 private void TankClient_KeyDown(object sender, KeyEventArgs e)
 {
     SingleObject.GetSingle().PT.KeyDown(e);
 }
Beispiel #21
0
 private void TankClient_Paint(object sender, PaintEventArgs e)
 {
     SingleObject.GetSingle().Draw(e.Graphics);
 }