好的,所以我正在尝试制作一个非常简单的文字角色扮演游戏,但我遇到了问题。我不知道我可以使用什么样的循环来循环这段代码:
getline(cin, response);
if(response == "Pick up the gun")
{
cout << "You pick up the gun.\n";
cout << "Knock down the door with it? (Y/N)\n";
getline(cin, response);
if(response == "Y")
{
cout << "The door opens.\n";
cout << "You see a zombie.\n";
cout << "You see an open window.\n";
cout << "What do you do?\n";
getline(cin, response);
if(response == "Shoot the zombie")
{
cout << "The zombie dies and it attracts other zombies.\n";
cout << "GAME OVER!\n";
cin.get();
return 0;
}
else if(response == "Jump out the window")
{
cout << "The zombie does not hear you and you safely make it out!\n";
cout << "VICTORY!\n";
cin.get();
return 0;
}
}
else if(response == "N")
{
}
}
else if(response == "Open the door")
{
cout << "It appears to be locked.\n";
}
因此,如果他们弄错了(例如,他们选择“开门”,它只会说它已锁定,并且由于某种原因它会结束程序。我希望用户能够选择不同的选择,而不是拥有它只是空白或损坏或结束等)它只会循环,但是当我尝试它时,它要么不会结束程序,只是让它我可以输入并且无论如何都不会发生任何事情,或者它绝对是垃圾邮件100次和我不能做任何事情等等。它很奇怪。那我怎么能这样做呢?谢谢!