tags:

views:

105

answers:

4

right now im trying to make it so ive got 1 character and 3 enemies if my character dies its suppossed to give game over or something but i cant make it to work(if enemies dies it works tho i dont know why)

here is what im doing bool Exit = false; bool CharDead = false;

        Heroe Heroe1 = p.ElementAt(0);
        Enemigo Enemigo1 = l.ElementAt(0);
        Enemigo Enemigo2 = l.ElementAt(1);
        Enemigo Enemigo3 = l.ElementAt(2);
        a.Agregar(comienza);
        List<Items> item = new List<Items>();
        do
        {
            if (Heroe1.HP > 0)
                AccionesHeroe1(l, p);

            if (Enemigo1.HP > 0)
                AccionesEnemigo1(l, p);

            if (Enemigo2.HP > 0)
                AccionesEnemigo2(l, p);

            if (Heroe1.HP > 0)
                AccionesHeroe1(l, p);
            else
                CharDead = true;
            if (Enemigo3.HP > 0)
                AccionesEnemigo3(l, p);

            if (Heroe1.HP <= 0)
            {
                CharDead = true;
            }
            if (Enemigo1.HP <= 0 && Enemigo2.HP <= 0 && Enemigo3.HP <= 0)
            {
                Exit = true;
            }

        } while (Exit == false || CharDead == false);
+6  A: 

Your ending condition is:

 (Exit == false || CharDead == false);

This will only exit when CharDead AND Exit are both true.

You probably want to rework it to be:

 (Exit == false && CharDead == false);

This way, as soon as Exit is not false or CharDead is not false, you'll exit.

Reed Copsey
Makenshi
beat me by 30 seconds. ill remove mine and upvote yours
Russ Bradberry
Eric Lippert
+1  A: 

I think you want to change your while loop expression to

do
{
} while(!Exit && !CharDead)
lfoust
+1  A: 

change

while (Exit == false || CharDead == false);

to

while (Exit == false && CharDead == false);
Ragepotato
A: 

This would work too, right?

while(!(Exit || CharDead));
Bryan Ross
Yes that would also work.
Jason D