直接上代码:
#include<bits/stdc++.h>
using namespace std;
int a[11][11],l,open[11][11];
int main()
{
for(int i=1;i<=10;i++)
for(int j=1;j<=10;j++)
{
system("cls");
cout<<"Making Maps \n( "<<i<<" , "<<j<<" ) / ( 10 , 10 )\n";
_sleep(1000);
srand(time(0));
int n=rand()%10;
if(n==1||n==9)
{a[i][j]=-1;l++;}
}
for(int i=1;i<=10;i++)
for(int j=1;j<=10;j++)
{
if(a[i][j]!=-1)
{
if(a[i][j+1]==-1)a[i][j]++;
if(a[i][j-1]==-1)a[i][j]++;
if(a[i+1][j]==-1)a[i][j]++;
if(a[i-1][j]==-1)a[i][j]++;
if(a[i+1][j+1]==-1)a[i][j]++;
if(a[i+1][j-1]==-1)a[i][j]++;
if(a[i-1][j-1]==-1)a[i][j]++;
if(a[i-1][j+1]==-1)a[i][j]++;// the blocks around
}
}
for(int i=1;i<=100-l;i++)
{
system("cls");
cout<<l<<" Bombs Left\n";
cout<<" 1 2 3 4 5 6 7 8 9 10 x"<<endl;
for(int i=1;i<=10;i++)
{
if(i<=9)
cout<<i<<" ";
else cout<<i<<" ";
for(int j=1;j<=10;j++)
{
if(open[i][j]==0)
cout<<"? ";
else cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<"y You will open ... (y x)";
int x,y;
cin>>x>>y;
open[x][y]=1;
if(a[x][y]==-1)
{
system("cls");
cout<<"YOU DIED !";
return 0;
}
}
system("cls");
cout<<"YOU WIN !";
return 0;
}
为了更准确的随机数,游戏初始化需要100秒。
记得关注哦!