예제 #1
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 an invader");
                    }

                    break;
                }
            }
        }
예제 #2
0
        public void FireOnInvaders(IInvader[] invaders)
        {
            foreach (IInvader invader in invaders)
            {
                // Do stuff with invader
                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;
                }
            }
        }
예제 #3
0
        public void FireOnInvaders(Invader[] invaders)
        {
            /* int index = 0;
             *
             * while (index < invaders.Length)
             * {
             *   Invader invader = invaders[index];
             *   // Do stuff with invader
             *
             *   index++;
             * }
             */

            /*  for (int i = 0; i < invaders.Length; i++)
             * {
             *    Invader invader = invaders[i];
             *    // Do stuff whith invader
             * }
             */
            foreach (Invader invader in invaders)
            {
                if (invader.IsActive && _location.InRangeOf(invader.Location, 1))
                {
                    invader.DecreaseHealth(1);
                    break;
                }
            }
        }
예제 #4
0
 public void FireOnInvaders(IInvader[] invaders)
 {
     foreach (IInvader invader in invaders)
     {
         if (invader.IsActive && _location.InRangeOf(invader.Location, Range))
         {
             invader.DecreaseHealth(Power);
         }
     }
 }
예제 #5
0
        // Builds method.
        // Takes one parameter,
        // an array from the class Invader.
        public void FireOnInvadors(IInvader[] invaders)
        {
            // Builds foreach loop.
            // Loops through every element in the array.
            foreach (IInvader invader in invaders)
            {
                // Builds if statement.
                // Checks to see if location is in range to the tower.
                if (invader.IsActive && _location.InRangeOf(invader.Location, Range))
                {
                    // Method call.
                    // Builds if statement.
                    if (IsSuccessfulShot())
                    {
                        // Method call
                        // using object name.
                        // Takes one parameter.
                        invader.DecreaseHealth(Power);
                        // Outputs to the console.


                        // Builds if statement.
                        // Method call
                        // using object name.
                        if (invader.IsNeutralized)
                        {
                            // Outputs to the console.
                            Console.WriteLine("Neutralized an invader" + invader.Location + "!");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Shot at and missed an invader.");
                    }

                    // If the invader is in range,
                    // it will decrease its health.
                    invader.DecreaseHealth(Power);
                    // Exits the loop.
                    break;
                }
            }
        }
예제 #6
0
 public void FireOnInvaders(IInvader[] invaders)
 {
     foreach (IInvader invader in invaders)
     {
         //Check if the tower's distance for each invader is less than the shooting range
         if (invader.IsActive && _location.InRangeOf(invader.Location, Range))
         {
             if (IsSucessfulShot())
             {
                 invader.DecreaseHealth(Power);
                 if (invader.IsNeutralized)
                 {
                     Console.WriteLine("Killed an invader at (" + invader.Location + ")");
                 }
             }
             break;
         }
     }
 }
예제 #7
0
 public void FireOnInvaders(Invader[] invaders)
 {
     foreach (var invader in invaders)
     {
         if (random.NextDouble() < Accuracy)
         {
             if (location.InRangeOf(invader.Location, FiringRange) && invader.IsActive)
             {
                 invader.DecreaseHealth(DamageAmount);
                 Console.WriteLine("Shot hit");
                 if (invader.IsDead)
                 {
                     Console.WriteLine("Invader killed");
                 }
                 break;                          // towers can only fire on one target at a time
             }
             Console.WriteLine("Shot missed");
         }
     }
 }
예제 #8
0
        public void FireOnInvaders(IInvader[] invaders)
        {
            //int index = 0;
            ////While Loop
            //while (index < invaders.Length)
            //{
            //    Invader invader = invaders[index];
            //    //Do stuff with invader

            //    index++;
            //}
            ////For Loop
            //for(int i = 0; i < invaders.Length; i++)
            //{
            //    Invader invader = invaders[i];
            //    //Do stuff with invader
            //}

            foreach (IInvader invader in invaders)
            {
                //Do stuff with invader
                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;
                }
            }
        }
