专栏文章
easyx扫雷
个人记录参与者 1已保存评论 0
文章操作
快速查看文章及其快照的属性,并进行相关操作。
- 当前评论
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mio0mh5z
- 此快照首次捕获于
- 2025/12/02 11:25 3 个月前
- 此快照最后确认于
- 2025/12/02 11:25 3 个月前
CPP
#include<conio.h>
#include<bits/stdc++.h>
#include<easyx.h>
#include<graphics.h>
using namespace std;
const int bn=30;
int f[8]={1,-1,0,0,0,0,-1,1};
bool boom[30][30];
//1雷0无雷
bool flag=0;
bool mp[30][30];
int number[30][30];
bool qi[30][30];
void dfs(int x,int y);
void ai();
signed main(){
srand(time(NULL));
initgraph(20*bn+50,20*bn+50,true);
setlinestyle(PS_SOLID,1);
int boom_cnt=0;
// while(boom_cnt<50){
// int boom_x=rand()%20;
// int boom_y=rand()%20;
// if(boom[boom_x][boom_y]==false){
// boom[boom_x][boom_y]=true;
// boom_cnt++;
// number[boom_x-1][boom_y-1]++;
// number[boom_x-1][boom_y]++;
// number[boom_x-1][boom_y+1]++;
// number[boom_x][boom_y-1]++;
// number[boom_x][boom_y+1]++;
// number[boom_x+1][boom_y-1]++;
// number[boom_x+1][boom_y]++;
// number[boom_x+1][boom_y+1]++;
// }
// }
for(int i=1;i<=50;i++){
int boom_x=rand()%20+1,boom_y=rand()%20+1;
while((boom_x>=9&&boom_x<=11&&boom_y>=9&&boom_y<=11)||boom[boom_x][boom_y]==true){//||d[x][y]=='*'||d[x+1][y]=='*'||d[x][y+1]=='*'||d[x+1][y+1]=='*'||d[x-1][y]=='*'||d[x][y-1]=='*'||d[x-1][y-1]=='*'||d[x+1][y-1]=='*'||d[x-1][y+1]=='*'){
boom_x=rand()%20+1,boom_y=rand()%20+1;
}
boom[boom_x][boom_y]=true;
number[boom_x-1][boom_y-1]++;
number[boom_x-1][boom_y]++;
number[boom_x-1][boom_y+1]++;
number[boom_x][boom_y-1]++;
number[boom_x][boom_y+1]++;
number[boom_x+1][boom_y-1]++;
number[boom_x+1][boom_y]++;
number[boom_x+1][boom_y+1]++;
}
while(true){
BeginBatchDraw();
for(int i=0;i<=20;i++){
line(25,i*bn+25,20*bn+25,i*bn+25);
}
for(int i=0;i<=20;i++){
line(i*bn+25,25,i*bn+25,20*bn+25);
}
for(int i=0;i<20;i++){
for(int j=0;j<20;j++){
if(boom[i][j]==true){
settextstyle(23,0,"楷体");
settextcolor(RGB(255,255,255));
outtextxy(j*bn+25+bn/2-textwidth("雷")/2,i*bn+25+bn/2-textheight("雷")/2,"雷");
}else{
settextstyle(23,0,"微软雅黑");
if(number[i][j]==1){
settextcolor(RGB(63,97,214));
outtextxy(j*bn+25+bn/2-textwidth("1")/2,i*bn+25+bn/2-textheight("1")/2,"1");
}
if(number[i][j]==2){
settextcolor(RGB(63,97,214));
outtextxy(j*bn+25+bn/2-textwidth("2")/2,i*bn+25+bn/2-textheight("2")/2,"2");
}
if(number[i][j]==3){
settextcolor(RGB(63,97,214));
outtextxy(j*bn+25+bn/2-textwidth("3")/2,i*bn+25+bn/2-textheight("3")/2,"3");
}
if(number[i][j]==4){
settextcolor(RGB(63,97,214));
outtextxy(j*bn+25+bn/2-textwidth("4")/2,i*bn+25+bn/2-textheight("4")/2,"4");
}if(number[i][j]==5){
settextcolor(RGB(63,97,214));
outtextxy(j*bn+25+bn/2-textwidth("5")/2,i*bn+25+bn/2-textheight("5")/2,"5");
}if(number[i][j]==6){
settextcolor(RGB(63,97,214));
outtextxy(j*bn+25+bn/2-textwidth("6")/2,i*bn+25+bn/2-textheight("6")/2,"6");
}
if(number[i][j]==7){
settextcolor(RGB(63,97,214));
outtextxy(j*bn+25+bn/2-textwidth("7")/2,i*bn+25+bn/2-textheight("7")/2,"7");
}
if(number[i][j]==8){
settextcolor(RGB(63,97,214));
outtextxy(j*bn+25+bn/2-textwidth("8")/2,i*bn+25+bn/2-textheight("8")/2,"8");
}
}
if(mp[i][j]==false){
setfillcolor(RGB(125,130,125));
solidrectangle(j*bn+25+1,i*bn+25+1,j*bn+bn+25-1,i*bn+bn+25-1);
}
if(qi[i][j]==true){
setfillcolor(RED);
solidrectangle(j*bn+25+15,i*bn+25+5,j*bn+25+25,i*bn+25+17);
line(j*bn+25+15,i*bn+25+5,j*bn+25+15,i*bn+25+25);
}
}
}
if(flag==1){
EndBatchDraw();
Sleep(3000);
return 0;
}
ExMessage msg={0};
if(peekmessage(&msg,EX_MOUSE)){
if(msg.message==WM_LBUTTONDOWN){
for(int i=0;i<20;i++){
for(int j=0;j<20;j++){
if(msg.x>=j*bn+25+1&&msg.y>=i*bn+25+1&&msg.x<=j*bn+bn+25-1&&msg.y<=i*bn+bn+25-1){
mp[i][j]=true;
if(boom[i][j]==1){
flag=1;
}else{
dfs(i,j);
}
break;
}
if(flag==1) break;
}
}
}
if(msg.message==WM_RBUTTONDOWN){
for(int i=0;i<20;i++){
for(int j=0;j<20;j++){
if(mp[i][j]==false&&msg.x>=j*bn+25+1&&msg.y>=i*bn+25+1&&msg.x<=j*bn+bn+25-1&&msg.y<=i*bn+bn+25-1){
qi[i][j]=!qi[i][j];
}
if(flag==1) break;
}
}
}
}
EndBatchDraw();
cleardevice();
}
}
void dfs(int x,int y){
if(number[x][y]!=0){
mp[x][y]=true;
return ;
}
for(int k=0;k<4;k++){
int u=x+f[k],v=y+f[4+k];
if(u>=0&&u<20&&v>=0&&v<20&&mp[u][v]==false&&boom[u][v]==0){
mp[u][v]=true;
dfs(u,v);
}
}
}
void ai(){
}
相关推荐
评论
共 0 条评论,欢迎与作者交流。
正在加载评论...