How to write snake in c language
# include & ltconio.h & gt # include & lt graphics.h & gt # include & lt time.h & gt # include & lt string.h & gt # include & lt malloc.h & gt # include & lt stdio.h & gtint level =5, points =0. Void set (), menu (), move_head (), move_body (), move (), init _ insect (), left (), upon (), right (), down (), init_graph (), food_f (), ahead (). Structural error {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,*p 1=NULL,* p2 = NULLvoid main(){ char ch; initgraph(800,600); set(); Init _ insect (); while( 1){ food _ f(); Sleep (level *10); Setcolor (black); Circular (head _ l->; x,head _ l-& gt; y,2); Setcolor (white); move _ body(); if(kb hit()){ ch = getch(); if(ch = = 27){ ahead(); set(); } else if(ch = =-32){ switch(getch()){ case 72:upon(); Break; Case 80: down (); Break; Case 75: Left (); Break; Case 77: Right (); Break; } } else ahead()。 } else { ahead(); } if(head _ f-& gt; x==food。 & amphead _ f-& gt; y = = food . y){ Sleep( 100); crate(); food . judge = 0; Point = point+(level 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) {Sleep (1000); Life-; food . judge = 0; init_graph()。 Init _ insect (); menu(); } for(p 1 = head _ f-& gt; Next; p 1! = NULLp 1 = p 1->; next){ if(head _ f-& gt; x = = p 1->; x & amp& amphead _ f-& gt; y = = p 1-& gt; y){ Sleep( 1000); Life-; food . judge = 0; init_graph()。 Init _ insect (); menu(); Break; } }} If (life = = 0) {Outtextxy (280 280,300, "Game over!" ); getch(); Return; } move(); }; } void init _ graph(){ clear viewport(); setlinestyle(PS_SOLID, 1,5); Rectangular (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, difficulty"); Outtextxy (640, 1 10, "4, start over"); switch(getch()){ case ' 1 ':menu(); Setcolor (green); circle(food.x,food.y,2); Setcolor (white); Return; Case "2": exit (0); Break; Case' 3': Outtextxy (700,90, ":12345"); grade = getch()-48; set(); Break; Case "4": food.judge = 0, grade = 5;; Point = 0; Life = 3; Init _ insect (); menu(); Break; Default value: Outtextxy (250,300, "Input error!" ); set(); Break; }} Voidmenu () {charstr [20], STR 1 [] = {"Score:"}, str2[]={ "Difficulty:"}, str3[]={ "Health:"}; init_graph()。 sprintf(str," %d ",point); strcat(str 1,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, 1 10, "setting: ESC"); } void init _ insect () {head _ f = (structbug *) malloc (sizeof (structbug)); head _ f-& gt; last = NULLhead _ f-& gt; x = 300head _ f-& gt; y = 300p2 = head _ f-& gt; Next=p 1= (structural bug *)malloc(sizeof); p 1->; last = head _ f; p 1->; x = 295p 1->; y = 300p 1 = p 1->; Next= (structural bug *)malloc(sizeof); p 1->; next = NULLp 1->; x = 290p 1->; y = 300p 1->; last = p2head _ l = p 1; } void move(){ for(p 1 = head _ f; p 1! = NULLp 1 = p 1->; Next) {circle (p1->; x,p 1->; y,2); } } void move _ head(){ } void move _ body(){ for(p 1 = head _ l,p2 = p 1-& gt; Finally; p2! = NULLp 1=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->; Next; p2 = p2-& gt; Next; 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; Next; p 1 = p 1->; Next; 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; Front (); } } void down(){ p 1 = head _ f-& gt; Next; p 1 = p 1->; Next; 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; Front (); } } void left(){ p 1 = head _ f-& gt; Next; p 1 = p 1->; Next; 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; Front (); } } void right(){ p 1 = head _ f-& gt; Next; p 1 = p 1->; Next; 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; Front (); } } void food_f() { if(! food . judge){ food . x =(rand()% 1 17+ 1)* 5; food . y =(rand()% 1 17+ 1)* 5; food . judge = 1; if(food . x & lt; 30 || food.y & lt30 || food.x & gt 570 || food.y & gt 570) {setcolor (red); Circle (f