这个扫雷非常难,2500个格子,500个雷
#include<bits/stdc++.h>
using namespace std;
char m[51][51],rm[51][51];
int bombs=500;
//int bxy[501][501];
int d[8][2]={{0,1},{0,-1},{1,1},{-1,1},{1,0},{-1,0},{-1,-1},{1,-1}};
void tancha(int x,int y){
int t=0;
if(rm[x+1][y+1]=='*') t++;
if(rm[x+1][y-1]=='*') t++;
if(rm[x-1][y+1]=='*') t++;
if(rm[x-1][y-1]=='*') t++;
if(rm[x][y+1]=='*') t++;
if(rm[x][y-1]=='*') t++;
if(rm[x+1][y]=='*') t++;
if(rm[x-1][y]=='*') t++;
if(t>0){
m[x][y]=char(t+'0');
rm[x][y]=char(t+'0');
}
else{
for(int i=0;i<8;i++){
tancha(x+d[i][0],y+d[i][1]);
}
}
return;
}
void start() {
for(int i=1; i<=50; i++) {
for(int j=1; j<=50; j++) {
m[i][j]='=';
rm[i][j]='=';
}
}
for(int i=1;i<=500;i++){
srand(time(0));
int bx=rand()%50+1;
int by=rand()%50+1;
while(rm[bx][by]=='*'){
bx=rand()%50+1;
by=rand()%50+1;
}
rm[bx][by]='*';
}
while(1) {
system("cls");
for(int i=1; i<=50; i++) {
for(int j=1; j<=50; j++) {
cout<<m[i][j]<<' ';
}
cout<<endl;
}
cout<<"还剩"<<bombs<<"个雷\n";
int x,y;
cout<<"请输入你要操作的格子的坐标:";
cin>>x>>y;
cout<<"你要做什么?\n";
cout<<"1.探查 2.排雷\n";
int p;
cin>>p;
if(p==1){
if(rm[x][y]=='*'){
cout<<"你踩中了雷!";
system("pause");
return;
}
else tancha(x,y);
}
else if(p==2){
if(rm[x][y]=='*')
bombs--;
m[x][y]='!';
rm[x][y]='!';
}
if(bombs==0){
cout<<"你胜利了!\n";
system("pause");
}
}
}
int main() {
system("color 07");
cout<<"扫雷(地狱难度)\n";
system("pause");
start();
}
大家给个赞吧
标签:1.0,cout,++,51,c++,char,int,小游戏,rm From: https://blog.csdn.net/piaojunhe_0825/article/details/137391733