资源描述:
《贪吃蛇C语言源代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include#include#include#include#include#include#include#definewidth10#defineLEFT_GAP30#defineRIGHT_GAP20#defineTOP_GAP40#defineBOTTOM_GAP20#defineUP0x4800#defineDOWN0x5000#defineRIGHT0x4d00#defineLEFT0x4b00#defineESC0x011b#defineENTER
2、0x1c0d#defineSPACE0x3920inti,key;intscore=0;intgamespeed=30000;structFood{intx;inty;intyes;}food;structSnake{intx[200];inty[200];intnode;intdirection;intlife;}snake;voidInit(void);voidClose(void);voidDrawwall(void);voidGameOver(void);voidGamePlay(void);voidPrScore(void);voidInitfood(void);voidInit
3、snake(void);voidDrawfood(void);voidEatfood(void);voidcreatemusic(void);voidmusic(void);voidplaygame(void);voidlocation();voidmain(void){Init();Drawwall();Initfood();GamePlay();location();getch();Close();}voidInit(void){intgdrive=DETECT,gmode;initgraph(&gdrive,&gmode,"d:\tc");cleardevice();}voidDr
4、awwall(void){intk;intleft,top,right,bottom;left=LEFT_GAP;top=TOP_GAP;setbkcolor(11);setfillstyle(1,13);bar(30,40,40,460);bar(30,40,620,50);bar(30,450,620,460);bar(610,40,620,460);setcolor(15);setlinestyle(SOLID_LINE,0,THICK_WIDTH);for(k=0;k<(640-LEFT_GAP-RIGHT_GAP)/width;k++){right=left+width;bott
5、om=top+width;rectangle(left,top,right,bottom);left+=width;}for(k=0;k<(480-TOP_GAP-BOTTOM_GAP)/width;k++){left=LEFT_GAP;top=TOP_GAP+k*width;right=LEFT_GAP+width;bottom=TOP_GAP+width;rectangle(left,top,right,bottom);}for(k=0;k<(480-TOP_GAP-BOTTOM_GAP)/width;k++){right=640-RIGHT_GAP;left=right-width;
6、top=TOP_GAP+k*width;bottom=TOP_GAP+width;rectangle(left,top,right,bottom);}for(k=0;k<(640-LEFT_GAP-RIGHT_GAP)/width;k++){left=LEFT_GAP+k*width;right=left+width;bottom=480-BOTTOM_GAP;top=bottom-width;rectangle(left,top,right,bottom);}}voidInitfood(void){inthori=640-LEFT_GAP-RIGHT_GAP-4*width;intver
7、=480-TOP_GAP-BOTTOM_GAP-4*width;food.x=random(hori/width)*width+LEFT_GAP+RIGHT_GAP;food.y=random(ver/width)*width+TOP_GAP+BOTTOM_GAP;}voidDrawfood(void){setcolor(14);setfillstyle(1,4);bar(food.x,food.y,food.x+wid