dev-c++中的C语言游戏代码是什么?
# include \ x0d \ # include \ x0d \ # include \ x0d \ # include \ x0d \ #定义u1 \ x0d \ #定义d2 \ x0d \ #定义l3 \ x0d \ #定义r D:below;l:left r:right \ x0d \ x0d \ typedef struct snake {//蛇体的一个节点\ x0d \ int x;\ x0d \ int y;\ x0d \ struct SNAKE * next\x0d\}蛇;\x0d\\x0d\//全局变量/\ x0d \ intscore = 0,add = 10;//总分和每道菜的分数。\x0d\int状态,sleeptime = 200//每次运行时间间隔\x0d\snake *head,* food//蛇头指针,食物指针\ x0d \ snake * q;//遍历snake时使用的指针\ x0d \ int endgamestatus = 0;//游戏结束,1:撞墙;2:咬自己;3:主动退出游戏。\x0d\\x0d\//声明所有函数//\ x0d \ void Pos();\ x0d \ void creat map();\ x0d \ void initsnake();\ x0d \ int bite self();\ x0d \ void create food();\ x0d \ void cant cross wall();\ x0d \ void snake move();\ x0d \ void pause();\ x0d \ void game circle();\ x0d \ void welcome togame();\ x0d \ void end game();\ x0d \ void gamestart();\x0d\\x0d\void Pos(int x,int y)//设置光标位置\ x0d \ { \ x0d \ COORD pos\ x0d \ HANDLE hOutput\x0d\pos。X = x\x0d\pos。Y = y\ x0d \ hOutput = GetStdHandle(STD _ OUTPUT _ HANDLE);\ x0d \ SetConsoleCursorPosition(hout put,pos);\ x0d \ } \ x0d \ x0d \ void creat map()//创建地图\ x0d \ { \ x0d \ int I;\ x0d \ for(I = 0;ix = 24\ x0d \ tail-& gt;y = 5;\ x0d \ tail-& gt;next = NULL\ x0d \ for(I = 1;inext = tail\ x0d \ head-& gt;x = 24+2 * I;\ x0d \ head-& gt;y = 5;\ x0d \ tail = head\x0d\}\x0d\while(tail!=NULL) {//从头到尾,输出snake \ x0d \ Pos(tail-& gt;x,tail-& gt;y);\ x0d \ printf("■");\ x0d \ tail = tail-& gt;接下来;\ x0d \ } \ x0d \ } \ x0d \ x0d \ int bite self()//判断是否咬过自己\ x0d \ { \ x0d \ snake * self\ x0d \ self = head-& gt;接下来;\x0d\while(self!= NULL){ \ x0d \ if(self-& gt;x = = head-& gt;x & amp& ampself->;y = = head-& gt;y){ \ x0d \ return 1;\ x0d \ } \ x0d \ self = self-& gt;接下来;\ x0d \ } \ x0d \ return 0;\ x0d \ } \ x0d \ x0d \ void create food()//Random food \ x0d \ { \ x0d \ snake * food _ 1;\x0d\srand((无符号)time(NULL));\ x0d \ food _ 1 =(snake *)malloc(sizeof(snake))。\ x0d \ while((food _ 1-& gt;x%2)!=0) {//保证是偶数,这样食物才能和黑鱼匹配\ x0d \ food _ 1-& gt;x = rand()% 52+2;\ x0d \ } \ x0d \ food _ 1-& gt;y = rand()% 24+1;\ x0d \ q = head\ x0d \ while(q-& gt;next = = NULL){ \ x0d \ if(q-& gt;x = = food _ 1-& gt;x & amp& ampq->;y = = food _ 1-& gt;Y) {//判断蛇身是否与food \x0d\free(food_1)重合;\ x0d \ create food();\ x0d \ } \ x0d \ q = q-& gt;接下来;\ x0d \ } \ x0d \ Pos(food _ 1-& gt;x,food _ 1-& gt;y);\ x0d \ food = food _ 1;\ x0d \ printf("■");\ x0d \ } \ x0d \ \ x0d \ Void cantrosswell()//不能穿墙\ x0d \ { \ x0d \ if(head-& gt;x = = 0 | | head-& gt;x = = 56 | | head->;y = = 0 | | head-& gt;y = = 26){ \ x0d \ endgamestatus = 1;\ x0d \ end game();\ x0d \ } \ x0d \ } \ x0d \ \ void snake move()//snake forward,up u,down d,left l,right R \ x0d \ { \ x0d \ snake * next head;\ x0d \ cant cross wall();\ x0d \ \ x0d \ next head =(snake *)malloc(sizeof(snake));\ x0d \ if(status = = U){ \ x0d \ next head-& gt;x = head-& gt;x;\ x0d \ next head-& gt;y = head-& gt;y-1;\ x0d \ if(next head-& gt;x = = food-& gt;x & amp& ampnext head-& gt;y = = food-& gt;Y) {//如果下一个有吃的//\ x0d \ next head-& gt;下一个=头;\ x0d \ head = nexthead\ x0d \ q = head\x0d\while(q!= NULL){ \ x0d \ Pos(q-& gt;x,q-& gt;y);\ x0d \ printf("■");\ x0d \ q = q-& gt;接下来;\ x0d \ } \ x0d \ score = score+add;\ x0d \ create food();\x0d\} else {//如果没有食物//\ x0d \ nextthe ad-> next = head;\ x0d \ head = nexthead\ x0d \ q = head\ x0d \ while(q-& gt;下一个-& gt;下一个!= NULL){ \ x0d \ Pos(q-& gt;x,q-& gt;y);\ x0d \ printf("■");\ x0d \ q = q-& gt;接下来;\ x0d \ } \ x0d \ Pos(q-& gt;下一个-& gt;x,q-& gt;下一个-& gt;y);\ x0d \ printf(" ");\ x0d \ free(q-& gt;下一个);\ x0d \ q-& gt;next = NULL\ x0d \ } \ x0d \ } \ x0d \ if(status = = D){ \ x0d \ next head-& gt;x = head-& gt;x;\ x0d \ next head-& gt;y = head-& gt;y+1;\ x0d \ if(next head-& gt;x = = food-& gt;x & amp& ampnext head-& gt;y = = food-& gt;Y) {//有吃的\ x0d \ next head-& gt;下一个=头;\ x0d \ head = nexthead\ x0d \ q = head\x0d\while(q!= NULL){ \ x0d \ Pos(q-& gt;x,q-& gt;y);\ x0d \ printf("■");\ x0d \ q = q-& gt;接下来;\ x0d \ } \ x0d \ score = score+add;\ x0d \ create food();\x0d\} else {//无食\ x0d \ nextthe ad-> next = head;\ x0d \ head = nexthead\ x0d \ q = head\ x0d \ while(q-& gt;下一个-& gt;下一个!= NULL){ \ x0d \ Pos(q-& gt;x,q-& gt;y);\ x0d \ printf("■");\ x0d \ q = q-& gt;接下来;\ x0d \ } \ x0d \ Pos(q-& gt;下一个-& gt;x,q-& gt;下一个-& gt;y);\ x0d \ printf(" ");\ x0d \ free(q-& gt;下一个);\ x0d \ q-& gt;next = NULL\ x0d \ } \ x0d \ } \ x0d \ if(status = = L){ \ x0d \ next head-& gt;x = head-& gt;x-2;\ x0d \ next head-& gt;y = head-& gt;y;\ x0d \ if(next head-& gt;x = = food-& gt;x & amp& ampnext head-& gt;y = = food-& gt;Y) {//有吃的\ x0d \ next head-& gt;下一个=头;\ x0d \ head = nexthead\ x0d \ q = head\x0d\while(q!= NULL){ \ x0d \ Pos(q-& gt;x,q-& gt;y);\ x0d \ printf("■");\ x0d \ q = q-& gt;接下来;\ x0d \ } \ x0d \ score = score+add;\ x0d \ create food();\x0d\} else {//无食\ x0d \ nextthe ad-> next = head;\ x0d \ head = nexthead\ x0d \ q = head\ x0d \ while(q-& gt;下一个-& gt;下一个!= NULL){ \ x0d \ Pos(q-& gt;x,q-& gt;y);\ x0d \ printf("■");\ x0d \ q = q-& gt;接下来;\ x0d \ } \ x0d \ Pos(q-& gt;下一个-& gt;x,q-& gt;下一个-& gt;y);\ x0d \ printf(" ");\ x0d \ free(q-& gt;下一个);\ x0d \ q-& gt;next = NULL\ x0d \ } \ x0d \ } \ x0d \ if(status = = R){ \ x0d \ next head-& gt;x = head-& gt;x+2;\ x0d \ next head-& gt;y = head-& gt;y;\ x0d \ if(next head-& gt;x = = food-& gt;x & amp& ampnext head-& gt;y = = food-& gt;Y) {//有吃的\ x0d \ next head-& gt;下一个=头;\ x0d \ head = nexthead\ x0d \ q = head\x0d\while(q!= NULL){ \ x0d \ Pos(q-& gt;x,q-& gt;y);\ x0d \ printf("■");\ x0d \ q = q-& gt;接下来;\ x0d \ } \ x0d \ score = score+add;\ x0d \ create food();\x0d\} else {//无食\ x0d \ nextthe ad-> next = head;\ x0d \ head = nexthead\ x0d \ q = head\ x0d \ while(q-& gt;下一个-& gt;下一个!= NULL){ \ x0d \ Pos(q-& gt;x,q-& gt;y);\ x0d \ printf("■");\ x0d \ q = q-& gt;接下来;\ x0d \ } \ x0d \ Pos(q-& gt;下一个-& gt;x,q-& gt;下一个-& gt;y);\ x0d \ printf(" ");\ x0d \ free(q-& gt;下一个);\ x0d \ q-& gt;next = NULL\ x0d \ } \ x0d \ } \ x0d \ if(bite self()= = 1){//判断是否会咬自己\ x0d \ endgamestatus = 2;\ x0d \ end game();\ x0d \ } \ x0d \ } \ x0d \ \ void Pause()//Pause \ x0d \ { \ x0d \ while(1){ \ x0d \ Sleep(300);\ x0d \ if(GetAsyncKeyState(VK _空间)){ \ x0d \ break\ x0d \ } \ x0d \ } \ x0d \ } \ x0d \ x0d \ void game circle()//控制游戏\ x0d \ {\ x0d \ x0d \ POS (64,15。\x0d\printf("不能穿墙,也不能咬自己\ n ");\x0d\Pos(64,16);\x0d\printf ("Use ←。← →分别控制蛇的移动。”);\x0d\Pos(64,17);\x0d\printf("F1为加速,F2为减速\ n ");\x0d\Pos(64,18);\x0d\printf("ESC:退出游戏。空间:暂停游戏。”);\x0d\Pos(64,20);\ x0d \//\ x0d \ status = R;\ x0d \ while(1){ \ x0d \ Pos(64,10);\x0d\printf("分数:%d ",分数);\x0d\Pos(64,11);\x0d\printf("每种食物得分:%d ",add);\ x0d \ if(GetAsyncKeyState(VK _ UP)& amp;& amp地位!= D){ \ x0d \ status = U;\ x0d \ } else if(GetAsyncKeyState(VK _下)& amp& amp地位!= U){ \ x0d \ status = D;\ x0d \ } else if(GetAsyncKeyState(VK _左)& amp& amp地位!= R){ \ x0d \ status = L;\ x0d \ } else if(GetAsyncKeyState(VK _右)& amp& amp地位!= L){ \ x0d \ status = R;\ x0d \ } else if(GetAsyncKeyState(VK空间)){ \ x0d \ pause();\ x0d \ } else if(GetAsyncKeyState(VK _ ESCAPE)){ \ x0d \ endgamestatus = 3;\ x0d \ break\ x0d \ } else if(GetAsyncKeyState(VK _ f 1)){ \ x0d \ if(睡眠时间& gt= 50){ \ x0d \ sleep time = sleep time-30;\ x0d \ add = add+2;\ x0d \ if(sleep time = = 320){ \ x0d \ add = 2;//减少到1 \ x0d \ } \ x0d \ } else if(getasynckeystate(vk _ F2)){ \ x0d \ if(sleep time)