初写代码贪吃蛇

初写代码贪吃蛇

ID:83045506

大小:15.29 KB

页数:26页

时间:2022-11-26

上传者:无敌小子
初写代码贪吃蛇_第1页
初写代码贪吃蛇_第2页
初写代码贪吃蛇_第3页
初写代码贪吃蛇_第4页
初写代码贪吃蛇_第5页
初写代码贪吃蛇_第6页
初写代码贪吃蛇_第7页
初写代码贪吃蛇_第8页
初写代码贪吃蛇_第9页
初写代码贪吃蛇_第10页
资源描述:

《初写代码贪吃蛇》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

//////////////////////////////mainO#include//#include#include//gotoXY,sleep;//kbhit();//exit⑴;#include#include#include#include#include/zstatement,h”#include/,function,h”intmain(){fpscore=fopen(^highestscore.dat","r");fgets(HighestScoreName,30,fpscore);fscanf(fpscore,&nhighestscore);fclose(fpscore);while(true)system("cis");//gotoXY(0,0);srand(time(NULL));

1funmapdefine(maparr,'');//funprintf();pchar[np]=&maparr[I][J];funProduceFood();while(true)]while((tim++)%speed==0)funoperation();if(again~l){again=0;speedjudge=0;tim=0;spe=0;speed=9999000;spee=l;direction=0;1=12;J=12;np=O;

2npl=O;score-0;Grade-1;scorejudge=O;break;return0;)

3头文件functionvoidfunProduceFood()intnjudge=0;intnjudgel=0;intnjudge2=0;for(inti=0;i

4judge2=njudge2;}}voidfunmapdefine(char[][24],charc){for(intn=0;n

5voidfunprintf()if(score%100==0&&score!=0&&score!=scorejudge)Grade++;scorejudge=score;}for(intnk=0;nk

6;score,Grade);if(Grade!=spee&&speed!=l){speeds(speed-(Grade*(990000)));spee++;}for(intni=0;nimaparr[ni][nt]);//if(ni==12||ni—13)

7//{//if(ni==12)//printfC|\t英?雄?毗%s|HighestScoreName);//if(ni==13)//printfC|\t最?高?分?:毗%d

8|nhighestscore);//)//elseprintf("[

9I");}printf('\b");for(intnk=0;nk

10intfundirection(intni,intnj)switch(direction)case2:case0:if(nijudgel)direction=3;return(ni-judgel);)break;case3:case1:if(nj

11return(judge2-nj);if(nj>judge2)direction=2;return(nj-judge2);)})voidfunoperationl()(maparr[I][J]=,@';funProduceFood();if(np—495)np=~l;if(np1—496)npl=0;pchar[++np]=&maparr[I][J];if(np>nlength)

12*pchar[npl++]=,,;funprintf();gotoXY(0,0);//gotoXY(0,0);}voidfunkbhit(){if(kbhit())]charch=getch();switch(ch)]case'8’:case72:if(direction-3){if(speed!=l)spe=speed;speed=l;

13speedjudge=l;elseif(speedjudge-l)speed=spe;speedjudge-0;idirection=3;break;case'4':case75:if(direction--2)(if(speed!-l)spe=speed;speed=l;speedjudge-1;Ielseif(speedjudge==l)(speed=spe;speedjudge-0;

14Idirection=2;break;case'5':case80:case'2':if(direction—l){if(speed!=l)spe-speed;speed=l;speedjudge=l;)elseif(speedjudge--1)(speed-spe;speedjudge=0;}direction-1;break;

15case'6’:case77:if(direction"。){if(speed!=l)spe-speed;speed=l;speedjudge=l;}elseif(speedjudge-1)(speed=spe;speedjudge=O;}direction=0;break;case'':system("pause");gotoXY(0,0);default:break;

16)}elseif(speedjudge-l){speed=spe;speedjudge=0;voidfunoperation(){/*if(judge-0)judge=fundirection(I,J);judge―;*/funkbhitO;〃从洙?键口盘i上?读d取?方?向6switch(direction)]case0:maparr[I][J]='*';if(J==(Ik-l))J=T;if(maparr[I][++J]=-)]npl—;

17score+=10;if(maparr[I][J]~,*')gotoXY(57,6);if(score>nhighestscore)(nhighestscore=score;printf("牛£逼?,?破?纪i录?了?!?〃);gotoXY(57,7);printf(〃英?雄?,?留?下?名?字?:毗〃);scanf('%s”,HighestScoreName);fpscore=fopen(^highestscore.dat","w");fprintf(fpscore,"%s

18",HighestScoreName);fprintf(fpscore,"%d”,nhighestscore);fclose(fpscore);gotoXY(57,8);printf("playagainpressenterorpress5!!”);Ielse(

19gotoXY(57,6);printf("youarelost!?");gotoXY(57,7);printf(*playagainpressenterorpress5!!”);Sleep(2000);if(kbhit())charcyn;cyn=getch();if(cyn==13||cyn--,5,)(gotoXY(0,0);again=l;break;)elseexit(1);}exit(1);)funoperation1();break;

