Beispiel #1
0
 private void TimeWatcher_Tick(object sender, EventArgs e)
 {
     if (Tmins == 0 && Tsecs == 0)
     {
         TimeWatcher.Stop();
         EnemiesMover.Stop();
         BulletChecker.Stop();
         IntersectionsDetecter.Stop();
         this.KeyDown  -= new KeyEventHandler(Level1_KeyDown);
         StartStop.Text = "Start";
         Tsecs          = 2;
         Tmins          = 0;
         ClearCurrentWindow();
         if (IScore >= 3000)
         {
             GameResult("Winner");
         }
         else
         {
             GameResult("Loser");
         }
         return;
     }
     else if (Tmins >= 1 && Tsecs == 0)
     {
         Tmins--;
         Tsecs = 59;
     }
     else if (Tsecs > 0)
     {
         Tsecs--;
     }
     UpdateTime();
 }
Beispiel #2
0
        void GameResult(string result)
        {
            IntersectionsDetecter.Stop();
            TimeWatcher.Stop();
            EnemiesMover.Stop();
            RandomEnemyBullets.Stop();
            Form2 f = new Form2(result);

            f.Show();
        }
Beispiel #3
0
        private void EnemiesMover_Tick(object sender, EventArgs e)
        {
            if (Level == 1)
            {
                int S = Enemies.Count();
                for (int i = 0; i < S; i++)
                {
                    if ((Enemies[0].Location.X + 20) >= 1100)
                    {
                        for (int j = 0; j < S; j++)
                        {
                            Enemies[j].Dispose();
                            Enemies.Remove(Enemies[j]);
                            S--; j--;
                        }

                        EnemiesMover.Stop();
                        EnemiesPictureBoxesMaker();
                        EnemiesSpawner();
                        x_enemy = -600;
                        break;
                    }
                    Enemies[i].Location = new Point(Enemies[i].Location.X + 20, Enemies[i].Location.Y);
                }
            }
            else
            {
                int        S       = Enemies.Count();
                bool       warning = false;
                List <int> higher  = new List <int>();
                List <int> lower   = new List <int>();
                for (int i = 0; i < S; i++)
                {
                    if (Enemies[i].Location.X + Flip > 900 || Enemies[i].Location.X + Flip < -10)
                    {
                        warning = true;
                    }
                }

                if (warning)
                {
                    Flip *= -1;
                }
                else if (lower.Count == 0 && higher.Count == 0)
                {
                    foreach (PictureBox box in Enemies)
                    {
                        box.Location = new Point(box.Location.X + Flip, box.Location.Y);
                    }
                }
            }
        }
Beispiel #4
0
 private void EnemiesSpawner()
 {
     if (Level == 1)
     {
         Random rnd = new Random();
         for (int i = 0; i < 3; i++)
         {
             Enemies[i].Location = new Point(x_enemy, y_enemy);
             this.Controls.Add(Enemies[i]);
             x_enemy += rnd.Next(150, 400);
         }
         if (Enemies[2].Location.X > -200)
         {
             int n = Enemies[2].Location.X + 200;
             foreach (PictureBox box in Enemies)
             {
                 box.Location = new Point(box.Location.X - n, y_enemy);
             }
         }
         foreach (PictureBox box in Enemies)
         {
             this.Controls.Add(box);
         }
         EnemiesMover.Start();
     }
     else
     {
         int[] x = { 100, 400, 700, 250, 550, 850, 50, 350, 650 };
         int   y = 20;
         for (int i = 0; i < Enemies.Count(); i++)
         {
             Enemies[i].Location = new Point(x[i], y);
             if (i == 2 || i == 5)
             {
                 y += 110;
             }
         }
         foreach (PictureBox box in Enemies)
         {
             this.Controls.Add(box);
         }
         EnemiesMover.Start();
     }
 }
