这是被调用的函数:
int onBattle(int level,char nomeheroi[20])
{
const char *monsternames[4][3] = {
{"Rat","Bat","Spider"},
{"Goblin","Orc","Dwarf"},
{"Dragon","Lich","Banshee"},
{"Demon","Hydra","Giant Spider"}
};
//printf("monster hp:%f , player hp:%f, player name:%s ",globalvar.monterhp, globalvar.playerhp,nomeheroi);
char opcaobattle;
rndMonster(level);
while((globalvar.monterhp > 0) || (globalvar.playerhp > 0)){
printf("Monster name:%s\n",monsternames[globalvar.monstercatego][globalvar.monsternivel]);
printf("Monster Life:%f\n",globalvar.monterhp);
printf("------------------------------------------\n");
printf("----------------BattleGround--------------\n");
printf("------------------------------------------\n");
printf("Player name:%s\n", nomeheroi);
printf("Player life:%f\n", globalvar.playerhp);
printf("----------------------------------------\n");
printf("------------------Menu------------------\n");
printf("----------------------------------------\n");
printf("A - Attack\n");
printf("D - Defend\n");
scanf("%c",&opcaobattle);
switch(opcaobattle)
{
case 'a':
danoPMonster();
break;
case 'd':
break;
}
}
if(globalvar.monterhp <= 0)
{
return 0;
}
else if(globalvar.playerhp <= 0)
{
return 1;
}
}
这就是发生的事情:
在停止 Scanf 之前,我在此代码中显示两次没有任何问题,我也尝试过 Do While 并且同样的事情发生有任何帮助吗?ps:那个 globalvar 是一个全局结构,是的,有一个值