如何用C语言写snake
# include & ltconio.h & gt# include & ltgraphics.h & gt# include & lttime.h & gt# include & ltstring.h & gt# include & ltmalloc.h & gt# include & ltstdio.h & gtint等级=5,点数=0,生命= 3;void set(),menu(),move_head(),move_body(),move(),init _昆虫(),left(),upon(),right(),down(),init_graph(),food_f(),ahead(),crate();结构错误{ int x;int y;struct bug * laststruct bug * next};struct FD { int x;int y;int judge}food={0,0,0 };struct bug *head_f=NULL,*head_l,*p1=NULL,* p2 = NULLvoid main(){ char ch;initgraph(800,600);set();init _昆虫();while(1){ food _ f();睡眠(等级* 10);setcolor(黑色);圆形(head _ l-& gt;x,head _ l-& gt;y,2);setcolor(白色);move _ body();if(kb hit()){ ch = getch();if(ch = = 27){ ahead();set();} else if(ch = =-32){ switch(getch()){ case 72:upon();打破;案例80:down();打破;案例75:左();打破;案例77:右();打破;} } else ahead()。} else { ahead();} if(head _ f-& gt;x==food。& amphead _ f-& gt;y = = food . y){ Sleep(100);crate();food . judge = 0;point=point+(6级)* 10;if(food . x & lt;30 | | food.y & lt30 | | food.x & gt570 | | food.y & gt570)life++;menu();} if(head _ f-& gt;x & lt5 | | head _ f-& gt;x & gt595 | | head _ f->;y & lt5 | | head _ f-& gt;y & gt595) {睡眠(1000);生活-;food . judge = 0;init_graph()。init _昆虫();menu();} for(p 1 = head _ f-& gt;接下来;p1!= NULLp 1 = p 1->;next){ if(head _ f-& gt;x = = p 1->;x & amp& amphead _ f-& gt;y = = p 1-& gt;y){ Sleep(1000);生活-;food . judge = 0;init_graph()。init _昆虫();menu();打破;}} If (life = = 0) {Outtextxy (280,300,“游戏结束!”);getch();返回;} move();};} void init _ graph(){ clear viewport();setlinestyle(PS_SOLID,1,5);矩形(2,2600,598);setlinestyle(PS_SOLID,1,1);} void set(){ init _ graph();Outtextxy(640,50,“1,start/return”);Outtextxy(640,70," 2,exit ");Outtextxy(640,90,“3,难度”);Outtextxy (640,110," 4,重新开始");switch(getch()){ case ' 1 ':menu();setcolor(绿色);circle(food.x,food.y,2);setcolor(白色);返回;案例“2”:出口(0);打破;案例' 3': outtextxy(700,90,":1 2 3 4 5 ");grade = getch()-48;set();打破;案例“4”:food . judge = 0,grade = 5;点= 0;生命= 3;init _昆虫();menu();打破;默认值:outtextxy(250,300,"输入错误!");set();打破;}} Voidmenu () {charstr [20],STR1 [] = { "分数:" },str2[]={ "难度:" },str3[]={ "健康:" };init_graph()。sprintf(str," %d ",point);strcat(str1,str);outtextxy(640,50,str 1);sprintf(str," %d ",grade);strcat(str2,str);outtextxy(640,70,str 2);sprintf(str," %d ",life);strcat(str3,str);outtextxy(640,90,str 3);Outtextxy(640,110,"设置:ESC ");} void init _昆虫(){ head _ f =(struct bug *)malloc(sizeof(struct bug));head _ f-& gt;last = NULLhead _ f-& gt;x = 300head _ f-& gt;y = 300p2 = head _ f-& gt;next=p1=(结构bug *)malloc(sizeof(结构bug));p 1->;last = head _ f;p 1->;x = 295p 1->;y = 300p 1 = p 1->;next=(结构bug *)malloc(sizeof(结构bug));p 1->;next = NULLp 1->;x = 290p 1->;y = 300p 1->;last = p2head _ l = p 1;} void move(){ for(p 1 = head _ f;p1!= NULLp 1 = p 1->;下一步){ circle(p 1->;x,p 1->;y,2);} } void move _ head(){ } void move _ body(){ for(p 1 = head _ l,p2 = p 1-& gt;最后;p2!= NULLp1=p2,p2 = p2-& gt;last){ p 1->;x = p2-& gt;x;p 1->;y = p2-& gt;y;} } void ahead(){ p 1 = head _ f;p2 = p 1->;接下来;p2 = p2-& gt;接下来;if(p 1->;x = = p2-& gt;x){ if(p 1->;y & gtp2->;y)head _ f-& gt;y+= 5;else head _ f-& gt;y-= 5;} else { if(p 1-& gt;x & gtp2->;x){ head _ f-& gt;x+= 5;} else head _ f-& gt;x-= 5;} } void on(){ p 1 = head _ f-& gt;接下来;p 1 = p 1->;接下来;head _ f-& gt;y-= 5;if(p 1->;x = = head _ f-& gt;x & amp& ampp 1->;y = = head _ f-& gt;y){ head _ f-& gt;y+= 5;前方();} } void down(){ p 1 = head _ f-& gt;接下来;p 1 = p 1->;接下来;head _ f-& gt;y+= 5;if(p 1->;x = = head _ f-& gt;x & amp& ampp 1->;y = = head _ f-& gt;y){ head _ f-& gt;y-= 5;前方();} } void left(){ p 1 = head _ f-& gt;接下来;p 1 = p 1->;接下来;head _ f-& gt;x-= 5;if(p 1->;x = = head _ f-& gt;x & amp& ampp 1->;y = = head _ f-& gt;y){ head _ f-& gt;x+= 5;前方();} } void right(){ p 1 = head _ f-& gt;接下来;p 1 = p 1->;接下来;head _ f-& gt;x+= 5;if(p 1->;x = = head _ f-& gt;x & amp& ampp 1->;y = = head _ f-& gt;y){ head _ f-& gt;x-= 5;前方();} } void food_f() { if(!food . judge){ food . x =(rand()% 117+1)* 5;food . y =(rand()% 117+1)* 5;food . judge = 1;if(food . x & lt;30 | | food.y & lt30 | | food.x & gt570 | | food.y & gt570) { setcolor(红色);圆圈(f