Example #1
0
 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
     }
 }
Example #2
0
        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);
        }
Example #3
0
        public void simulateCollisionDetection(int plant, component e)
        {
            if (plant == 1)
            {
                doDamage(25, 'r', e);
            }

            else if (plant == 2)      //watermelon
            {
                doDamage(30, 'o', e); //this is for the watermelon which will go over
            }

            else if (plant == 3) //magnet
            {
                applyMagnetForce(e);
            }

            else
            {
                Console.WriteLine("unrecognized shooter type");
            }
        }
Example #4
0
 public void doDamage(int d, char plantType, component e)
 {
     e.TakeDamage(d, plantType); //need plant type char passed in
 }
Example #5
0
 public override void RemoveItemFromZombie(component c1)
 {
     throw new NotImplementedException();
 }
Example #6
0
 public override void AddItemToZombie(component c1)
 {
     throw new NotImplementedException();
 }
Example #7
0
 public override void RemoveItemFromZombie(component c1)
 {
     itemList.Remove(c1);
 }
Example #8
0
        //public override void Add(Zombie z) //adding to zombie list
        //{
        //    itemList.Add(z);
        //}


        public override void AddItemToZombie(component c1)
        {
            itemList.Add(c1); //added component aka item
        }