资源描述:
《贪吃蛇tc源代码》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、#include#include#include#include#defineLEFT0x4b00#defineRIGHT0x4d00#defineDOWN0x5000#defineUP0x4800#defineESC0x011b#defineN100inti,key;intspeed;voidGameOver();voidPlay();voiddwall();voidwall(intx,inty);intSpeed();structFOOD{intx;inty;intflag;}food;struc
2、tSnake{intx[N];inty[N];intnode;intdir;intlife;}snake;voidwall(intx,inty){intsizx=9;intsizy=9;setcolor(15);line(x,y,x+sizx,y);line(x,y+1,x+sizx-1,y+1);line(x,y,x,y+sizy);line(x+1,y,x+1,y+sizy-1);setcolor(4);line(x+1,y+sizy,x+sizx,y+sizy);line(x+2,y+sizy-1,x+sizx,y+sizy-1);line(x+sizx-1,y+2,x
3、+sizx-1,y+sizy-1);line(x+sizx,y+1,x+sizx,y+sizy);setfillstyle(1,12);bar(x+2,y+2,x+sizx-2,y+sizy-2);}voiddwall(){intj;for(j=50;j<=600;j+=10){wall(j,40);wall(j,451);}for(j=40;j<=450;j+=10){wall(50,j);wall(601,j);}}intSpeed(){intm;gotoxy(20,10);printf("level1");gotoxy(20,12);printf("level2
4、");gotoxy(20,14);printf("level3ttpleasechoose:");scanf("%d",&m);switch(m){case1:return60000;case2:return40000;case3:return20000;default:cleardevice();Speed();}}voidPlay(void){srand((unsignedlong)time(0));food.flag=1;snake.life=0;snake.dir=1;snake.x[0]=300;snake.y[0]=240;snake.x[1]=290;s
5、nake.y[1]=240;snake.node=2;do{while(!kbhit()){if(food.flag==1)do{food.x=rand()%520+60;food.y=rand()%370+60;food.flag=0;}while(food.x%10!=0
6、
7、food.y%10!=0);if(food.flag==0){setcolor(GREEN);setlinestyle(3,0,3);rectangle(food.x,food.y,food.x+10,food.y+10);}for(i=snake.node-1;i>0;i--){snake.x[i]
8、=snake.x[i-1];snake.y[i]=snake.y[i-1];}switch(snake.dir){case1:snake.x[0]+=10;break;case2:snake.x[0]-=10;break;case3:snake.y[0]-=10;break;case4:snake.y[0]+=10;break;}for(i=3;i9、
10、
11、snake.x[0]>590
12、
13、snake.y[0]<50
14、
15、snake.y[0]>440){GameOver();snake.life=1;break;}if(snake.x[0]==food.x&&snake.y[0]==food.y){setcolor(0);rectangle(food.x,food.y,food.x+10,food.y+10);snake.node++;food.flag=1;}setcolor(4);for(i=0;i