我正在创建一个将用完C++命令提示符的游戏。如何重新启动C++命令提示符应用程序?
这款游戏叫做PIG。你正在对抗电脑,你的目标是通过掷骰子达到100 GAME SCORE。如果你掷出1,你的回合结束,你没有增加任何分数。如果您掷出任何其他号码,它会被添加到您的“分数”中。滚动后,您可以选择再次滚动或“保持”。持有会将您的“比分”添加到您的“比赛分数”中,并将该回合传给下一名玩家。
一切都按照我希望的方式工作,但现在我正在尝试创建一个playagain()函数,在游戏结束时询问用户是否希望再次玩游戏。如果他们这样做,应用程序重新启动,并将零的所有变量。如果他们不这样做,程序就会退出。
这里是我的问候,我的问题:
if(comp_score == 100){
char ans;
cout << "Your opponent has reached a score of 100 and has won! Would you like to play again? [y/n] ";
cin >> ans;
if(ans == 'y'){
/*restarts application and zero's all variables*/
playagain();
} else if(ans == 'n'){ exit(); }}
if(play_score == 100){
char ans;
cout << "You have reached a score of 100 and have won! Would you like to play again? [y/n] ";
cin >> ans;
if(ans == 'y'){
/*restarts application and zero's all variables*/
playagain();
} else if(ans == 'n'){ exit(); }
}
TIA!
你知道['while'loops](http://msdn.microsoft.com/en-us/library/0c98k0ks.aspx)吗? – clcto 2014-10-28 21:55:14
当我有多个功能时,如何使用'while'循环,并且游戏在每个循环之间传递? @clcto – Welsh4588 2014-10-28 21:57:35
您将信息从一个函数传递给另一个函数:'do {/*....*/ playAgain = PromptPlayAgain(); } while(playAgain);'例如。 – clcto 2014-10-28 21:59:17