下载包
扫雷规则介绍:
游戏目标:在不点击到地雷的情况下,揭开所有安全格子。
棋盘构成:由若干格子组成的矩阵,格子数量及地雷分布随难度递增。
操作方式:左键点击揭开格子,若该格子为雷则失败;若周边有雷,则显示雷数。 右键单击标记可疑地雷,双击快速揭开周围无雷的格子。
胜利条件:成功标记所有地雷并揭开所有非雷格子。
失败条件:点击到地雷格子,游戏结束。
游戏说明:
点击笑脸可以重新开始,开始游戏默认中级难度,可以选择难度直接开始游戏,点击返回回到界面
版本介绍:
目前这个版本的扫雷是专门为Dev-C++量身定做的,也就是Dev-C++版
这个扫雷的70%是由网上一位大主包写的,剩下的30%是由作者本入写的,调整了一下在Dev-C++里无法使用的代码,搞了点加载动画
市面上的扫雷基本都不适配于Dev-C++
温馨提示:
请不要修改文件里的图片名和文件夹名,否则可能会报错
源代码可以找我要
运行源代码时要有EasyX库,不然会报错
看到我的题解记得点赞!
文章作者:gf25051
//扫雷源代码
//要搭配下载包和EasyX库
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <graphics.h>
int grahight=415;
int grawidth=340;
#define allhight 100
#define allwidth 100
int hight=17;
int width=17;
int times=0;
int time1=0,time2=0,time3=0;
int first=1;
int bomb=45;
int runing=1;
int smiles=0;
int ture=1;
int a=1;
int map[allhight+2][allwidth+2]= {0};
clock_t start_t,end_t;
IMAGE block[13];
IMAGE smile[4];
IMAGE numbomb[10];
int numbombs=0;
int numbombss=0;
int win=0;
int choice=0;
void printfmap();
void updategame();
int findbomb(int a,int b);
void theloadimage();
void playgame();
void newgame();
void whitchtouch2();
void showbomb();
void openzero(int m,int n);
void whitchtouth();
void printfmaps() {
for(int i=1; i<=hight; i++) {
printf("第%d行:",i);
for(int j=1; j<=width; j++) {
int a=(j-1)*20;
int b=(i-1)*20+72;
printf("%3d",map[i][j]);
}
printf("\n");
}
}
void before();
int main() {
HWND hwnd=initgraph(grawidth,grahight);
setbkcolor(RGB(189,189,189));
cleardevice();
IMAGE img;
loadimage(&img,_T("img/咸鱼.png"),getwidth(),getheight());
putimage(0,0,&img);
Sleep(2000);
cleardevice();
IMAGE img2;
loadimage(&img2,_T("img/扫雷.png"),getwidth(),getheight());
putimage(0,0,&img2);
Sleep(2000);
cleardevice();
IMAGE img3;
loadimage(&img3,_T("img/小黄工作室.png"),getwidth(),getheight());
putimage(0,0,&img3);
Sleep(2000);
cleardevice();
while(ture) {
settextcolor(BLACK);
rectangle(80,50,250,120);
outtextxy(130,80,"开始游戏");
rectangle(80,150,250,220);
outtextxy(130,180,"难度设置");
outtextxy(30,280,"游戏说明:");
outtextxy(105,280,"点击笑脸可以重新开始,开始");
outtextxy(105,305,"游戏默认中级难度,可以选择");
outtextxy(105,330,"难度直接开始游戏,点击返回");
outtextxy(105,355,"回到界面");
whitchtouth();
}
cleardevice();
while(choice) {
settextcolor(BLACK);
rectangle(80,50,250,120);
outtextxy(130,80,"初级");
rectangle(80,150,250,220);
outtextxy(130,180,"中级");
rectangle(80,250,250,320);
outtextxy(130,280,"高级");
whitchtouch2();
}
initgraph(grawidth,grahight);
setbkcolor(RGB(189,189,189));
cleardevice();
numbombss=bomb%10;
numbombs=bomb/10;
theloadimage();
updategame();
printfmaps();
while(1) {
printfmap();
playgame();
if(win==hight*width-bomb&&a) {
a=0;
smiles=3;
printfmap();
MessageBox(hwnd,"you win the game!","",MB_OK);
}
if(smiles==1) {
first=1;
a=1;
win=0;
system("cls");
newgame();
printfmaps();
}
end_t=clock();
int q=(end_t-start_t)/1000;
if(runing==1&&first==0&&win!=hight*width-bomb) {
time1=q/100;
time2=q/10%10;
time3=q%10;
}
if(first==1) {
time1=time2=time3=0;
}
}
closegraph();
return 0;
}
void printfmap() {
outtextxy(grawidth/2-25,0,"返回");
putimage(grawidth/2-20,30,&smile[smiles]);
putimage(10,10,&numbomb[numbombs]);
putimage(40,10,&numbomb[numbombss]);
putimage(grawidth-90,10,&numbomb[time1]);
putimage(grawidth-60,10,&numbomb[time2]);
putimage(grawidth-30,10,&numbomb[time3]);
putimage(grawidth-60, grahight-30, &block[0]);
outtextxy(grawidth-55, grahight-25, "关于游戏");
for(int i=1; i<=hight; i++) {
for(int j=1; j<=width; j++) {
int a=(j-1)*20;
int b=(i-1)*20+72;
if(map[i][j]<=28&&map[i][j]>=19)
putimage(a,b,&block[0]);
else if(map[i][j]<=8&&map[i][j]>=-1) {
switch(map[i][j]) {
case-1:
putimage(a,b,&block[9]);
break;
case 0:
putimage(a,b,&block[10]);
break;
case 1:
putimage(a,b,&block[1]);
break;
case 2:
putimage(a,b,&block[2]);
break;
case 3:
putimage(a,b,&block[3]);
break;
case 4:
putimage(a,b,&block[4]);
break;
case 5:
putimage(a,b,&block[5]);
break;
case 6:
putimage(a,b,&block[6]);
break;
case 7:
putimage(a,b,&block[7]);
break;
case 8:
putimage(a,b,&block[8]);
break;
}
} else if(map[i][j]<=48&&map[i][j]>=39)
putimage(a,b,&block[11]);
else if(map[i][j]==-100)
putimage(a,b,&block[12]);
}
}
}
void updategame() {
srand((unsigned int)time(NULL));
int n=0;
while(n<bomb) {
int x=rand()%hight+1;
int y=rand()%width+1;
if(map[x][y]==0&&x!=0&&y!=0) {
map[x][y]=-1;
n++;
}
}
for(int i=1; i<=hight; i++) {
for(int j=1; j<=width; j++) {
if(map[i][j]==0) {
int sign=0;
sign=findbomb(i,j);
map[i][j]=sign;
}
}
}
for(int i=1; i<=hight; i++) {
for(int j=1; j<=width; j++) {
map[i][j]+=20;
}
}
}
int findbomb(int a,int b) {
int all=0;
for(int i=a-1; i<=a+1; i++) {
for(int j=b-1; j<=b+1; j++) {
if(map[i][j]==-1) {
all++;
}
}
}
return all;
}
void theloadimage() {
loadimage(&block[0],"img/方块.png",20,20);
loadimage(&block[1],"img/11.png",20,20);
loadimage(&block[2],"img/22.png",20,20);
loadimage(&block[3],"img/33.png",20,20);
loadimage(&block[4],"img/44.png",20,20);
loadimage(&block[5],"img/55.png",20,20);
loadimage(&block[6],"img/66.png",20,20);
loadimage(&block[7],"img/77.png",20,20);
loadimage(&block[8],"img/88.png",20,20);
loadimage(&block[9],"img/bom.png",20,20);
loadimage(&block[10],"img/方块2.png",20,20);
loadimage(&block[11],"img/flag.png",20,20);
loadimage(&block[12],"img/red-bom.png",20,20);
loadimage(&smile[0],"img/笑脸.png",30,30);
loadimage(&smile[1],"img/笑脸2.png",30,30);
loadimage(&smile[2],"img/dead.png",30,30);
loadimage(&smile[3],"img/cool.png",30,30);
loadimage(&numbomb[0],"img/0.png",30,50);
loadimage(&numbomb[1],"img/1.png",30,50);
loadimage(&numbomb[2],"img/2.png",30,50);
loadimage(&numbomb[3],"img/3.png",30,50);
loadimage(&numbomb[4],"img/4.png",30,50);
loadimage(&numbomb[5],"img/5.png",30,50);
loadimage(&numbomb[6],"img/6.png",30,50);
loadimage(&numbomb[7],"img/7.png",30,50);
loadimage(&numbomb[8],"img/8.png",30,50);
loadimage(&numbomb[9],"img/9.png",30,50);
}
void playgame() {
if(MouseHit()) {
MOUSEMSG msg=GetMouseMsg();
int x=msg.x;
int y=msg.y;
switch(msg.uMsg) {
case WM_LBUTTONDOWN:
if(x>=0&&x<=grawidth&&y>=72&&y<=grahight&&runing&&smiles!=3) {
if(first==1) {
start_t=clock();
first=0;
}
x=x/20+1;
y=(y-72)/20+1;
if(map[y][x]<=28&&map[y][x]>=19) {
if(map[y][x]==20) {
openzero(y,x);
} else {
map[y][x]-=20;
win++;
if(map[y][x]==-1)
win--;
}
}
if(map[y][x]==-1) {
map[y][x]=-100;
showbomb();
smiles=2;
printfmap();
runing=0;
}
} else if(x>=grawidth/2-20&&x<=grawidth/2+10&&y>=20&&y<=55) {
smiles=1;
runing=1;
} else if(x>=grawidth/2-25&&x<=grawidth/2+10&&y>=0&&y<=19) {
before();
printf("1\n");
} else if(x>=grawidth-60&&x<=grawidth-30&&y>=grahight-30&&y<=grahight-10) {
ShellExecute(NULL, "open", "关于游戏.txt", NULL, NULL, SW_SHOW);
}
break;
case WM_LBUTTONUP:
if(runing==1&&win!=hight*width-bomb)
smiles=0;
break;
case WM_RBUTTONDOWN:
if(x>=0&&x<=grawidth&&y>=72&&y<=grahight&&runing==1) {
if(first==1) {
start_t=clock();
first=0;
}
x=x/20+1;
y=(y-72)/20+1;
if(map[y][x]<=28&&map[y][x]>=19) {
map[y][x]+=20;
} else if(map[y][x]<=48&&map[y][x]>=39) {
map[y][x]-=20;
}
}
break;
}
}
}
void openzero(int m,int n) {
map[m][n]-=20;
win++;
for(int i=m-1; i<=m+1; i++) {
for(int j=n-1; j<=n+1; j++) {
if(i>=1&&i<=width&&j>=1&&j<=hight) {
if(map[i][j]<=28&&map[i][j]>=19) {
if(map[i][j]!=20) {
map[i][j]-=20;
win++;
} else
openzero(i,j);
}
}
}
}
}
void newgame() {
for(int i=1; i<=hight; i++) {
for(int j=1; j<=width; j++) {
map[i][j]=0;
}
}
updategame();
}
void whitchtouth() {
MOUSEMSG msg=GetMouseMsg();
int x=msg.x;
int y=msg.y;
switch(msg.uMsg) {
case WM_LBUTTONDOWN:
if(x>=80&&x<=250&&y>=50&&y<=120) {
ture=0;
} else if(x>=80&&x<=250&&y>=150&&y<=220) {
ture=0;
choice=1;
}
break;
}
}
void showbomb() {
int i,j;
for(i=1; i<=hight; i++) {
for(j=1; j<=width; j++) {
if(map[i][j]==19) {
map[i][j]-=20;
}
}
}
}
void whitchtouch2() {
MOUSEMSG msg=GetMouseMsg();
int x=msg.x;
int y=msg.y;
switch(msg.uMsg) {
case WM_LBUTTONDOWN:
if(x>=80&&x<=250&&y>=50&&y<=120) {
choice=0;
cleardevice();
hight=10;
width=10;
grahight=275;
grawidth=200;
bomb=15;
} else if(x>=80&&x<=250&&y>=150&&y<=220) {
cleardevice();
choice=0;
hight=17;
width=17;
grahight=415;
grawidth=340;
bomb=45;
} else if(x>=80&&x<=250&&y>=250&&y<=320) {
cleardevice();
choice=0;
hight=20;
width=20;
grahight=475;
grawidth=400;
bomb=60;
}
break;
}
}
void before() {
for(int i=1; i<=hight; i++) {
for(int j=1; j<=width; j++) {
map[i][j]=0;
}
}
ture=1;
choice=0;
first=1;
smiles=0;
runing=1;
win=0;
a=1;
system("cls");
initgraph(340,415);
setbkcolor(RGB(189,189,189));
cleardevice();
while(ture) {
settextcolor(BLACK);
rectangle(80,50,250,120);
outtextxy(130,80,"开始游戏");
rectangle(80,150,250,220);
outtextxy(130,180,"难度设置");
outtextxy(30,280,"游戏说明:");
outtextxy(105,280,"点击笑脸可以重新开始,开始");
outtextxy(105,305,"游戏默认中级难度,可以选择");
outtextxy(105,330,"难度直接开始游戏,点击返回");
outtextxy(105,355,"回到界面");
whitchtouth();
}
cleardevice();
while(choice) {
settextcolor(BLACK);
rectangle(80,50,250,120);
outtextxy(130,80,"初级");
rectangle(80,150,250,220);
outtextxy(130,180,"中级");
rectangle(80,250,250,320);
outtextxy(130,280,"高级");
whitchtouch2();
}
initgraph(grawidth,grahight);
setbkcolor(RGB(189,189,189));
cleardevice();
numbombss=bomb%10;
numbombs=bomb/10;
updategame();
printfmaps();
}