(在按下WSAD方向键后请按下enter)
#include<bits/stdc++.h>
using namespace std;
int a[21][21];char n;
int x=1,y=1,x_1=1,y_1=0,x_2=1,y_2=0,x_3=1,y_3=0;
int kk1=1,kk2=1;
int xx=5,yy=5,sum,k,x2=5,y2=5;
int main(){
while(n!='0'){
for(int i=1;i<=20;i++){
for(int j=1;j<=20;j++){
if(x==xx&&y==yy){
xx=rand()%(17-1+1)+1;
yy=rand()%(17-1+1)+1;
sum++;
}
if(x==x2&&y==y2){
x2=rand()%(7-1+1)+1;
y2=rand()%(7-1+1)+1;
sum++;
}
else if(i==x&&j==y)cout<<"卐";
else if(i==x_1&&j==y_1)cout<<"卐";
else if(i==x_2&&j==y_2)cout<<"卐";
else if(i==x_3&&j==y_3)cout<<"卐";
else if(i==xx&&j==yy)cout<<"英";
else if(i==x2&&j==y2)cout<<"法";
else if(i==20||j==20)cout<<"# ";
else if(x==20||y==20){
system("cls");
cout<<"Game Over!";
return 0;
}
else cout<<" ";
}
cout<<endl;
}
cout<<"分数:"<<sum;
cin>>n;
kk1=x;
kk2=y;
if(n=='w') x--;
if(n=='s') x++;
if(n=='a') y--;
if(n=='d') y++;
x_3=x_2;
y_3=y_2;
x_2=x_1;
y_2=y_1;
x_1=kk1;
y_1=kk2;
if(sum==20){
system("cls");
cout<<"Game Over!"<<endl;
cout<<"You Win!"<<endl;
return 0;
}
system("cls");
}
return 0;
}