如何用C语言编程扫雷!~
扫雷
# include & ltstdio.h & gt
# include & ltgraphics.h & gt
# include & ltstdlib.h & gt
结构列表
{
int x;
int y;
int num
int炸弹;
int wa
};
结构列表di[10][10];
int currentx = 210;
int currenty = 130;
void initxy(void)
{
int i,j;
for(I = 0;我& lt=9;i++)
for(j = 0;j & lt=9;j++)
{
迪[j]。x = I * 20+200;
迪[j]。y = j * 20+120;
迪[j]。wa = 0;
迪[j]。炸弹= 0;
}
}
void initmu(void)
{
int i,j;
set color(2);
矩形(200,120,400,320);
矩形(190,110,410,330);
setfillstyle(8,14);
漫填(191,111,2);
for(I = 0;我& lt=9;i++)
for(j = 0;j & lt=9;j++)
矩形(di[j].x,di[j]。y,di[j]。x+19,第[j]号。y+19);
outtextxy(450,200,“按‘回车’踢”);
outtextxy(450,250,"按' \ '标记");
}
无效随机炸弹(无效)
{
int k;
int i,j;
randomize();
for(I = 0;我& lt=9;i++)
for(j = 0;j & lt=9;j++)
{
k =随机(5);
如果(k==2)
迪[j]。炸弹= 1;
}
}
void计算(void)
{
int k = 0;
int i,j;
for(I = 0;我& lt=9;i++)
for(j = 0;j & lt=9;j++)
{
如果(我& amp& amp强生公司。& ampdi[i-1][j-1]。炸弹)
k = k+1;
如果(我& amp& amp第[i-1][j]。炸弹)
k = k+1;
如果(j & amp& amp迪[j-1]。炸弹)
k = k+1;
如果(我& lt= 8 & amp& ampdi[i+1][j]。炸弹)
k = k+1;
if(j & lt;= 8 & amp& ampdi[j+1]。炸弹)
k = k+1;
如果(我& lt= 8 & amp& ampj & lt= 8 & amp& ampdi[i+1][j+1]。炸弹)
k = k+1;
如果(我& amp& ampj & lt= 8 & amp& ampdi[i-1][j+1]。炸弹)
k = k+1;
如果(我& lt= 8 & amp& amp强生公司。& ampdi[i+1][j-1]。炸弹)
k = k+1;
迪[j]。num = k;
k = 0;
}
}
空仙弹(void)
{
int i,j;
char表记[2];
炭化锌[2];
biaoji[0]= 1;
biaoji[1]= NULL;
for(I = 0;我& lt=9;i++)
for(j = 0;j & lt=9;j++)
{
if(di[j].炸弹==1)
outtextxy(di[j].x+2,di[j]。y+2,标基);
其他
{
itoa(di[j].num,znum,10);
setfillstyle(1,0);
杠(i*20+202,j*20+122,i*20+218,j * 20+138);
outtextxy(i*20+202,j*20+122,znum);
}
}
}
无效移动(无效)
{
int键;
key = BIOS key(1);
如果(关键)
key = BIOS key(0);
if(key==0x4800)
{
if(currenty & gt;130)
{
set color(0);
circle(currentx,currenty,5);
电流-= 20;
set color(4);
circle(currentx,currenty,5);
}
其他
{
set color(0);
circle(currentx,currenty,5);
currenty = 310;
set color(4);
circle(currentx,currenty,5);
}
}
if(key==0x4b00)
{
if(currentx & gt;210)
{
set color(0);
circle(currentx,currenty,5);
currentx-= 20;
set color(4);
circle(currentx,currenty,5);
}
其他
{
set color(0);
circle(currentx,currenty,5);
currentx = 390
set color(4);
circle(currentx,currenty,5);
}
}
if(key==0x4d00)
{
if(currentx & lt;390)
{
set color(0);
circle(currentx,currenty,5);
currentx+= 20;
set color(4);
circle(currentx,currenty,5);
}
其他
{
set color(0);
circle(currentx,currenty,5);
currentx = 210;
set color(4);
circle(currentx,currenty,5);
}
}
if(key==0x5000)
{
if(currenty & lt;310)
{
set color(0);
circle(currentx,currenty,5);
当前+= 20;
set color(4);
circle(currentx,currenty,5);
}
其他
{
set color(0);
circle(currentx,currenty,5);
currenty = 130;
set color(4);
circle(currentx,currenty,5);
}
}
if(key==0x1c0d)
{
int i,j;
char snum[2];
snum[0]= NULL;
snum[1]= NULL;
I =(currentx-210)/20;
j =(currenty-130)/20;
if(di[j].炸弹==1)
{
outtextxy(100,100,“游戏结束”);
xian bomb();
睡眠(2);
退出(0);
}
if(di[j].炸弹==0)
{
迪[j]。wa = 1;
setfillstyle(1,0);
bar(currentx-8,currenty-8,currentx+8,currenty+8);
set color(15);
itoa(di[j].num,snum,10);
outtextxy(currentx-8,currenty-8,snum);
set color(4);
circle(currentx,currenty,5);
}
}
if(key==0x2b5c)
{
char表记[2];
biaoji[0]= 1;
biaoji[1]= NULL;
set color(0);
bar(currentx-8,currenty-8,currentx+8,currenty+8);
set color(4);
outtextxy(currentx-8,currenty-8,biaoji);
circle(currentx,currenty,5);
}
}
作废成功(void)
{
int k = 1;
int i,j;
for(I = 0;我& lt=9;i++)
for(j = 0;j & lt=9;j++)
if(di[j].炸弹= = 0 & amp& amp迪[j]。wa==0)
k = 0;
如果(k==1)
{
outtextxy(100,100,“成功好”);
xian bomb();
睡眠(2);
退出(0);
}
}
无效总管(无效)
{
int gd=DETECT,GM;
init graph(& amp;gd,& ampgm,“”;
initxy();
initmu();
rand bomb();
吉苏安();
set color(4);
圆(210,130,5);
while(1)
{
move();
success();
}
}