自己做的扫雷游戏,报错求调,闭关
SDchenyihang · · 个人记录
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a[11][11]={0},i,c,x=0;
bool is_p=0;
srand(time(0));
while(i<10)
{
int b=rand()%9+1;
int c=rand()%9+1;
if(a[b][c]==0)
{
a[b][c]=-1;
i++;
}
}
for(int j=1;j<=9;j++)
{
for(int k=1;k<=9;k++)
{
if(a[j][k]!=-1)
{
for(int x=j-1;x<=j+1;x++)
{
for(int y=k-1;y<=k+1;y++)
{
if(a[x][y]==-1)
{
a[j][k]++;
}
}
}
}
}
}
for(int t=1;t<=9;t++)
{
for(int e=1;e<=9;e++)
{
cout<<setw(2)<<"*"<<" ";
}
cout<<endl;
}
int x,y;
bool flag[11][11]={0};
do
{
cout<<"___________________________________________________________________________";
cout<<"请输入两个数字,代表你要点开的位置(第几行第几列)"<<endl;
cin>>x>>y;
flag[x][y]=1;
for(int i=1;i<=9;i++)
{
for(int j=1;j<=9;j++)
{
if(flag[i][j]==1)
{
cout<<setw(2)<<a[i][j]<<" ";
if(a[i][j]==-1)
{
cout<<"恭喜你,找到了对方的一颗雷!" ;
x++;
}
}
else
{
cout<<setw(2)<<"*"<<" ";
}
}
cout<<endl;
}
}
while(a[x][y]!=-1);
if(x==10)
{
cout<<"恭喜你,成为为了一名合格的工兵!"
}
return 0;
}
我不知道错在哪
我猜是最后判断和x,y
再见, 宣传一下
休闲游戏