gpt4 book ai didi

c++ - 虽然循环条件不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 14:45:17 28 4
gpt4 key购买 nike

嘿,基本上我希望玩家和狼群互相攻击,直到对方死亡。但是 while 循环是无限的,所以显然不满足条件。但是我看不出这个 if ( choice1 == 1)//if 语句在整个游戏中出现的问题,以允许用户在游戏中通过选择进行交互。

while((Status.health != 0) && (Wolves.health != 0) )
{
int playerAttack = Status.strength + hitPoints() + Rock.attack;
cout<< "This is the player attack" << playerAttack;
Wolves.health = Wolves.health - playerAttack;
cout << "This is the wolves health" << Wolves.health;
if (Wolves.health <= 0)
{
cout << "\nThe wolves are dead\n ";
}
int wolfAttack = Wolves.attack + hitPoints();
Status.health - wolfAttack;
if(Status.health <= 0)
{
gameOver();
}// print out of object health.
}

有人可以帮忙吗?

最佳答案

比较:

Wolves.health = Wolves.health - playerAttack;

对比

Status.health - wolfAttack;

注意到有什么不同吗?

关于c++ - 虽然循环条件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12806359/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com