//Use link to figure out which invaders should be able to return fire
        public void ReturnFire(int wave, Random random)
        {
            if (wave + 1 == enemyShots.numberOfShots())
            {
                return;
            }

            if (random.Next(10) < 10 - wave)
            {
                return;
            }

            //Linq query to extract the invader to return fire
            var theShootingInvaders = (from invader in invaders
                                       group invader by invader.Location.X
                                       into invaderGroup
                                       orderby invaderGroup.Key descending
                                       select invaderGroup);


            if (invaders.Count() > 0)
            {
                //Gets the first invader in each column last will take the closest invaders while first while take the invaders in the back
                Invader theShooter = theShootingInvaders.ElementAt(random.Next(theShootingInvaders.Count())).Last <Invader>();

                Fire(theShooter);
            }
        }
Exemple #2
0
        public void Fire()
        {
            //Centralize the origin of the shot to the center front of the ship
            Point gunOfShip = new Point(location.X + image.Width / 2 - 2, location.Y - image.Height);

            //Only allow addition of shots if the total number of shots by the player is less than 5
            if (playerShots.numberOfShots() < 5)
            {
                playerShots.Add(new Shot(gunOfShip, true, boundaries));
            }
        }
        public void CheckForCollisions(Display scoreBoard)
        {
            for (int i = 0; i < playerShots.numberOfShots(); i++)
            {
                for (int j = 0; j < invaders.Count(); j++)
                {
                    if (invaders.ElementAt <Invader>(j).Area.Contains(playerShots.ElementAt(i).Area) == true)
                    {
                        playerShots.Remove(i);
                        scoreBoard.Score = invaders.ElementAt <Invader>(j).Score;
                        invaders.RemoveAt(j);
                        InvadersLeft = -1;

                        break;
                    }
                }
            }
        }
Exemple #4
0
        public bool CheckForCollisions()
        {
            for (int i = 0; i < enemyShots.numberOfShots(); i++)
            {
                if (Area.Contains(enemyShots.ElementAt(i).Area) == true)
                {
                    Alive = false;
                    enemyShots.Remove(i);
                    return(Alive);
                }

                else
                {
                    Alive = true;
                }
            }

            return(Alive);
        }