//贪吃蛇,wsad调整蛇的方向,"{}"是蛇头,"[]"是蛇身,"()"是蛇尾,"$"是食物,蛇到边缘会出现在对面
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
//可调整
#define Long 20//地图长度
#define SLEEP 90//这个是蛇每N毫秒向前移动一格
#define t(y,x) (y-1)*(Long+1)+x
int main(){
int Hy=Long/2,Hx=Long/2,map[(Long+1)*(Long+1)+20],len=4,c='d',c1='d',i=0,j=0;
CONSOLE_CURSOR_INFO cursor_info={1,0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
for(memset(map,0,sizeof(map)),srand(time(0)),i=rand()%Long+1,j=rand()%Long+1,map[t(i,j)]=-1;true;Sleep(SLEEP),(_kbhit()?c1=getch(),c1=tolower(c1):c),
c=(c=='a'&&c1!='d')||(c=='d'&&c1!='a')||(c=='w'&&c1!='s')||(c=='s'&&c1!='w')?c1:c){
for(c=='a'?(Hx==1?Hx=Long:Hx--):(c=='d'?(Hx==Long?Hx=1:Hx++):(c=='w'?(Hy==1?Hy=Long:Hy--):(c=='s'?(Hy==Long?Hy=1:Hy++):c))),i=1;i<=(Long+1)*Long;i++)map[i]>0?map[i]--:c;
if(map[t(Hy,Hx)]>0)exit(0);
for((map[t(Hy,Hx)]==-1?len++,i=rand()%Long+1,j=rand()%Long+1,map[t(i,j)]=-1:c),system("cls"),i=1;i<=Long+1;i++)cout<<"--";
for(cout<<"\n",map[t(Hy,Hx)]=len,i=1;i<=Long;i++)for(cout<<'|',j=1;j<=Long+1;j++)map[t(i,j)]>0?(map[t(i,j)]==len?cout<<"{}":(map[t(i,j)]==1?cout<<"()":cout<<"[]")):(map[t(i,j)]==-1?cout<<" $":(j==Long+1?cout<<"|\n":cout<<" "));
for(i=1;i<=Long+1;i++)cout<<"--";
}
}