#include<bits/stdc++.h> #include<windows.h> #include<conio.h> using namespace std; int mp[209][209],tx[4]= {1,-1,0,0},ty[4]= {0,0,-1,1}; void cls() { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); COORD topLeft = {0, 0}; SetConsoleCursorPosition(hConsole, topLeft); } struct zd { int fx,x,y,fl,tm; } d[1000009]; int nd=0; void jd(int fx,int x,int y){ d[++nd]={fx,x,y,1,clock()}; } int main() { srand(time(0)); int fx=rand()%20,sx=rand()%20,fy=rand()%20,sy=rand()%20,fms=0,sms=0; while(1) { cls(); for(int i=0; i<=20; i++) for(int j=0; j<=20; j++) mp[i][j]=0; for(int i=1;i<=nd;i++) if(d[i].fl)mp[d[i].x][d[i].y]=3; mp[fx][fy]=1,mp[sx][sy]=2; for(int i=0; i<=19; i++) { for(int j=0; j<=19; j++) { if(mp[i][j]==1) cout<<’#’; if(mp[i][j]==2) cout<<’%’; if(mp[i][j]==3) cout<<‘o’; if(!mp[i][j])cout<<’.’; } cout<<endl; } if(_kbhit()) { int x=_getch(); if(x==‘0’)fms^=1; if(x==‘q’)sms^=1; if(x==224) { x=_getch(); if(!fms) { if(x==75) fy—; if(x==77) fy++; if(x==72) fx—; if(x==80) fx++; } else { if(x==75) jd(2,fx,fy); if(x==77) jd(3,fx,fy); if(x==72) jd(1,fx,fy); if(x==80) jd(0,fx,fy); } } else { if(!sms) { if(x==97) sy—; if(x==100) sy++; if(x==119) sx—; if(x==115) sx++; }else{ if(x==97) jd(2,sx,sy); if(x==100) jd(3,sx,sy); if(x==119) jd(1,sx,sy); if(x==115) jd(0,sx,sy); } } } sx=(sx+20)%20,sy=(sy+20)%20; fx=(fx+20)%20,fy=(fy+20)%20; for(int i=1;i<=nd;i++){ if(d[i].fl&&clock()-d[i].tm>100){ d[i].x+=tx[d[i].fx]; d[i].y+=ty[d[i].fx]; if(d[i].x<0||d[i].x>19||d[i].y<0||d[i].y>19)d[i].fl=0; d[i].tm=clock(); if(d[i].x==fx&&d[i].y==fy){ cout<<“\n玩家2赢了”; return 0; } if(d[i].x==sx&&d[i].y==sy){ cout<<“\n玩家1赢了”; return 0; } } } } return 0; }
剪贴板
剪贴板 ticr55qk
剪贴板信息
剪贴板信息
- 收录
- 更新