Пример #1
0
 /// <summary>
 /// Missile intersectswith EnemyShip
 /// </summary>
 private void MissileHitEnemyShip()
 {
     if (enemyShipFleet.EnemyShips.Count > 0 && missileFleet.Missiles.Count > 0)
     {
         for (int i = 0; i < missileFleet.Missiles.Count; i++)
         {
             for (int j = 0; j < enemyShipFleet.EnemyShips.Count; j++)
             {
                 if (missileFleet.Missiles[i].GetRectangle().IntersectsWith(enemyShipFleet.EnemyShips[j].GetRectangle()))
                 {
                     GlobalVariable.PlaySound(GlobalVariable.explode4);
                     Point explosionLocation = new Point(missileFleet.Missiles[i].Position.X, missileFleet.Missiles[i].Position.Y);
                     missileFleet.Missiles.Remove(missileFleet.Missiles[i]);
                     if (j > 1 && enemyShipFleet.EnemyShips[j].CouldDropBomb) //only last column give drop bomb rights  此处有漏洞(比如打中中间的敌舰,会有两个敌舰同时丢炸弹),需修正 it might be bug here
                     {
                         enemyShipFleet.EnemyShips[j - 1].CouldDropBomb = true;
                     }
                     enemyShipFleet.EnemyShips.Remove(enemyShipFleet.EnemyShips[j]);
                     enemyShipCount++;
                     PlayExplosionEffect(explosionLocation);
                     break;
                 }
             }
         }
     }
     else if (enemyShipFleet.EnemyShips.Count == 0)
     {
         enemyShipFleet.Alive = true;
     }
 }
Пример #2
0
        //Timer1 Tick event handler
        private void Timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                bufferGraphics.DrawImage(bufferBackImage, 0, 0, Width, Height);
                manager.Run();
                graphics.DrawImage(bufferImage, 0, 0, Width, Height);

                lblEnemyShipCount.Text = manager.GetEnemyShipCount().ToString();
                lblBombCount.Text      = manager.GetBombCount().ToString();

                //check EnemyShipFleet is over
                if (manager.CheckEnemyShipFleetLife())
                {
                    timer1.Enabled = false;
                    GlobalVariable.PlaySound(GlobalVariable.tr_holo_congrats);
                    MessageBox.Show("Congratulate, You destroyed all of the EnemyShip...");
                    pictureBoxReplay.Visible = true;
                    isStart = false;
                }
                else
                {
                    // Check any EnemyShip whether reach bottom line except MotherShip top
                    if (manager.IsEnemyShipReachBottomLine())
                    {
                        timer1.Enabled = false;
                        GlobalVariable.PlaySound(GlobalVariable.ctwin);
                        MessageBox.Show("oops...The EnemyShip has been caught you");
                        pictureBoxReplay.Visible = true;
                        isStart = false;
                    }
                }

                //check MotherShip whether hit all bombs
                if (manager.CheckMotherShipLife() == 0)
                {
                    timer1.Enabled = false;
                    GlobalVariable.PlaySound(GlobalVariable.ctwin);
                    MessageBox.Show("oops...You have been hit by Bomb");
                    pictureBoxReplay.Visible = true;
                    isStart = false;
                }
                else if (manager.CheckMotherShipLife() == -1) //MotherShip is over
                {
                    timer1.Enabled = false;
                    GlobalVariable.PlaySound(GlobalVariable.ctwin);
                    MessageBox.Show("oops...You have been hit by EnemyShip");
                    pictureBoxReplay.Visible = true;
                    isStart = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #3
0
 /// <summary>
 /// Start Game
 /// </summary>
 private void InitializeStartGame()
 {
     GlobalVariable.PlaySound(GlobalVariable.letsgo);
     timer1.Enabled                = true;
     isStart                       = true;
     pictureBoxStart.Visible       = false;
     pictureBoxLogo.Visible        = false;
     pictureBoxInstruction.Visible = false;
     pictureBox3.Visible           = false;
     lblEnemyShip.Visible          = true;
     lblEnemyShipCount.Visible     = true;
     lblBomb.Visible               = true;
     lblBombCount.Visible          = true;
 }
Пример #4
0
 /// <summary>
 /// MotherShip intersectswith EnemyShip
 /// </summary>
 private void MotherShipHitEnemyShip()
 {
     if (enemyShipFleet.EnemyShips.Count > 0)
     {
         for (int i = 0; i < enemyShipFleet.EnemyShips.Count; i++)
         {
             if (enemyShipFleet.EnemyShips[i].GetRectangle().IntersectsWith(motherShip.GetRectangle()))
             {
                 GlobalVariable.PlaySound(GlobalVariable.explode4);
                 motherShip.AliveStatus = -1;
             }
         }
     }
 }
Пример #5
0
        /// <summary>
        /// Initialize Game Default states
        /// </summary>
        private void InitializeGameDefault()
        {
            GlobalVariable.PlaySound(GlobalVariable.game_music);
            pictureBoxReplay.Visible  = false;
            lblEnemyShip.Visible      = false;
            lblEnemyShipCount.Visible = false;
            lblBomb.Visible           = false;
            lblBombCount.Visible      = false;
            pictureBox3.Image         = Properties.Resources.VolumeOn;
            GlobalVariable.boundries  = ClientSize;
            random  = new Random();
            isStart = false;

            graphics        = CreateGraphics();
            bufferImage     = new Bitmap(Width, Height);
            bufferBackImage = new Bitmap(Properties.Resources.A10073);
            BackgroundImage = bufferBackImage; //when open game to display background
            bufferGraphics  = Graphics.FromImage(bufferImage);
            manager         = new Manager(bufferGraphics, random);
        }
Пример #6
0
 /// <summary>
 /// Missile intersectswith Bomb
 /// </summary>
 private void MissileHitBomb()
 {
     if (enemyShipFleet.Bombs.Count > 0 && missileFleet.Missiles.Count > 0)
     {
         for (int i = 0; i < missileFleet.Missiles.Count; i++)
         {
             for (int j = 0; j < enemyShipFleet.Bombs.Count; j++)
             {
                 if (missileFleet.Missiles[i].GetRectangle().IntersectsWith(enemyShipFleet.Bombs[j].GetRectangle()))
                 {
                     GlobalVariable.PlaySound(GlobalVariable.explode4);
                     Point explosionLocation = new Point(missileFleet.Missiles[i].Position.X, missileFleet.Missiles[i].Position.Y);
                     missileFleet.Missiles.Remove(missileFleet.Missiles[i]);
                     enemyShipFleet.Bombs.Remove(enemyShipFleet.Bombs[j]);
                     bombCount++;
                     PlayExplosionEffect(explosionLocation);
                     break;
                 }
             }
         }
     }
 }
Пример #7
0
 private void PlaySoundMouseHover()
 {
     GlobalVariable.PlaySound(GlobalVariable.tutor_msg);
 }