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;