Right now I'm trying to make it so I've got 1 character and 3 enemies if my character dies 开发者_如何学运维it's supposed to give game over or something but I can't make it to work (if enemies die it works tho I don't know why).
Here is what I'm 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);
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.
I think you want to change your while loop expression to
do
{
} while(!Exit && !CharDead)
change
while (Exit == false || CharDead == false);
to
while (Exit == false && CharDead == false);
This would work too, right?
while(!(Exit || CharDead));
精彩评论