0

How can i break from the loop when the first warrior has the health of 0. Currently when the warriors health is under 0 they still strike the opponent. Please find attached my picture.

public void StrikeOpponent(Warrior one, Warrior two)
    {

        while (one.Health > 0 && two.Health > 0)
        {

            two.Strike = rnd.Next(1, 100);
            one.Health = one.Health - two.Strike;
            Console.WriteLine("{0} dealt {1} damage", one.Name, two.Strike);
            Console.WriteLine("{0}s health is {1}", one.Name, one.Health);

            one.Strike = rnd.Next(1, 100);
            two.Health = two.Health - one.Strike;
            Console.WriteLine("{0} dealt {1} damage", two.Name, one.Strike);
            Console.WriteLine("{0}s health is {1}", two.Name, two.Health);
        }


    }

enter image description here

Alexia
  • 83
  • 1
  • 8
  • 1
    Do you mean `if (one.Health == 0) break;` ??? – John Wu May 30 '18 at 04:36
  • 2
    I think you want to wrap the second set of statements in an additional if statement, checking that one's health is greater than zero. Or what John Wu said, in between. – pinkfloydx33 May 30 '18 at 04:37

0 Answers0