Ejemplo n.º 1
0
        private void Restart_Click(object sender, EventArgs e)
        {
            AsteroidPositionTimer.Stop();

            StartGame.IsStarted  = false;
            destroyed            = false;
            Bomb.IsExploding     = false;
            Gift.IsRocketComming = false;
            Rocket.IsFired       = false;
            nukeCity             = false;

            Bomb.Life = 3;
            Bomb.Y    = -30;
            Gift.Y    = -30;

            BombPB.Hide();
            RocketPB.Hide();
            LaserPB.Hide();
            RedGift.Hide();
            GameOver.Hide();
            DashboardGiftLabel.Hide();

            Rocket.Count = 10;
            score        = -1;
            missCount    = 6;

            RocketCount(Rocket.Count);
            ScoreCounter();
            MissCounter();
            Lives.Show();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The logic implement movement of destroing asteroids and calculating using a timer
        /// This method chek if lives == 0 -> Game Over
        /// </summary>
        private void AnimationTimer_Tick(object sender, EventArgs e)
        {
            if (destroyedImageCounter > 1 && destroyed)
            {
                ExplodingAsteroid.Hide();
                destroyed             = false;
                destroyedImageCounter = 0;
            }
            else if (destroyed)
            {
                destroyedImageCounter++;
            }

            if (nukeCity && !destroyed)
            {
                if (nukeCloudCounter == 0)
                {
                    MissCounter();

                    if (missCount == 0)
                    {
                        AsteroidPositionTimer.Stop();
                        StartGame.IsStarted = false;

                        BombPB.Hide();
                        RedGift.Hide();
                        NukeCloud.Hide();
                        ExplodingAsteroid.Hide();
                        RocketPB.Hide();
                        RocketGift.Hide();
                        Lives.Hide();

                        GameOver.Show();
                    }

                    nukeCity           = true;
                    NukeCloud.Location = new Point(Bomb.X, Bomb.Y);
                    NukeCloud.Show();
                    PlaySound.PlayExplodeSound();

                    Bomb.Life = BombLife;
                    SpawnNewBomb();
                }
                else if (nukeCloudCounter > 10)
                {
                    NukeCloud.Hide();
                    AnimationTimer.Stop();
                    nukeCity = false;
                }

                nukeCloudCounter++;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Logic implement spawn a Asteroid.
        /// We get current Gift location X and if coordinates match with the asteroid, give it new random location x
        /// Chek while asteroid is spawn on other coordinates.
        /// And get new coordinates for Y
        /// </summary>
        private void SpawnNewBomb()
        {
            Bomb.X          = rnd.Next(BombPB.Width + 10, this.Width - BombPB.Width - 10);
            Bomb.Y          = -30;
            BombPB.Location = new Point(Bomb.X, Bomb.Y);

            int[] giftXLocation =
            {
                Gift.X - RedGift.Width,
                Gift.X + RedGift.Width
            };

            while (Bomb.X >= giftXLocation[0] && Bomb.X <= giftXLocation[1])
            {
                Bomb.X = rnd.Next(BombPB.Width + 10, this.Width - BombPB.Width - 10);
            }

            BombPB.Show();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Logic implement Destroying a Bomb
        /// Hide unnecessary pictures
        /// Show destroing animation, reset the constants and spawn new bomb.
        /// </summary>
        private void DestroyBomb()
        {
            PlaySound.PlayExplodeSound();
            BombPB.Hide();
            RocketPB.Hide();
            LaserPB.Hide();

            ExplodingAsteroid.Left = BombPB.Left - 10;
            ExplodingAsteroid.Top  = BombPB.Top - 20;
            ExplodingAsteroid.Show();

            destroyed        = true;
            nukeCity         = false;
            Bomb.IsExploding = false;
            Rocket.IsFired   = false;
            Bomb.Life        = 3;

            SpawnNewBomb();
            ScoreCounter();
            AnimationTimer.Start();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// The logic implement movement of gifts and asteroids and calculating using a timer
        /// </summary>
        private void AsteroidPositionTimer_Tick(object sender, EventArgs e)
        {
            /// <summary>
            /// Stop timer, when the game is not start with start buton
            /// </summary>
            if (!StartGame.GameIsStarted())
            {
                AsteroidPositionTimer.Stop();
            }

            /// <summary>
            /// If an asteroid and a gift appear at the same place, new coordinates are calculated
            /// </summary>
            if (Gift.ContentShowTyme > 0)
            {
                Gift.ContentShowTyme--;

                if (Gift.ContentShowTyme == 0)
                {
                    RocketGift.Hide();
                    DashboardGiftLabel.Hide();
                }
            }

            /// <summary>
            /// Look Rocket.cs class
            /// </summary>
            if (Rocket.IsFired)
            {
                Rocket.Move(RocketPB);
            }

            /// <summary>
            /// Chek count laser hits on asteroid and when asteroid is dead, hide Laser from the screen.
            /// </summary>
            if (Laser.TimeCounter > 0)
            {
                Laser.TimeCounter--;
            }
            else
            {
                LaserPB.Hide();
            }

            /// <summary>
            /// If asteroid is hiting by laser or rocket, we destroying him.
            /// </summary>
            if (Bomb.IsExploding)
            {
                DestroyBomb();
            }

            /// <summary>
            /// Set new coordinates on asteroid and show bomb.
            /// </summary>
            Bomb.Y         += 7;
            BombPB.Location = new Point(Bomb.X, Bomb.Y);
            BombPB.Show();

            /// <summary>
            /// Chek coordinates and explode asteroid random on screen.
            /// </summary>
            if (Bomb.Y >= rnd.Next(380, 470) && !Bomb.IsExploding)
            {
                nukeCity         = true;
                nukeCloudCounter = 0;
                AnimationTimer.Start();
            }

            /// <summary>
            /// If gift is hiting by laser or rocket, we destroying him.
            /// </summary>
            if (Gift.IsExploding)
            {
                DestroyGift();
            }

            /// <summary>
            /// Logic encompasses the movement and the disappearance of the gift when it's not hiting.
            /// </summary>
            if (isGiftVisible)
            {
                if (Gift.Y >= 700)
                {
                    isGiftVisible = false;
                    RedGift.Hide();
                }
                else
                {
                    Gift.Y          += 5;
                    RedGift.Location = new Point(Gift.X, Gift.Y);
                }
            }
            else
            {
                isGiftVisible = rnd.Next(0, 50) == 1;

                if (isGiftVisible)
                {
                    SpawnGift();
                }
            }
        }