我的代码现在可以正常工作了。 但是,当运行嵌套的for循环时,回合计数不会改变。 我哪里出问题了? 还有如何将健康状况的变化存储在各个变量中?
for (int round = 1; round <=30; round++)
{
int sorceressHealth = 30;// sets health
int wizardHealth = 30;
for (int x = 0; x <= ARRAYROW; x++) {
system("pause");
//Round begins
cout << endl << "Round " << round << " fight!" << endl;
//Sorceress draws card
cout << "Sorceress draws " << sorDeck[x].sName << endl;
//Card attacks Wizard
cout << sorDeck[x].sName << " deals " << sorDeck[x].sAttk << " damage to Wizard!" << endl;
//wizard draws card
cout << "Wizard draws " << wizDeck[x].wName << endl;
//Card attacks sorceress
cout << wizDeck[x].wName << " deals " << wizDeck[x].wAttk << " damage to Sorceress!" << endl;
cout << endl << "Sorceress has:" << sorceressHealth - wizDeck[x].wAttk << " Health" << endl; // displays health
cout << "Wizard has:" << wizardHealth - sorDeck[x].sAttk << " Health" << endl;
答案 0 :(得分:0)
要回答问题的第二部分,假设健康状况会持续下降,直到1个玩家的生命值降为0。(由于您现在正在实施该方法,因此每次执行内部For循环时,您重置了巫师和女巫的健康状况,因此使此要求毫无用处
在两个循环之外声明 wizardHealth 和 sorceressHealth
log
这样,每次迭代都将使用更新的变量,而不是30。(如果我对您的执行要求有误,请纠正我)
P.S您的外部(循环)循环在我的IDE上执行完美。我没看到问题。