";for(inti=1;i=n;i++)cout"";cout"
"endl;}cout"";for(inti=1;i=n;i++)cout"-";}voidprint_snake(){locate(snake[0].x,snake[0].y);cout"
";for(inti=1;i=snake_length-1;i++){locate(snake[i].x,snake[i].y);cout"*";}}boolis_correct(){if(snake[0].x==0snake[0].y==0
snake[0].x==m+1
snake[0].y==n+1)returnfalse;for(inti=1;i=snake_length-1;i++){if(snake[0].x==snake[i].xsnake[0].y==snake[i].y)returnfalse;}returntrue;}boolprint_food(){srand((unsigned)time(0));boole;while(1){e=true;inti=(int)random(0,m)+1,j=(int)random(0,n)+1;food.x=i;food.y=j;for(intk=0;k=snake_length-1;k++){if(snake[k].x==food.xsnake[k].y==food.y){e=false;break;}}if(e)break;}locate(food.x,food.y);cout"$";returntrue;}boolgo_ahead(){nodetemp;boole=false;temp=snake[snake_length-1];for(inti=snake_length-1;i=1;i--)snake[i]=snake[i-1];snake[0].x+=direct[dir][0];snake[0].y+=direct[dir][1];locate(snake[1].x,snake[1].y);cout"*";if(snake[0].x==food.xsnake[0].y==food.y){snake_length++;e=true;snake[snake_length-1]=temp;}if(!e){locate(temp.x,temp.y);cout"";}elseprint_food();locate(snake[0].x,snake[0].y);cout"
";if(!is_correct()){system("cls");cout"Youlose!"endl"Length:"snake_lengthendl;returnfalse;}returntrue;}intmain(){cout"-----------------------------------------------"endl;cout"请先输入两个数,表示地图大小.要求长宽均不小于10."endl;cout"请注意窗口大小,以免发生错位.建议将窗口调为最大."endl;cout"再选择难度.请在1-10中输入1个数,1最简单,10则最难"endl;cout"然后进入游戏画面,以方向键控制方向.祝你游戏愉快!"endl;cout"-----------------------------------------------"endl;cinmn;if(m10n10
m25
n40){cout"ERROR"endl;system("pause");return0;}inthard;cinhard;if(hard=0
hard){cout"ERROR"endl;system("pause");return0;}snake_length=5;clock_ta,b;charch;doublehard_len;for(inti=0;i=4;i++){snake[i].x=1;snake[i].y=5-i;}dir=3;system("cls");hide();print_wall();print_food();print_snake();locate(m+2,0);cout"Nowlength:";while(1){hard_len=(double)snake_length/(double)(m*n);a=clock();while(1){b=clock();if(b-a=(int)(-30*hard)*(1-sqrt(hard_len)))break;}if(kbhit()){ch=getch();if(ch==-32){ch=getch();switch(ch){case72:if(dir==2
dir==3)dir=0;break;case80:if(dir==2
dir==3)dir=1;break;case75:if(dir==0
dir==1)dir=2;break;case77:if(dir==0
dir==1)dir=3;break;}}}if(!go_ahead())break;locate(m+2,12);coutsnake_length;}system("pause");return0;}啊,这居然是。。。(这里先不说嘿嘿)各位小伙伴们快去试试吧,你们一定会惊呼有毒的~~文字:陆旸编辑:陆旸瑜伽寻找我们与城市的平衡维库溴铵误注入硬膜外腔一例