版本比较
一个扫雷游戏,c++自创
正文
增加 13 行删除 13 行
6 行未改动78910111112131415151617181913 行未改动333435363737383940416 行未改动48495051525253545556565758596061626364656566676869707172737475747576777879798081818283848586878889899091919293949596979898991001011023 行未改动6 行未改动#include <cstdlib>#include <ctime>#include <iomanip>using namespace std;//定义变量 //定义变量 int q[11][11]={},sx,sy,shu=1; int p[11][11]={},ls=0,x,y; bool a=0;//暗棋盘 //暗棋盘void dayin_yin(){ cout<<" | 1| 2| 3| 4| 5| 6| 7| 8| 9| 10"; cout<<endl<<" ________________________________"<<endl; for(int i=1;i<11;i++){13 行未改动 cout<<"--- -------------------------------"; cout<<endl; }}//明棋盘 //明棋盘void dayin_ming(){ cout<<" | 1| 2| 3| 4| 5| 6| 7| 8| 9| 10"; cout<<endl<<" ________________________________"<<endl; for(int i=1;i<11;i++){6 行未改动 cout<<endl; cout<<"--- -------------------------------"; cout<<endl; }} }
int main(){ srand(time(0)); //随机生成雷 //随机生成雷 while(ls<10){ x=rand()%10+1; y=rand()%10+1; if(p[x][y]==0){ p[x][y]= -1; ls++; } } //生成数 //生成数 for(int i=1;i<10;i++){ for(int j=1;j<10;j++){ if(p[i][j] != -1){ for(int x=i-1;x<=i+1;x++){ for(int y=j-1;y<=j+1;y++){ if(p[x][y]==-1){ p[i][j]++; } } } } } } } } //打印 //打印 dayin_yin();
while(1){ cout<<endl<<"请输入信息:行 列 操作(0或1,0为查看,1为标记):"; cin>>sx>>sy>>a; q[sx][sy]=1; if(a){ q[sx][sy]=-1; } //打印 //打印 dayin_yin();
shu++; if(p[sx][sy]==-1 && !a){ cout<<"你输了"<<endl<<endl; dayin_ming(); break; }else if(shu>=90){ cout<<"你赢了"<<endl<<endl; cout<<"你赢了"<<endl<<endl; dayin_ming(); break; } }3 行未改动