20case1:maparr[I][J]=,*';I=-l;if(maparr[++I][J]==,$,)]npl一;score+=10;}if(maparr[I][J]=='*,)]gotoXY(57,6);if(score>nhighestscore)(nhighestscore=score;printf(〃牛£逼?,?破?纪i录?了?!?〃);gotoXY(57,7);printf(〃英?雄?,?留?下?名?字?:一”);scanf('%s”,HighestScoreName);fpscore=fopen(''highestscore.dat","w");fprintf(fpscore,"%s

21",HighestScoreName);

22fprintf(fpscore,"%d”,nhighestscore);fclose(fpscore);gotoXY(57,8);printf(z/playagainpressenterorpress5!!”);else(gotoXY(57,6);printf("youarelost!?");gotoXY(57,7);printf("playagainpressenterorpress5!!”);}Sleep(2000);if(kbhit())(charcyn;cyn=getch();if(cyn~131|cyn~,5,)]gotoXY(0,0);again=l;

23break;)elseexit(1);exit(1);)funoperationl();break;case1:maparr[I][J]='*';if(J==0)J=Ik;if(maparr[I][—J]=-)]gotoXY(0,0);npl—;score+=lO;}if(maparr[I][J]==,*,)]gotoXY(57,6);

24if(score>nhighestscore)(nhighestscore=score;printf(〃牛£逼?,?破?纪i录?了?!?”);gotoXY(57,7);printf(〃英?雄?,?留?下?名?字?:一〃);scanf(,/%s,/,HighestScoreName);fpscore=fopen(^highestscore.dat","w");fprintf(fpscore,"%s

25",HighestScoreName);fprintf(fpscore,"%d”,nhighestscore);fclose(fpscore);gotoXY(57,8);printf("playagainpressenterorpress5!!”);}else(gotoXY(57,6);printf("youarelost!?");gotoXY(57,7);printf("playagainpressenterorpress5!!”);

26}Sleep(2000);if(kbhit())charcyn;cyn:getch();if(cyn==13||cyn=二'5")gotoXY(0,0);again=l;break;)elseexit(1);)exit(1);)funoperationl();break;case1:

27maparr[I][J]二';if(I==0)I=Ik;if(maparr[―I][J]==,$')npl—;score+=10;}if(maparr[I][J]~,*')]gotoXY(57,6);if(score>nhighestscore)(nhighestscore=score;printf(〃牛£逼?,?破?纪i录?了?!?〃);gotoXY(57,7);printf(〃英?雄?,?留?下?名?字?:附〃);scanfHighestScoreName);fpscore=fopenC'highestscore.dat","w");fprintf(fpscore,"%s

28",HighestScoreName);

29fprintf(fpscore,"%d”,nhighestscore);fclose(fpscore);gotoXY(57,8);printf(/zplayagainpressenterorpress5!!”);elsegotoXY(57,6);printf(*youarelost!?");gotoXY(57,7);printf(*playagainpressenterorpress5!!”);}Sleep(2000);if(kbhit())charcyn;cyn=getch();if(cyn~131|cyn=='5,){gotoXY(0,0);again=l;break;

30)elseexit(1);}exit(1);)funoperationl();break;default:break;}

31头文件statementcharmaparr[24][24]={0};intIk=24;intnhighestscore=20;charHighestScoreName[30]=“吴a小?军ii”;FILE*fpscore;int1=12,J=12;〃ncount=lintjudgel=0,judge2=0;〃judgel,2保馈?存?食?物?位?置?intdirection=0,judge=0;〃judge自?动一运?行D时骸?控?制?用?intnp=0,npl=0,scorejudge=0;〃scorejudge控?制?等台?级?时骸?用?intscore=0,Grade=l;char*pchar[500]={0};intnlength=3;〃初?始?长0度8intagain=0;〃控?制?是?否?再ti来而?inttim=0;intspeed=18000000;〃控?制?速ti度eintspee=l;〃控?制?是?否?加6速ti

32intspe=O;〃控?制?主小动一加6速tiintspeedjudge-0;

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。
最近更新
更多
大家都在看
近期热门
关闭