资源描述:
《贪吃蛇的c语言源程序.doc》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、#include#include#include#include#include#include#defineNULL0#defineUP4471#defineLEFT7777#defineDOWN8051#defineRIGHT8292#definePAUSE6512#defineESC283#defineSNAKE_COLOR4#defineSNAKE_BOND_COLOR2#define
2、SNAKE_STYLELTBKSLASH_FILL#defineFOOD_STYLECLOSE_DOT_FILL#defineMAP_COLOR8#defineMAP_BOND_COLOR6#defineMAP_STYLESOLID_FILLtypedefstructSnake_Node{intx,y;structSnake_Node*next;}Snake_Node,*P_Snake_Node;struct{intx,y,color;}Food;struct{intdx;intdy;}Direct
3、={0,1};staticintspeed=1,len=4,px,py;staticP_Snake_NodeHead;staticP_Snake_NodeMap;voidpaint_node(int,int,int,int,int);voidPut_Food(int);voidPut_Snake_Node(P_Snake_Node,int);voidInit();voidGrow_up(int,int);voidMake_Map();voidAuto_Make_Map();voidLoad_Game
4、();voidAuto_Start();intSnake_Dead();voidGO_GO_GO();voidPlay_Game();voidExit_Save();voidFailed();voidmain();voidpaint_node(intx,inty,intcolor1,intcolor2,intstyle){setfillstyle(SOLID_FILL,color2);bar(x*10,479-y*10,x*10+9,479-y*10-9);setfillstyle(style,co
5、lor1);bar(x*10+1,479-y*10-1,x*10+9-1,479-y*10-9+1);setfillstyle(SOLID_FILL,15);}voidPut_Food(intcolor){randomize();Food.x=random(46)+1;Food.y=random(46)+1;Food.color=color;paint_node(Food.x,Food.y,Food.color,Food.color,FOOD_STYLE);}voidPut_Snake_Node(P
6、_Snake_Nodep,intflag){if(flag)paint_node(p->x,p->y,SNAKE_COLOR,SNAKE_BOND_COLOR,SNAKE_STYLE);elsepaint_node(p->x,p->y,getbkcolor(),getbkcolor(),SOLID_FILL);}voidInit(){intgdrive=VGA,gmode=VGAHI;initgraph(&gdrive,&gmode,"d:\TC20\turboc2");setfillstyle
7、(XHATCH_FILL,2);bar(490,0,509,479);setfillstyle(SOLID_FILL,6);bar(480,0,489,479);setfillstyle(SOLID_FILL,15);setcolor(9);setlinestyle(CENTER_LINE,0,3);line(490,0,490,479);setcolor(3);setlinestyle(SOLID_LINE,0,3);line(509,0,509,479);line(509,479,639,479
8、);line(639,479,639,0);line(639,0,509,0);setlinestyle(SOLID_LINE,0,0);setcolor(10);settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);outtextxy(530,12,"GREEDY");outtextxy(537,40,"SNAKE");settextstyle(0,0,0);setcolor(13);outtextxy(510,80,"<<=========