Example #1
0
        public void FireOnInvaders(Invader[] invaders)
        {
            for (int index = 0; index < invaders.Length; index++)
            {
                Invader invader = invaders[index];
                // Do stuff with invader
            }

            foreach (Invader invader in invaders)
            {
                if (invader.IsActive && _location.InRangeOf(invader.Location, _range))
                {
                    if (IsSuccessfulShot())
                    {
                        invader.DecreaseHealth(_power);

                        if (invader.IsNeutralized)
                        {
                            Console.WriteLine("Neutralized an invader!");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Shot at and missed an invader.");
                    }


                    break;
                }
            }
        }
Example #2
0
        public void FireOnInvaders(Invader[] invaders)
        {
            const int range = 1;

            foreach (Invader invader in invaders)
            {
                if (invader.IsActive && _location.InRangeOf(invader.Location, _range))
                {
                    if (IsSuccessfulShot())
                    {
                        invader.DecreaseHealth(_damage);
                        Console.WriteLine("Damage is done to invader");

                        if (invader.IsNeutralized)
                        {
                            Console.WriteLine("Invader is DEAD.");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Missed.");
                    }

                    break;
                }
            }
        }
Example #3
0
        public void FireOnInvaders(Invader[] invaders)
        {
            foreach (Invader invader in invaders)
            {
                if (invader.IsActive && _location.InRangeOf(invader.Location, _range))
                {
                    if (IsSuccessfulShot())
                    {
                        invader.DecreaseHealth(_power);
                        Console.WriteLine("Shot at and hit an invader!");

                        if (invader.IsNeutralized)
                        {
                            Console.WriteLine("Neutralized an invader!");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Shot at and missed and invader.");
                    }

                    break;
                }
            }
        }
Example #4
0
 public void FireOnInvaders(Invader[] invaders)
 {
     foreach (Invader invader in invaders)
     {
         // Do stuff with invader
         if (invader.IsActive && _location.InRangeOf(invader.Location, Range))
         {
             if (IsSuccessfuleShot())
             {
                 invader.DecreaseHealth(Power);
             }
             break;
         }
     }
 }
Example #5
0
 public void FireOnInvaders(Invader[] invaders)
 {
     foreach (Invader invader in invaders)
     {
         //Checks whether the invader is active and within the declared range of 1 and if so fires upon it
         if (invader.IsActive && _location.InRangeOf(invader.Location, Range))
         {
             if (IsSuccesfulShot())
             {
                 //decreases health of the invader by 1
                 invader.DecreaseHealth(Power);
                 Console.WriteLine("Shot at and hit an invader!");
             }
             else
             {
                 Console.WriteLine("Shot at and missed an invader.");
             }
             break;
         }
     }
 }
Example #6
0
        public void FireOnInvaders(Invader[] invaders)
        {
            /*int i = 0;
             * while(i < invaders.Length)
             * {
             *  Invader invader = invaders[i];
             *
             *  i++;
             * }*/

            /*for(int i=0; i < invaders.Length; i++)
             * {
             *  Invader invader = invaders[i];
             *
             * }*/

            foreach (Invader invader in invaders)
            {
                if (invader.IsActive && _location.InRangeOf(invader.Location, _range))
                {
                    if (IsSuccessfulShot())
                    {
                        invader.DecreaseHealth(_power);
                        if (invader.IsNeutralized)
                        {
                            Console.WriteLine("Neutralized an invader!");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Shot at and missed an invader!");
                    }
                    break;
                }
            }
        }
        public void FireOnInvaders(IInvader[] invaders)
        {
            foreach (IInvader invader in invaders)
            {
                if (invader.IsActive && _location.InRangeOf(invader.Location, Range))
                {
                    if (IsSuccessfulShot())
                    {
                        invader.DecreaseHealth(Power);

                        if (invader.IsNeutralized)
                        {
                            Console.WriteLine("Neutralized an invader at " + invader.Location + "!");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Shot at and MISSED an invader.");
                    }

                    break;
                }
            }
        }
Example #8
0
        public void FireOnInvaders(IInvader[] invaders)
        {
            foreach (IInvader invader in invaders)
            {
                if (invader.IsActive && _location.InRangeOf(invader.Location, Range))
                {
                    if (IsSuccessfulShot())
                    {
                        invader.DecreaseHelth(Power);


                        if (invader.IsNeutralized)
                        {
                            WriteLine("Neutralized Invader!!! at  " + invader.Location);
                        }
                    }
                    else
                    {
                        WriteLine("Shot at and missed an invader. ");
                    }
                    break;
                }
            }
        }
Example #9
0
        // Will need a check to ensure the tower is not on the path

        // Method to shoot on invaders.
        // Will list through all the invaders in range and "shoot" each of them.
        // ie decrease their health by 1.
        // Takes an array of Invaders as parameter.
        public void FireOnInvader(Invader[] invaders)
        {
            //// Initialise the range of the tower in the method
            //const int range = 1;
            //// We chose to declare the constant in the class instead.

            //// Can use a while loop to do this.
            //int i = 0;
            //while (i < invaders.Length)
            //{
            //	Invader invader = invaders[i];
            //	// Makes an instance of an invader corresponding to the invader in the array at the given index.
            //	i++;
            //	Increment the index.
            //	// This is followed by the code that checks if an invader is in range.
            //}

            //// Can use a for loop as well to be more concise.
            //// for loops take three arguments:
            //// Initialising the index.
            //// Boolean condition (loop will iterate while it is true).
            //// index increment.
            //for (int i = 0; i < invaders.Length; i++)
            //{
            //	Invader invader = invaders[i];
            //	// This is followed by the code that checks if an invader is in range.
            //}
            //// This can be further simplified using a foreach loop

            // Using a foreach loop
            foreach (Invader invader in invaders)
            {
                // Code that checks if an invader is active and is in range.
                if (invader.IsActive || _location.InRangeOf(invader.Location, _range))
                {
                    // First check if the tower successfully hits or misses the target
                    // Only decrease the health of the enemy if the tower hits
                    if (IsSuccessfulShot())
                    {
                        // Decrease the health of the invader
                        invader.DecreaseInvaderHealth(_damage);
                        // We want the tower to only shoot at one invader at a time.
                        // So once the above method is called, we increment the loop index by breaking out of the loop.

                        //// Print to the console to indicate the successful shot
                        //Console.WriteLine("Shot and hit an invader!");
                        //// Later decided to move this to the DecreaseHeath() method.

                        // Print to the console if invader is neutralised
                        if (invader.IsNeutralized)
                        {
                            Console.WriteLine("Invader has been successfully neutralized!");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Shot and missed an invader!");
                    }
                    break;
                }
            }
        }