printf("\n\nExiting the game, please wait!\n");//正在退出游戏,请稍等
Sleep(100);
break;
}
}
}
复制代码
用户选择 2
此时表现游戏帮助,由于在 iChoose 为 0 分支内,采用了 break 语句跳出循环,故在此分支内依旧用 if 判断,而不采用 else if 判断
int main(void)
{
while (true)
{
...
//帮助
if (2 == iChoose)
{
printf("\n\nThe game has primary, intermediate, advanced and custom modes\n");
printf("A certain number of mines are randomly arranged in the minefield\n");
printf("The player needs to find all the blocks that are not mines as soon as possible, but do not step on the mines.\n\n\n");
Sleep(2000);
continue;
}
}
}
复制代码
用户选择其他选项
此时为无效输入,由于在 iChoose 为 2 分支内,采用了 continue 语句来竣事此次循环,进入下一次循环,故在此分支内依旧用 if 判断,而不采用 else if 判断
int main(void)
{
while (true)
{
...
//无效输入
if (iChoose > 2)
{
printf("\n\nInvalid input\n\n");//输入无效
Sleep(500);
continue;
}
}
}
复制代码
用户选择 1
此时开始游戏,以上分支均未跑到的话,那用户就是选择 1 了,此处无需判断,直接实现
此处将游戏部分封装在了 Play 函数内,直接调用,调用竣事后代表游戏竣事,随即询问用户是否再来一局:
如若不来,则退出循环,再在外层循环判断一下,进而退出外层循环
如若需要再来一局,则继承循环,调用 Play 函数,进行游戏
int main(void)
{
...
int iiChoose;
//游戏
while (true)
{
//PlayMenu();//无等级选择,故无此函数
Play();
printf("Do you want another game? 1 Yes, other no");//是否再来一局,1是,其他否