【发布时间】:2014-07-04 06:20:33
【问题描述】:
我正在用 c++ 编写刽子手,它也接受来自用户的命令(以便他们可以看到线索并退出游戏)。
我目前正在执行命令,但似乎无法使其工作。我被困在一个帮助命令上,该命令使用pause() 函数让用户阅读文本。
暂停功能似乎不起作用,即使它在程序的早期工作过。
到目前为止的代码
这里是代码:HelloWorld.cpp
void pause( string msg = "Press enter to continue..." ){
cout << msg;
cin.ignore();
}
// game loop.
do {
correctLetters = 0;
nl();
showLives(lives);
nl(5);
showWordGuessed(wordGuessed);
nl(1);
cout << "Guess a letter (type /help to see commands): ";
cin >> guess;
if (guess.size() == 1){
for (int i = 0;i < 5;i++){
if (word[i] == guess) wordGuessed[i] = word[i];
}
} else if (guess[0] == '/'){
if (guess == "/ans"){
} else if (guess == "/clue"){
} else if (guess == "/help"){
nl();
cout << "Typing /ans will show you the answer and quit the game.\n";
cout << "Typing /clue will show you one unknown letter.\n";
cout << "Typing /guess will allow you to guess the entire word.\n";
cout << "Typing /hangman will quit the game.\n";
cout << "Typing /help will show you this help message.\n\n";
pause("Press enter to continue playing...");
} else if (guess == "/guess"){
} else if (guess == "/hangman"){
return 0;
} else {
}
} else {
nl();
}
for (int i = 0;i < 5;i++){
if (wordGuessed[i] == word[i]) correctLetters++;
}
win = ((correctLetters == 5) ? win = true : win = false);
} while (!win);
cout << "you win";
【问题讨论】:
-
请edit你的问题有一个更有意义的标题(主题)。 “为什么我的 C++ 程序不起作用?”绝对没有信息,对于在搜索结果中找到它的未来读者肯定不会有用。谢谢。
标签: c++ function while-loop do-while