资源描述:
《贪吃蛇C语言源代码.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include#include#include#include#include#include#include#definewidth10#defineLEFT_GAP30#defineRIGHT_GAP20#defineTOP_GAP40#defineBOTTOM_GAP20#defineUP0x4800#defineDOWN0x5000#defineRIGHT0x4d00#defineLEFT0x4b00#define
2、ESC0x011b#defineENTER0x1c0d#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);voi
3、dPrScore(void);voidInitfood(void);voidInitsnake(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
4、,gmode;initgraph(&gdrive,&gmode,"d:\tc");cleardevice();}voidDrawwall(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_LIN
5、E,0,THICK_WIDTH);for(k=0;k<(640-LEFT_GAP-RIGHT_GAP)/width;k++){right=left+width;bottom=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(le
6、ft,top,right,bottom);}for(k=0;k<(480-TOP_GAP-BOTTOM_GAP)/width;k++){right=640-RIGHT_GAP;left=right-width;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-B
7、OTTOM_GAP;top=bottom-width;rectangle(left,top,right,bottom);}}voidInitfood(void){inthori=640-LEFT_GAP-RIGHT_GAP-4*width;intver=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
8、){setcolor(14);setfillstyle(1,4);bar(food.x,food.y,food.x+wid