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; } } }
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; } } }
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; } } }
public void FireOnInvaders(IInvader[] invaders) { foreach (IInvader invader in invaders) { if (invader.IsActive && _location.InRangeOf(invader.Location, Range)) { invader.DecreaseHealth(Power); } } }
// 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; } } }
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; } } }
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"); } } }
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; } } }
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; } } }
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; } } }
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; } } }
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"); } } } }
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; } } }
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; } } }
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; } } }
public bool IsInDanger(MapLocation location, int range) => _location.InRangeOf(location, range);