升级版贪吃蛇
作者: Linx
时间:2019暑期
答辩说明:
答辩全是有c语言书写,其中涉及winds的api操作,多线程,随机函数等等。功能包括有:
- 1.登陆注册(采用文件保存的方式实现的数据库)
- 2.排行榜(对文件数据的操作)
- 3.难度设置以及计时系统(调节蛇的移动速度,计时游戏)
- 4.游戏中返回主菜单(游戏中按特定的键位可返回登陆页面)
- 5.三种游戏的模式
- 单蛇模式(普通贪吃蛇模式)
- 双蛇模式(控制两条蛇)
- 对战模式(双人对战,果实数量增多,可吃对方蛇,计时系统)
答辩内容
bool login(info temp){
info tmp;
FILE *fp;
fp = fopen("rank.txt","r");
if(fp==NULL){
printf("cannot open the files\n");
system("pause");
return -1;
}
while(fscanf(fp,"%s %s %d %d",tmp.name,tmp.password,&tmp.score,&tmp.DoubleScore)!=EOF){
if(strcmp(tmp.name,temp.name) == 0){
if(strcmp(tmp.password,temp.password) == 0){
NowGamer = tmp;
fclose(fp);
return true;
}
else{
fclose(fp);
return false;
}
}
}
NowGamer = temp;
fprintf(fp,"%s %s %d %d\n",temp.name,temp.password,temp.score,temp.DoubleScore);
fclose(fp);
return true;
}
if(NowGamer.score <= (SnakeLength-SNAKE_LENGTH)*10 + int((SnakeLength-SNAKE_LENGTH) / 5) * 10){
NowGamer.score = (SnakeLength-SNAKE_LENGTH)*10 + int((SnakeLength-SNAKE_LENGTH) / 5) * 10;
Psqrt(19,3,18,12);
Goto(26,13);
printf("再接再厉");
Goto(19,14);
printf("恭喜%s大侠,你创造了自己的新纪录!",NowGamer.name);
FILE *fin,*ftp;
info temp;
fin=fopen("rank.txt","r");
ftp=fopen("tmp.txt","w");
while(fscanf(fin,"%s %s %d %d",temp.name,temp.password,&temp.score,&temp.DoubleScore)!=EOF)
if( strcmp(temp.name,NowGamer.name) != 0 )
fprintf(ftp,"%s %s %d %d\n",temp.name,temp.password,temp.score,temp.DoubleScore);
fprintf(ftp,"%s %s %d %d\n",NowGamer.name,NowGamer.password,NowGamer.score,NowGamer.DoubleScore);
fclose(fin);
fclose(ftp);
remove("rank.txt");
rename("tmp.txt","rank.txt");
}else{
Psqrt(19,3,18,12);
Goto(26,13);
printf("不要放弃");
Goto(19,14);
printf("很遗憾%s大侠,你就差那么一点点!",NowGamer.name);
}
if(clock() - StartTime > DefaultTime * GameTime ) break;
if(WaitTime == 0)
{
int NewTime;
NewTime = Speed - (SnakeLength-SNAKE_LENGTH)*10;
if(NewTime >= 10)
WaitTime = NewTime;
else
WaitTime = 10;
}
10
WaitTime = NewTime;
else
WaitTime = 10;
}
收获与感悟
- 自己收获还是挺多的,一方面自己在暑假回顾了C语言,在一个方面自己懂得了一个游戏程序应该如何去设计。如何增加游戏体验感等等
- 我采用的是多线程实现的,我听学长他们说,如果是一条蛇的话,可是不使用多线程,但是使用多线程还是不错的,至少现在自己知道怎么去编写自定义的多线程了。
- 关于Windows库有了很深刻的理解,其中的api自己也熟悉了一部分,总的还说这个暑假还是过的很充实的。
写在最后的
Git下载链接