Ejemplo n.º 1
0
 /// <summary>
 /// border collision detect
 /// </summary>
 public override void MoveToBorder()
 {
     if (this.Y >= 900)
     {
         //remove enemy game object;
         SingeOblect.GetSingle().RemoveGameObject(this);
     }
     //if small plane's y >= 200
     if (this.EnemyType == 1 && this.Y >= 200)
     {
         //small is on the left
         if (this.X >= 0 && this.X <= 240)
         {
             this.X += r.Next(0, 50);
         }
         else
         {
             //small is on the right
             this.X -= r.Next(0, 50);
         }
     }
     else
     {
         //medium and big plan accelerate
         this.Speed += 1;
     }
 }
Ejemplo n.º 2
0
        public override void Draw(Graphics g)
        {
            switch (this.Type)
            {
            case 1:
                for (int i = 0; i < imgsSmall.Length; i++)
                {
                    g.DrawImage(imgsSmall[i], this.X, this.Y);
                }
                break;

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

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

            default:
                break;
            }

            //after playing images, remove images from the scene
            SingeOblect.GetSingle().RemoveGameObject(this);
        }
 public static SingeOblect GetSingle()
 {
     if (_single == null)
     {
         _single = new SingeOblect();
     }
     return(_single);
 }
 public override void MoveToBorder()
 {
     if (this.Y <= 0 || this.Y >= 850)
     {
         //remove bullet object
         SingeOblect.GetSingle().RemoveGameObject(this);
     }
 }
        public override void Draw(Graphics g)
        {
            for (int i = 0; i < imgsPlayer.Length; i++)
            {
                g.DrawImage(imgsPlayer[i], this.X, this.Y);
            }

            SingeOblect.GetSingle().RemoveGameObject(this);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// enemy die
        /// </summary>
        public override void IsOver()
        {
            if (this.Life <= 0)
            {
                //explosion effect
                SingeOblect.GetSingle().AddGameObjects(new EnemyExplosion(this.X, this.X, this.EnemyType));

                //remove enemy plane
                SingeOblect.GetSingle().RemoveGameObject(this);
            }
        }
        /// <summary>
        /// initialize game
        /// </summary>
        private void InitialGame()
        {
            //initialize Background object
            SingeOblect.GetSingle().AddGameObjects(new Background(0, -850, 20));

            //initialize Player object
            SingeOblect.GetSingle().AddGameObjects(new Player(200, 200, 20, 1, Direction.Up));

            //initialize enemy object
            InitializeEnemyPlane();
        }
        /// <summary>
        /// initialize enemy plane
        /// </summary>
        private void InitializeEnemyPlane()
        {
            for (int i = 0; i < 4; i++)
            {
                SingeOblect.GetSingle().AddGameObjects(new Enemy(r.Next(0, this.Width), -200, r.Next(1, 3)));
            }

            //10% boss plan appears
            if (r.Next(1, 101) > 90)
            {
                SingeOblect.GetSingle().AddGameObjects(new Enemy(r.Next(0, this.Width), -200, 3));
            }
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            //window continue redraw
            this.Invalidate();

            //check the number of enemy plane
            if (SingeOblect.GetSingle().enemyList.Count < 2)
            {
                //re-initialize enemy
                InitializeEnemyPlane();
            }

            //collision check
            SingeOblect.GetSingle().Collision();
        }
        private void timer2_Tick(object sender, EventArgs e)
        {
            if (isStart)
            {
                //if game starts
                playTime++;
                if (playTime == 20)
                {
                    //time end, stop game
                    isStart = false;

                    //send result to server
                    //transfer score to byte, send to server
                    byte[] buffer = Encoding.Default.GetBytes(SingeOblect.GetSingle().Score.ToString());

                    socket.Send(buffer);
                }
            }
        }
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            //draw background
            SingeOblect.GetSingle().BG.Draw(e.Graphics);

            if (isStart)
            {
                //draw other game objects
                SingeOblect.GetSingle().DrawGameObject(e.Graphics);

                //draw score
                String score = SingeOblect.GetSingle().Score.ToString();
                e.Graphics.DrawString(score, new Font("微软雅黑", 20, FontStyle.Bold), Brushes.Red, new Point(10, 10));
            }

            if (isGameOver)
            {
                //draw result
                e.Graphics.DrawString(result, new Font("微软雅黑", 20, FontStyle.Bold), Brushes.Red, new Point(100, this.Height / 2 - 100));
            }
        }
Ejemplo n.º 12
0
 /// <summary>
 /// enemy fire
 /// </summary>
 public override void Fire()
 {
     SingeOblect.GetSingle().AddGameObjects(new BulletEnemy(this, this.EnemyType));
 }
 /// <summary>
 /// player die
 /// </summary>
 public override void IsOver()
 {
     SingeOblect.GetSingle().AddGameObjects(new PlayerExplosion(this.X, this.Y));
 }
 /// <summary>
 /// player fire
 /// </summary>
 public override void Fire()
 {
     SingeOblect.GetSingle().AddGameObjects(new BulletPlayer(this, 20, 1));
 }
 private void Form1_MouseDown(object sender, MouseEventArgs e)
 {
     //player shoot
     SingeOblect.GetSingle().Player.MouseDownLeft(e);
 }
 /// <summary>
 /// give the x and y of cursor to x and y of player
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Form1_MouseMove(object sender, MouseEventArgs e)
 {
     SingeOblect.GetSingle().Player.MoveWithMouse(e);
 }