我一直在为我的高级 RAP 项目开发一款游戏,直到最近我才开始使用这个循环。当玩家或敌人的生命值等于 0 时,我需要一种方法来迭代它。我不希望它们都等于 0,这两个示例都这样做。我已经尝试过几种方式重写它,但它不起作用。感谢所有为此提供帮助的人。
while (!(enemyHealth == 0 || playerHealth == 0)
{ //START WHILE
Console.WriteLine("[System:] Here are the list of moves that you can do:\n1)Punch\n2)Kick\n3)Round House Kick");
Console.WriteLine();
decision = Console.ReadLine();
Console.WriteLine();
decisionNumber = int.Parse(decision);
if (decisionNumber < 1 || decisionNumber > 3)
{ //STARTS IF
throw new Exception();
} //ENDS IF
else
{ //STARTS ELSE
enemyHealth = enemyHealth - attackNumber;
playerHealth = playerHealth - enemyAttackNumber;
Console.WriteLine();
Console.WriteLine("[System:] Enemy Health: " + enemyHealth + "\nYour Health: " + playerHealth);
} //ENDS ELSE
} //ENDS WHILE
while (enemyHealth > 0 || playerHealth > 0)
{ //START WHILE
Console.WriteLine("[System:] Here are the list of moves that you can do:\n1)Punch\n2)Kick\n3)Round House Kick");
Console.WriteLine();
decision = Console.ReadLine();
Console.WriteLine();
decisionNumber = int.Parse(decision);
if (decisionNumber < 1 || decisionNumber > 3)
{ //STARTS IF
throw new Exception();
} //ENDS IF
else
{ //STARTS ELSE
enemyHealth = enemyHealth - attackNumber;
playerHealth = playerHealth - enemyAttackNumber;
Console.WriteLine();
Console.WriteLine("[System:] Enemy Health: " + enemyHealth + "\nYour Health: " + playerHealth);
} //ENDS ELSE
} //ENDS WHILE
任何人都可以解决这个问题,因为我遇到了重大问题。