Пример #1
0
        /// <summary>
        /// Zombies move in a random direction. Since there's only one on
        /// the screen, we just track it using the PictureBox variable
        /// instead of a list. Obviously if you had multiple zombies, you'd
        /// probably want to use a list to make things MUCH easier.
        /// </summary>
        void MoveZombie()
        {
            for (int i = 0; i < sentinelPBList.Count; i++)
            {
                PictureBox enemy = sentinelPBList[i];
                // Skip if invisible (must be dead)
                if (enemy.Visible == false)
                {
                    return;
                }

                // Zombies change direction completely randomly and stay moving
                // in the new direction for 10 to 20 steps (frames).
                enemyStepsRemaining--;
                if (enemyStepsRemaining < 0)
                {
                    enemyDirection      = rand.Next(0, 10);
                    enemyStepsRemaining = rand.Next(15, 39);
                }

                switch (enemyDirection)
                {
                case 0:     //up
                    enemy.Top -= enemySpeed;
                    if (enemy.IsInsideOfForm() == false)
                    {
                        enemy.Top += enemySpeed;
                    }
                    break;

                case 1:     // right
                    enemy.Left += enemySpeed;
                    if (enemy.IsInsideOfForm() == false)
                    {
                        enemy.Left -= enemySpeed;
                    }
                    break;

                case 2:     // down
                    enemy.Top += enemySpeed;
                    if (enemy.IsInsideOfForm() == false)
                    {
                        enemy.Top -= enemySpeed;
                    }
                    break;

                case 3:     // left
                    enemy.Left -= enemySpeed;
                    if (enemy.IsInsideOfForm() == false)
                    {
                        enemy.Left += enemySpeed;
                    }
                    break;
                }
            }
        }
Пример #2
0
        private void TrackBadBullets()
        {
            for (int i = 0; i < badBulletList.Count; i++)
            {
                PictureBox badbullet = badBulletList[i];
                badbullet.Left -= badBulletSpeed;


                // Remove the bullet if it leaves the screen
                if (badbullet.IsInsideOfForm() == false)
                {
                    // remove it from both the List and from the Window's
                    // Controls collection.
                    badBulletList.Remove(badbullet);
                    this.Controls.Remove(badbullet);
                }

                // Kill THE good guy if the bullet hits him
                if (pictureBoxPlayer.IsTouching(badbullet))
                {
                    Death();
                    Close();
                }
            }
        }
Пример #3
0
        private bool CanMove(PictureBox pb)
        {
            if (pb.IsInsideOfForm() == false)
            {
                return(false);
            }


            return(true);
        }
Пример #4
0
        private void TrackBullets()
        {
            for (int i = 0; i < bulletList.Count; i++)
            {
                PictureBox bullet = bulletList[i];
                bullet.Left += bulletSpeed;

                // Remove the bullet if it leaves the screen
                if (bullet.IsInsideOfForm() == false)
                {
                    // remove it from both the List and from the Window's
                    // Controls collection.
                    bulletList.Remove(bullet);
                    this.Controls.Remove(bullet);
                }

                // Kill a bad guy if the bullet hits him
                for (int j = 0; j < allBadGuys.Count; j++)
                {
                    PictureBox badGuy = allBadGuys[j];

                    // Skip if invisible (already dead)
                    if (badGuy.Visible == false)
                    {
                        continue;
                    }


                    if (badGuy.IsTouching(bullet))
                    {
                        // remove the bullet from both the List and from the
                        // Window's Controls collection.
                        bulletList.Remove(bullet);
                        this.Controls.Remove(bullet);
                        this.Controls.Remove(badGuy);

                        // "Kill" the bad guy
                        badGuy.Visible = false;

                        // Add to list of dead bad guys and check for win
                        deadBadGuys.Add(badGuy);



                        break;
                    }
                }
            }
        }
Пример #5
0
 private bool CanMove(PictureBox pb)
 {
     if (pb.IsInsideOfForm() == false)
     {
         return(false);
     }
     foreach (var trees in trees)
     {
         if (pb.IsTouching(trees) == true)
         {
             return(false);
         }
     }
     return(true);
 }
Пример #6
0
        private void HandleDragonMove()
        {
            for (int i = 0; i < sentinelPBList.Count; i++)
            {
                PictureBox sentinel  = sentinelPBList[i];
                int        direction = sentinelDirList[i];


                // Skip if invisible (must be dead)
                if (sentinel.Visible == false)
                {
                    continue;
                }


                if (direction == 0)
                {
                    // up
                    sentinel.Top -= sentinelSpeed;
                }
                else
                {
                    // down
                    sentinel.Top += sentinelSpeed;
                }


                if (sentinel.IsInsideOfForm() == false)
                {
                    if (direction == 1)
                    {
                        sentinelDirList[i] = 0;
                    }
                    else
                    {
                        sentinelDirList[i] = 1;
                    }
                }
            }
        }