版本比较
look here
正文
增加 1 行删除 138 行
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381```cpp#include<easyx.h>#include<windows.h>#include<conio.h>#include<cstdlib>#include<ctime>#include<string>#include<thread>#include<queue>#define LARGE 15#define X 25#define Y 19#define SPEED 200using namespace std;const long long fx[4]={0,1,0,-1},fy[4]={-1,0,1,0};long long mp[X+10][Y+10];char c=' ';bool running=1;void input(){ while(running){ c=getch(); } return;}void output(long long x,long long y){ if(mp[x][y]==0){ setlinecolor(WHITE); setfillcolor(WHITE); } if(mp[x][y]==1){ setlinecolor(RED); setfillcolor(RED); } if(mp[x][y]==2){ setlinecolor(BLACK); setfillcolor(WHITE); } if(mp[x][y]==3){ setlinecolor(BLACK); setfillcolor(BLACK); } fillrectangle((x-1)*LARGE,(y-1)*LARGE,x*LARGE,y*LARGE);}void new_apple(){ srand(time(0)); long long t1,t2; do{ t1=rand()%X+1,t2=rand()%Y+1; }while(mp[t1][t2]!=0); mp[t1][t2]=1; output(t1,t2);}queue<long long>qx,qy;int main(){ initgraph(X*LARGE,Y*LARGE); thread LBWNB(input); setbkcolor(WHITE); long long x=X/2,y=(Y+1)/2,f=3,l=3; mp[x][y]=3,mp[x+1][y]=mp[x+2][y]=2; qx.push(x+2);qy.push(y); qx.push(x+1);qy.push(y); qx.push(x);qy.push(y); BeginBatchDraw(); new_apple(); while(1){ mp[x][y]=2; if(c=='w'&&f!=2){ f=0; c=' '; } else if(c=='d'&&f!=3){ f=1; c=' '; } else if(c=='s'&&f!=0){ f=2; c=' '; } else if(c=='a'&&f!=1){ f=3; c=' '; } x=x+fx[f],y+=fy[f]; if(x==0){ x=X; } if(y==0){ y=Y; } if(x==X+1){ x=1; } if(y==Y+1){ y=1; } if(mp[x][y]==2){ FlushBatchDraw(); break; } if(mp[x][y]==1){ new_apple(); } else{ mp[qx.front()][qy.front()]=0; qx.pop(); qy.pop(); } mp[x][y]=3; qx.push(x); qy.push(y); for(int i=1;i<=X;++i){ for(int j=1;j<=Y;++j){ output(i,j); } } qx.push(-1); while(qx.front()!=-1){ output(qx.front(),qy.front()); qx.push(qx.front()); qy.push(qy.front()); qx.pop(); qy.pop(); } qx.pop(); FlushBatchDraw(); Sleep(SPEED); } running=0; string s="game over"; settextcolor(BLACK); outtextxy(X*LARGE/2-LARGE*2,Y*LARGE/2,&s[0]); FlushBatchDraw(); system("pause"); EndBatchDraw(); closegraph(); return 0;}``````https://cdn.luogu.com.cn/upload/image_hosting/bn0ocyh7.png