Beispiel #1
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();
        }
Beispiel #2
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();
                }
            }
        }