#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int main()
{
while(1)
{
char a[13][13]={0};
int b[13][13]={0};
bool c[13][13]={0};
for(int i=1;i<=12;i++)
{
for(int j=1;j<=12;j++)
{
a[i][j]='?';
}
}
int n=0,m,s=0,n2;
string g;
cout<<" 扫雷游戏"<<endl;
cout<<"--------------powered by C.G.P.S-----------------"<<endl;
cout<<endl;
cout<<"请选择难度:"<<endl;
cout<<"1.简单"<<endl;
cout<<"2.中等"<<endl;
cout<<"3.困难"<<endl;
cout<<"请输入:";
cin>>g;
if(g.size()>1||g[0]>'3'||g[0]<'1')
{
system("cls");
cout<<endl<<" 您的输入不正确!";
Sleep(2000);
system("cls");
continue;
}
system("cls");
cout<<" 扫雷游戏"<<endl;
cout<<"--------------powered by C.G.P.S--------------"<<endl;
cout<<endl;
srand(time(0));
if(g=="1")
{
n=rand()%5+1;
m=rand()%3+1;
a[n][m]='*';
n=rand()%4+2;
m=rand()%5+1;
a[n][m]='*';
n=0;
for(int i=1;i<=10;i++)
{
for(int j=1;j<=10;j++)
{
if(a[i][j]=='*')
{
n++;
}
}
}
cout<<"雷数:"<<n<<endl;
n2=n;
n=5;
s=5*5;
}
if(g=="2")
{
n=rand()%10+9;
m=rand()%10+9;
a[n][m]='*';//
n=rand()%8+7;
m=rand()%8+7;
a[n][m]='*';//
n=rand()%6+5;
m=rand()%6+5;
a[n][m]='*';//
n=rand()%5+4;
m=rand()%5+4;
a[n][m]='*';//
n=rand()%3+2;
m=rand()%3+2;
a[n][m]='*';//
n=rand()%10+2;
m=rand()%6+2;
a[n][m]='*';//
n=rand()%10+2;
m=rand()%6+2;
a[n][m]='*';//
n=rand()%8+3;
m=rand()%10+1;
a[n][m]='*';//
n=rand()%3+2;
m=rand()%3+2;
a[n][m]='*';//
n=rand()%10+2;
m=rand()%6+2;
a[n][m]='*';//
n=rand()%10+2;
m=rand()%6+2;
a[n][m]='*';//
n=rand()%8+3;
m=rand()%10+1;
a[n][m]='*';//
n=rand()%3+2;
m=rand()%3+2;
a[n][m]='*';//
n=rand()%10+2;
m=rand()%6+2;
a[n][m]='*';//
n=rand()%10+2;
m=rand()%6+2;
a[n][m]='*';//
n=rand()%8+3;
m=rand()%10+1;
a[n][m]='*';//
n=0;
for(int i=1;i<=10;i++)
{
for(int j=1;j<=10;j++)
{
if(a[i][j]=='*')
{
n++;
}
}
}
cout<<"雷数:"<<n<<endl;
n2=n;
n=10;
s=10*10;
}
if(g=="3")
{
for(int i=1;i<=3;i++)
{
n=rand()%8+1;
m=rand()%12+2;
a[n][m]='*';//
n=rand()%12+1;
m=rand()%8+3;
a[n][m]='*';//
n=rand()%10+6;
m=rand()%8+6;
a[n][m]='*';//
n=rand()%11+2;
m=rand()%12+2;
a[n][m]='*';//
n=rand()%5+1;
m=rand()%9+6;
a[n][m]='*';//
n=rand()%10+7;
m=rand()%12+2;
a[n][m]='*';//
n=rand()%10+7;
m=rand()%12+2;
a[n][m]='*';//
n=rand()%10+7;
m=rand()%12+2;
a[n][m]='*';//
n=rand()%10+7;
m=rand()%12+2;
a[n][m]='*';//
n=rand()%12+7;
m=rand()%6+2;
a[n][m]='*';//
}
n=0;
for(int i=1;i<=12;i++)
{
for(int j=1;j<=12;j++)
{
if(a[i][j]=='*')
{
n++;
}
}
}
cout<<"雷数:"<<n<<endl;
n2=n;
n=12;
s=12*12;
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(a[i][j]=='*')
{
b[i-1][j-1]++;
b[i-1][j]++;
b[i-1][j+1]++;
b[i][j-1]++;
b[i][j+1]++;
b[i+1][j-1]++;
b[i+1][j]++;
b[i+1][j+1]++;
}
}
}
cout<<n<<"*"<<n<<"矩阵"<<endl;
for(int i=1;i<=n+3;i++)
{
cout<<"=";
}
cout<<endl;
cout<<" ";
for(int i=1;i<=n;i++)
{
cout<<i<<" ";
if(i<10)
{
cout<<" ";
}
}
cout<<endl;
cout<<" ";
cout<<endl;
for(int i=1;i<=n;i++)
{
if(i<10)
{
cout<<" ";
}
cout<<i<<"| ";
for(int j=1;j<=n;j++)
{
cout<<"□ ";
}
cout<<endl;
}
int f=1;
while(s>n2)
{
int x,y;
cout<<endl;
cout<<"请输入行号和列号:";
cin>>x>>y;
system("cls");
cout<<" 扫雷游戏"<<endl;
cout<<"--------------powered by C.G.P.S--------------"<<endl;
c[x][y]=1;
cout<<endl;
cout<<"雷数:"<<n2<<endl;
cout<<n<<"*"<<n<<"矩阵"<<endl;
for(int i=1;i<=n+3;i++)
{
cout<<"=";
}
cout<<endl;
cout<<" ";
for(int i=1;i<=n;i++)
{
cout<<i<<" ";
if(i<10)
{
cout<<" ";
}
}
cout<<endl;
cout<<" ";
cout<<endl;
for(int i=1;i<=n;i++)
{
if(i<10)
{
cout<<" ";
}
cout<<i<<"| ";
for(int j=1;j<=n;j++)
{
if(a[x][y]=='*'&&a[i][j]=='*')
{
cout<<a[i][j]<<" ";
}
else if((c[i][j]==1||a[x][y]=='*')&&s>n2)
{
cout<<b[i][j]<<" ";
}
else
{
cout<<"□ ";
}
}
cout<<endl;
}
if(a[x][y]=='*')
{
cout<<endl<<"你扫到雷了!";
Sleep(5000);
system("cls");
cout<<endl<<" 游戏失败!";
Sleep(3000);
f=0;
break;
}
s--;
}
if(f==1)
{
system("cls");
cout<<" 扫雷游戏"<<endl;
cout<<"--------------powered by C.G.P.S--------------"<<endl<<endl;
cout<<"雷数:"<<n2<<endl;
cout<<n<<"*"<<n<<"矩阵"<<endl;
for(int i=1;i<=n+3;i++)
{
cout<<"=";
}
cout<<endl;
cout<<" ";
for(int i=1;i<=n;i++)
{
cout<<i<<" ";
if(i<10)
{
cout<<" ";
}
}
cout<<endl;
cout<<" ";
cout<<endl;
for(int i=1;i<=n;i++)
{
if(i<10)
{
cout<<" ";
}
cout<<i<<"| ";
for(int j=1;j<=n;j++)
{
if(a[i][j]=='*')
{
cout<<a[i][j]<<" ";
}
else
{
cout<<b[i][j]<<" ";
}
}
cout<<endl;
}
cout<<endl<<"游戏胜利!";
Sleep(3000);
}
system("cls");
}
}
11-28
631
04-26
191
03-16
108
03-11
3020
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交