Beispiel #5
0
        private void IntersectionsDetecter_Tick(object sender, EventArgs e)
        {
            int CEnemies        = Enemies.Count();
            int CShipBullets    = ShipBullets.Count();
            int CEnemiesBullets = EnemiesBullets.Count();

            for (int i = 0; i < CEnemies; i++)
            {
                for (int j = 0; j < CShipBullets; j++)
                {
                    if (CEnemies == 0 || CShipBullets == 0)
                    {
                        break;
                    }
                    else if (Enemies[i].Bounds.IntersectsWith(ShipBullets[j].Bounds))
                    {
                        ScoreUpdater(Enemies[i]);
                        Enemies[i].Dispose();
                        ShipBullets[j].Dispose();
                        Enemies.Remove(Enemies[i]);
                        ShipBullets.Remove(ShipBullets[j]);
                        SoundPlayer player = new SoundPlayer(MaterialsDoc + @"\Sound\Explosion.wav");
                        player.Play();
                        CEnemies--;
                        if (i - 1 >= 0)
                        {
                            i--;
                        }
                        if (j - 1 >= 0)
                        {
                            j--;
                        }
                        CShipBullets--;
                    }
                }
            }
            CEnemiesBullets = EnemiesBullets.Count();
            if (Level == 2)
            {
                for (int i = 0; i < CEnemiesBullets; i++)
                {
                    for (int j = 0; j < CShipBullets; j++)
                    {
                        if (EnemiesBullets.Count() == 0 || CShipBullets == 0)
                        {
                            break;
                        }
                        if (EnemiesBullets[i].Bounds.IntersectsWith(ShipBullets[j].Bounds))
                        {
                            ScoreUpdater(EnemiesBullets[i]);
                            EnemiesBullets[i].Dispose();
                            ShipBullets[j].Dispose();
                            EnemiesBullets.Remove(EnemiesBullets[i]);
                            ShipBullets.Remove(ShipBullets[j]);
                            SoundPlayer player = new SoundPlayer(MaterialsDoc + @"\Sound\Explosion.wav");
                            player.Play();
                            CEnemiesBullets--;
                            if (i - 1 >= 0)
                            {
                                i--;
                            }
                            if (j - 1 >= 0)
                            {
                                j--;
                            }
                            CShipBullets--;
                        }
                    }
                }
                CEnemiesBullets = EnemiesBullets.Count();
                for (int i = 0; i < CEnemiesBullets; i++)
                {
                    if (EnemiesBullets[i].Bounds.IntersectsWith(SpaceShip.Bounds))
                    {
                        EnemiesMover.Stop();
                        BulletChecker.Stop();
                        IntersectionsDetecter.Stop();
                        RandomEnemyBullets.Stop();
                        WinOrLose.Stop();
                        GameResult("Loser");
                        break;
                    }
                }
            }
            if (Enemies.Count == 0 && Level == 1)
            {
                EnemiesPictureBoxesMaker();
                EnemiesSpawner();
            }
        }
Beispiel #6
0
 private void StartStopGame(object sender, EventArgs e)
 {
     if (StartStop.Text == "Start")
     {
         StartStop.Text = "Pause";
         if (Level == 1)
         {
             if (start)
             {
                 EnemiesSpawner();
                 start = false;
             }
             IntersectionsDetecter.Start();
             TimeWatcher.Start();
             EnemiesMover.Start();
             BulletChecker.Start();
             ScoreTimePan.Click += new EventHandler(BulletMaker);
             this.Click         += new EventHandler(BulletMaker);
             this.KeyDown       += new KeyEventHandler(Level1_KeyDown);
             this.ActiveControl  = null;
         }
         else
         {
             if (start)
             {
                 EnemiesSpawner();
                 start = false;
             }
             IntersectionsDetecter.Start();
             EnemiesMover.Start();
             BulletChecker.Start();
             ScoreTimePan.Click += new EventHandler(BulletMaker);
             this.Click         += new EventHandler(BulletMaker);
             this.KeyDown       += new KeyEventHandler(Level1_KeyDown);
             this.ActiveControl  = null;
             RandomEnemyBullets.Start();
             WinOrLose.Start();
         }
     }
     else
     {
         StartStop.Text = "Start";
         if (Level == 1)
         {
             IntersectionsDetecter.Stop();
             TimeWatcher.Stop();
             EnemiesMover.Stop();
             BulletChecker.Stop();
             ScoreTimePan.Click -= new EventHandler(BulletMaker);
             this.Click         -= new EventHandler(BulletMaker);
             this.KeyDown       -= new KeyEventHandler(Level1_KeyDown);
         }
         else
         {
             IntersectionsDetecter.Stop();
             EnemiesMover.Stop();
             BulletChecker.Stop();
             ScoreTimePan.Click -= new EventHandler(BulletMaker);
             this.Click         -= new EventHandler(BulletMaker);
             this.KeyDown       -= new KeyEventHandler(Level1_KeyDown);
             this.ActiveControl  = null;
             RandomEnemyBullets.Stop();
             WinOrLose.Stop();
         }
     }
 }