给代码加上注释 while (gameover == false) { cout << endl << "下一天:----------------------------" << endl; for (int i = 1; i <= 4; i++) { if (i == 1 && (life[l1] >= 0 or life[l2] >= 0)) { cout << "狼人:" << endl; srand((unsigned)time(NULL)); die = rand() % 6; while (name[die] == "狼人" || life[die] == -1) die = rand() % 6; life[die]--; cout << "狼人杀了" << name[die] << endl; } if (i == 2 && life[y] >= 0) { cout << "预言家:" << endl; cout << "预言完毕" << endl; } if (i == 3 && life[n] >= 0) { cout << "女巫:" << endl; int dor; srand((unsigned)time(NULL)); dor = rand() % 3; if (dor == 0) { die_potions = rand() % 6; while (name[die_potions] == "女巫" || life[die_potions] <= 0) die_potions = rand() % 6;
时间: 2024-02-10 14:14:01 浏览: 76
飞机空战小游戏planewar(dev-c++开发纯字符输出模式)
// 这段代码是一个游戏主循环,只要游戏没有结束就会一直运行
while (gameover == false)
{
// 输出下一天的开始
cout << endl << "下一天:----------------------------" << endl;
// 循环遍历4个角色
for (int i = 1; i <= 4; i++)
{
// 如果当前是狼人的回合,并且至少有两个狼人还活着
if (i == 1 && (life[l1] >= 0 or life[l2] >= 0))
{
cout << "狼人:" << endl;
// 随机选择一个还活着的非狼人角色
srand((unsigned)time(NULL));
die = rand() % 6;
while (name[die] == "狼人" || life[die] == -1) die = rand() % 6;
// 减少所选角色的生命值
life[die]--;
cout << "狼人杀了" << name[die] << endl;
}
// 如果当前是预言家的回合,并且预言家还活着
if (i == 2 && life[y] >= 0)
{
cout << "预言家:" << endl;
cout << "预言完毕" << endl;
}
// 如果当前是女巫的回合,并且女巫还活着
if (i == 3 && life[n] >= 0)
{
cout << "女巫:" << endl;
// 随机选择一个操作
int dor;
srand((unsigned)time(NULL));
dor = rand() % 3;
// 如果选择使用毒药
if (dor == 0)
{
// 随机选择一个还活着的非女巫角色
die_potions = rand() % 6;
while (name[die_potions] == "女巫" || life[die_potions] <= 0)
die_potions = rand() % 6;
}
}
}
}
阅读全文