コード例 #1
0
        /// <summary>
        /// left and right walls boundary check
        /// if a missile goes past gdi boundaries
        /// then remove them in main form code
        /// </summary>
        /// <param name="foe"></param>
        /// <returns></returns>
        public static bool boundaryCheckLeftRIght(missile foe)
        {
            //null check
            if (foe == null)
            {
                return(false);
            }

            // if past gdi walls return its location and have it removed in main
            return((foe.Where().X < (0 + foe.radius * 2)) || (foe.Where().X > (_drawer.ScaledWidth + foe.radius * 2)));
        }
コード例 #2
0
        /// <summary>
        /// top and bottom boundary check
        /// if a missile goes past gdi boundaries(left and right walls)
        /// then remove them in main form code
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        public static bool BoundaryCheckUpDown(missile arg)
        {
            //null check
            if (arg == null)
            {
                return(false);
            }

            // if past gdi walls return its location and have it removed in main
            return((arg.Where().Y < 0) || (arg.Where().Y > _drawer.ScaledHeight));
        }
コード例 #3
0
 /// <summary>
 /// explosion method to determine if explosion is done or not
 /// </summary>
 /// <param name="arg"></param>
 /// <returns></returns>
 public static bool Explosion(missile arg)
 {
     //if explosion radius' alpha value is less then or equal to 10
     //the explosion is done happening
     if (arg.alpha <= 10)
     {
         return(true);
     }
     //otherwise explosion is still happening
     else
     {
         return(false);
     }
 }
コード例 #4
0
        /// <summary>
        /// the main event for game code
        /// does everything needed for game to run
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Timer_Tick(object sender, EventArgs e)
        {
            Point pt;

            missile.boomRadius = boomTrackBar.Value;
            labelBommVal.Text  = boomTrackBar.Value.ToString();

            //add enemy missiles to list and update label
            if (foemissiles.Count < missilesUpDown.Value)
            {
                missile newMissile = new missile();
                foemissiles.Add(newMissile);
                missilsIN += 1;
            }

            //colilsion check
            List <missile> colided = friendlyMissile.Intersect(foemissiles).ToList();

            //remove all colided missiles
            //also update score and update counter for removed missiles
            foreach (missile item in colided)
            {
                while (foemissiles.Remove(item))
                {
                    score += 100;
                    gone  += 1;
                }
            }

            //remove any missiles outside of boundaries
            friendlyMissile.RemoveAll(missile.Explosion);
            missile.Loading = true;
            foemissiles.RemoveAll(missile.boundaryCheckLeftRIght);

            // if missile reaches bottom of gdi lives --
            if (foemissiles.RemoveAll(missile.BoundaryCheckUpDown) >= 1)
            {
                lives -= 1;
            }

            // and a "bunker" where frindly misslies spawn
            CDrawer.AddCenteredRectangle(CDrawer.ScaledWidth / 2, CDrawer.ScaledHeight, 30, 30, Color.Green);
            CDrawer.AddText($"Lives {lives} Score {score}", 60, Color.Cyan);

            // update labels
            labelmissIN.Text    = missilsIN.ToString();
            labelDestroyed.Text = gone.ToString();
            labelFriend.Text    = friendlyIN.ToString();
            labelKD.Text        = KD.ToString();

            //update k/d ratio as long as there is at least 1 missle on screen
            if (friendlyIN > 0)
            {
                KD = (double)Math.Round(Convert.ToDecimal((missilsIN / friendlyIN)), 2);
            }

            missile.Loading = false;//start rending in missiles and effects

            //movment for enemy missiles
            foreach (missile item in foemissiles)
            {
                item.move();
                item.DrawMissiles();
            }

            //movment for friendly missiles
            foreach (missile item in friendlyMissile)
            {
                //bool for friend?
                item.move();
                item.DrawMissiles();
            }

            //on a left click spawn a friendly missile and update label
            if (CDrawer.GetLastMouseLeftClick(out pt))
            {
                friendlyMissile.Add(new missile(pt));
                friendlyIN++;
            }

            //when adjusting timerinterval stop the game
            //adjust interval and resume game
            if (timer1.Enabled)
            {
                timer1.Stop();
            }
            this.timer1.Interval = (int)intervalUpDown.Value;
            timer1.Start();

            //if a game over happens
            //set game over state, stop the timer
            //and display game over text
            if (currentState == eGameState.Over)
            {
                currentState   = eGameState.Unstarted;
                timer1.Enabled = false;
                timer1.Stop();
                missile.Loading = true;
                CDrawer.AddText("GAME OVER", 60, Color.Cyan);
                missile.Loading = false;
            }

            //if lives 0 game is over
            if (lives == 0)
            {
                currentState = eGameState.Over;
            }
        }