public void applyMagnetForce(component e) { if ((e.zombieType == 'b') || (e.zombieType == 's')) { e.TakeDamage(25, 'm'); //this should remove the item from the zombie ->m for magnet, this will call removeitemfromzombie } }
public override int TakeDamage(int d, char plantType) { //now i need to hit item first component c1 = null; //no component // c1 = itemList.First(); //empty list returns null /*Unhandled Exception: System.InvalidOperationException: Sequence contains no elements * at System.Linq.Enumerable.First[TSource](IEnumerable`1 source) * at ConsoleApp1.Zombie.TakeDamage(Int32 d) in C:\Users\slaterweinstock\Documents\CS487\HW4\ConsoleApp1\ConsoleApp1\Zombie.cs:line 54 * at ConsoleApp1.Program.Main(String[] args) in C:\Users\slaterweinstock\Documents\CS487\HW4\ConsoleApp1\ConsoleApp1\Program.cs:line 26*/ if (itemList.Count == 0) //list is empty --> my fix due to the above error { health -= d; Die(); } else //if list isnt empty { c1 = itemList.First(); //item if (c1.isAlive() && d <= c1.health) { c1.TakeDamage(d, plantType); } else if (c1.isAlive() && d > c1.health) { int leftover = c1.TakeDamage(d, plantType); health -= leftover; } else { itemList.RemoveAt(0); //remove the item TakeDamage(d, plantType); //recursive call since item has been removed } } return(0); }
public void doDamage(int d, char plantType, component e) { e.TakeDamage(d, plantType); //need plant type char passed in }