来帮帮我呗!谢谢
#include <stdio.h>#include <stdlib.h>
#include <time.h>
void play();
void getguess_num(int);
int getinitlevel();
int getrnd_num(int);
main(){
char ch;
clrscr();
printf("do you want to play this game?(y or n)");
scanf("%c",&ch);
switch(ch){
case 'y':
case 'Y':
play();
break;
}
getchar();
printf("please any key to exit game!");
getchar();
}
void play(){
int now_level, rnd_num;
char play_continue;
clrscr();
printf("*****************************************************\n");
printf("**************wellcome to play this game*************\n");
printf("**please input choose level you want to play!(1-10)**\n");
printf("*****************************************************\n");
now_level = getinitlevel();
do{
rnd_num = getrnd_num(now_level);
printf("\n");
printf("the level is:%d,you guess_num is between:0 - %d\n",now_level,now_level *10);
printf("the guess_num is:%d\n",rnd_num);
getguess_num(rnd_num);
now_level ++;
printf("Do you want to continue?(y or n)");
getchar();
scanf("%c",&play_continue);
}while((play_continue == 'y' || play_continue == 'Y') && now_level <= 10);
printf("------------------------------------------------------------\n");
printf("-------- Bye-bye wellcome you next visit ------------------\n");
printf("------------------------------------------------------------\n");
}
int getinitlevel(){
int level;
printf("please input you choose level!(1-10)\n");
do{
printf("Init level:");
scanf("%d",&level);
if(level < 1 || level > 10){
printf("the Init levle is error! please choose again!(1-10)\n");
getchar();
}
}while(level < 1 || level > 10);
return level;
}
int getrnd_num(int now_level){
int num, rnd_num;
num = 10 * now_level;
rnd_num = rand()%num;
return rnd_num;
}
void getguess_num(int rnd_num){
int guess_num;
long begin_time, end_time;
printf("please input your guess_num:\n");
begin_time = time(NULL);
scanf("%d",&guess_num);
while(guess_num != rnd_num){
if (guess_num > rnd_num){
printf("please input a num little than %d\n", guess_num);
}
else{
printf("please input a num bigger than %d\n", guess_num);
}
scanf("%d",&guess_num);
}
end_time = time(NULL);
if((end_time - begin_time) <= 120s){
printf("you use %ds to guess\n",end_time -begin_time);
}
}
这是一个猜数游戏 顺利猜对能自己增加难度可以运行,现在我想在这里面加一个功能:比如突然有事关掉了这个界面怎样做才能使下次玩得时候接着玩下去 ?