예제 #9
0
 public void FireOnInvaders(Invader[] invaders)
 {
     foreach (Invader invader in invaders)
     {
         if (invader.isActive && _location.InRangeOf(invader.Location, _power))
         {
             if (isSuccessfulShot())
             {
                 invader.DecreateHealth(_range);
                 if (invader.isNeutralized)
                 {
                     Console.WriteLine("Invader has been neutralized");
                 }
             }
             else
             {
                 Console.WriteLine("Missed!");
             }
             break;
         }
     }
 }
예제 #10
0
 public void FireOnInvaders(Invader[] invaders)
 {
     foreach (Invader invader in invaders)
     {
         if (invader.IsActive && _location.InRangeOf(invader.Location, Range))
         {
             if (IsSuccessfulShot())
             {
                 invader.DecreaseHealth(Power, this.ToString());
                 if (invader.IsNeutralized)
                 {
                     Console.WriteLine(this.ToString() + " neutralized " + invader.ToString() + " at " + invader.Location + "!");
                 }
             }
             else
             {
                 Console.WriteLine(this.ToString() + " shot at and missed " + invader.ToString() + " at " + invader.Location + ".");
             }
             break;
         }
     }
 }
예제 #11
0
 public void FireOnInvaders(IInvader[] invaders) //loops through the invaders and shoot at them
 {
     foreach (IInvader invader in invaders)
     {
         if (invader.IsActive && _location.InRangeOf(invader.Location, Range)) //checks if the invader is active and in range of the tower
         {
             if (IsSuccessfulShot())                                           //if the accuracy is under .75 then it shoots successfully , otherwise it misses the target and retries for the next one
             {
                 invader.DecreaseHealth(Power);
                 if (invader.IsNeutralized)
                 {
                     Console.WriteLine("Neutralized an invader at " + invader.Location + " !");
                 }
             }
             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(string.Format("Neutralized an invader at {0}!", invader.Location));
                        }
                    }
                    else
                    {
                        Console.WriteLine("Shot at and missed an invader");
                    }

                    break;
                }
            }
        }
예제 #13
0
 public void FireOnInvadors(Invader[] invaders)
 {
     foreach (Invader invader in invaders)
     {
         if (invader.IsActive && _location.InRangeOf(invader.Location, _range))
         {
             if (this.IssuccessfulShot())
             {
                 invader.DecreaseHealth(_power);
                 Console.WriteLine("invader was hit");
                 if (invader.IsNeutralized)
                 {
                     Console.WriteLine("invader neutralized");
                 }
                 break;
             }
             else
             {
                 Console.WriteLine("missed");
             }
         }
     }
 }
예제 #14
0
 public void FireOnInvaders(IInvader[] invaders)
 {
     foreach (IInvader invader in invaders)
     {
         if (invader.IsActive && _location.InRangeOf(invader.Location, Range))
         {
             if (IsSuccessfulShot())
             {
                 Console.Write($"{this.ToString()} shot ");
                 invader.DecreaseHealth(Power);
                 if (invader.IsNeutralized)
                 {
                     Console.WriteLine($"   ** Neutralized {invader.ToString()} at {invader.Location}! **");
                 }
             }
             else
             {
                 Console.WriteLine($"{this.ToString()} fired and missed {invader.ToString()}");
             }
             break;
         }
     }
 }
예제 #15
0
        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.IsDead)
                        {
                            Console.WriteLine("You destroyed an invader at " + invader.Location);
                        }
                    }
                    else
                    {
                        Console.WriteLine("You missed an invader!");
                    }
                    break;
                }
            }
        }
예제 #16
0
        public void FireOnInvaders(IInvader[] invaders)
        {
            foreach (IInvader invader in invaders)
            {
                if (invader.IsActive && _location.InRangeOf(invader.Location, Range))
                {
                    if (IsShotSuccessful())
                    {
                        invader.Hit(Power);


                        if (invader.IsNeutralized)
                        {
                            Console.WriteLine("Invader neutralized at " + invader.Location + "!");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Shot and missed!");
                    }
                    break;
                }
            }
        }
예제 #17
0
 public bool IsInDanger(MapLocation location, int range) => _location.InRangeOf(location, range);