有一个10×10的矩阵,中间是一个井号,其他位置是星号。按下w,a,s,d 控制井号的方向。每当一个井号碰到一个星号时,星号就会被消除。你的任务是在105步以内消除所有的星号。
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
char a[12][12];
int main(){
cout<<"欢迎来到消除星号小游戏。"<<endl;
cout<<"按下w,a,s,d控制方向。"<<endl;
cout<<"系统会给出一个10 ×10的方阵,中间有一个#,其他符号为*。"<<endl;
cout<<"你的目标是在105步内控制井号消除所有星号。"<<endl;
cout<<"按下y开始游戏,按下n结束游戏!"<<endl;
char u,x;
cin>>u;
int n=5,m=5;
short w=105;
if(u=='n'){
return 0;
}
if(u=='y'){
for(int i=1;i<=10;i++){
for(int j=1;j<=10;j++){
if(i==5&&j==5)a[i][j]='#';
else a[i][j]='*';
}
}
for(int i=1;i<=10;i++){
for(int j=1;j<=10;j++){
cout<<a[i][j];
}
cout<<endl;
}
cout<<endl;
while(cin>>x){
if(w!=1){
if(x=='w'){
w--;
cout<<"您还有"<<w<<"步。"<<endl;
a[n][m]=' ';
a[n-1][m]='#';
n--;
for(int i=1;i<=10;i++){
for(int j=1;j<=10;j++){
cout<<a[i][j];
}
cout<<endl;
}
cout<<endl;
}
if(x=='a'){
w--;
cout<<"您还有"<<w<<"步。"<<endl;
a[n][m]=' ';
a[n][m-1]='#';
m--;
for(int i=1;i<=10;i++){
for(int j=1;j<=10;j++){
cout<<a[i][j];
}
cout<<endl;
}
cout<<endl;
}
if(x=='s'){
w--;
cout<<"您还有"<<w<<"步。"<<endl;
a[n][m]=' ';
a[n+1][m]='#';
n++;
for(int i=1;i<=10;i++){
for(int j=1;j<=10;j++){
cout<<a[i][j];
}
cout<<endl;
}
cout<<endl;
}
if(x=='d'){
w--;
cout<<"您还有"<<w<<"步。"<<endl;
a[n][m]=' ';
a[n][m+1]='#';
m++;
for(int i=1;i<=10;i++){
for(int j=1;j<=10;j++){
cout<<a[i][j];
}
cout<<endl;
}
cout<<endl;
}
}
if(w==1){
if(x=='w'){
cout<<"您还有0步。"<<endl;
a[n][m]=' ';
a[n-1][m]='#';
for(int i=1;i<=10;i++){
for(int j=1;j<=10;j++){
cout<<a[i][j];
}
cout<<endl;
}
cout<<endl;
}
if(x=='a'){
cout<<"您还有0步。"<<endl;
a[n][m]=' ';
a[n][m-1]='#';
m--;
w--;
for(int i=1;i<=10;i++){
for(int j=1;j<=10;j++){
cout<<a[i][j];
}
cout<<endl;
}
cout<<endl;
}
if(x=='s'){
cout<<"您还有0步。"<<endl;
a[n][m]=' ';
a[n+1][m]='#';
n++;
w--;
for(int i=1;i<=10;i++){
for(int j=1;j<=10;j++){
cout<<a[i][j];
}
cout<<endl;
}
cout<<endl;
}
if(x=='d'){
cout<<"您还有0步。"<<endl;
a[n][m]=' ';
a[n][m+1]='#';
m++;
w--;
for(int i=1;i<=10;i++){
for(int j=1;j<=10;j++){
cout<<a[i][j];
}
cout<<endl;
}
cout<<endl;
}
cout<<"恭喜你走完了所有步!"<<endl;
cout<<"下面系统会对你的做法进行测评!";
cout<<"LOADING............"<<endl;
int fl=0;
for(int i=1;i<=10;i++){
for(int j=1;j<=10;j++){
if(a[i][j]=='*'){
fl++;
}
}
}
if(fl==0){
cout<<"恭喜你!你赢了!";
return 0;
}
if(fl!=0){
cout<<"可惜!你没能成功。你还差"<<fl<<"个*就赢了!"<<endl;
char s;
return 0;
}
}
}
}
return 0;
}