Example #1
0
        public void FireOnInvaders(Invader[] invaders)
        {
            //int index = 0;

            //while (index < invaders.Length)
            //{
            //    Invader invader = invaders[index];

            //    index ++;
            //}

            //for (int index = 0; index < invaders.Length; index ++)
            //{
            //    Invader invader = invaders[index];
            //}
            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.IsDead)
                        {
                            Console.WriteLine("Kill an invader!");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Shot at the missed an ivader.");
                    }
                    break;
                }
            }
        }
        public void FireOnInvaders(IInvader[] invaders)
        {
            foreach (IInvader invader in invaders)
            {
                if (invader.IsActive && _location.InRangeOf(invader.Location, Range))
                {
                    if (IsSuccessfulShot())
                    {
                        invader.DecreaseHealth(Power);
                        Console.WriteLine("Hit");
                        if (invader.IsNeutralized)
                        {
                            Console.WriteLine("Destroyed an invader at " + invader.Location);
                        }
                        else
                        {
                            Console.WriteLine("Miss");
                        }
                    }

                    break;
                }
            }
        }