失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > java扫雷随机地雷_原创扫雷(未添加随机分布地雷) 想看就进来看下吧

java扫雷随机地雷_原创扫雷(未添加随机分布地雷) 想看就进来看下吧

时间:2022-05-22 05:34:28

相关推荐

java扫雷随机地雷_原创扫雷(未添加随机分布地雷) 想看就进来看下吧

该楼层疑似违规已被系统折叠隐藏此楼查看此楼

/* 里面涉及的知识主要是递归和数组 */

#include "stdio.h"

#include "conio.h"

int count=0;

void mark(int mobang[11][11],char xianxi[11][11],int x,int y)

{

xianxi[x][y]=' ';count++;

if((x-1)<1||(y-1)<1||(xianxi[x-1][y-1]==' '));else { if(mobang[x-1][y-1]!=0){xianxi[x-1][y-1]=' ';count++;} else mark(mobang,xianxi,x-1,y-1);}

if((x-1)<1||(xianxi[x-1][y]==' '));else { if(mobang[x-1][y]!=0){xianxi[x-1][y]=' ';count++;} else mark(mobang,xianxi,x-1,y);}

if((x-1)<1||(y+1)>9||(xianxi[x-1][y+1]==' '));else { if(mobang[x-1][y+1]!=0){xianxi[x-1][y+1]=' ';count++;} else mark(mobang,xianxi,x-1,y+1);}

if((y-1)<1||(xianxi[x][y-1]==' '));else { if(mobang[x][y-1]!=0){xianxi[x][y-1]=' ';count++;} else mark(mobang,xianxi,x,y-1);}

if((y+1)>9||(xianxi[x][y+1]==' '));else { if(mobang[x][y+1]!=0){xianxi[x][y+1]=' ';count++;} else mark(mobang,xianxi,x,y+1);}

if((x+1)>9||(y-1)<1||(xianxi[x+1][y-1]==' '));else { if(mobang[x+1][y-1]!=0){xianxi[x+1][y-1]=' ';count++;} else mark(mobang,xianxi,x+1,y-1);}

if((x+1)>9||(xianxi[x+1][y]==' '));else { if(mobang[x+1][y]!=0){xianxi[x+1][y]=' ';count++;} else mark(mobang,xianxi,x+1,y);}

if((x+1)>9||(y+1)>9||(xianxi[x+1][y+1]==' '));else { if(mobang[x+1][y+1]!=0){xianxi[x+1][y+1]=' ';count++;} else mark(mobang,xianxi,x+1,y+1);}

}

int main(void)

{

int mobang[11][11]={0};

char xianxi[11][11]={'*'};

int i,j;

int count1=0;

int zhonglei=0;

int flag1=0;

int flag2=0;

int choice1,choice2;

mobang[1][2]=mobang[2][7]=mobang[2][8]=9;

mobang[5][5]=mobang[6][4]=mobang[7][4]=9;

mobang[8][7]=mobang[9][1]=mobang[9][7]=9;

for(i=1;i<10;i++)

{

for(j=1;j<10;j++)

{

if(mobang[i][j]==9);

else {

if(mobang[i-1][j-1]==9) count1++;

if(mobang[i-1][j]==9) count1++;

if(mobang[i-1][j+1]==9) count1++;

if(mobang[i][j-1]==9) count1++;

if(mobang[i][j+1]==9) count1++;

if(mobang[i+1][j-1]==9) count1++;

if(mobang[i+1][j]==9) count1++;

if(mobang[i+1][j+1]==9) count1++;

mobang[i][j]=count1;

}

count1=0;

}

}

for(i=1;i<11;i++)

for(j=1;j<11;j++) xianxi[i][j]='*';

while(1)

{

printf(" 1 2 3 4 5 6 7 8 9 ");

for(i=1;i<10;i++)

{

if(i!=1)printf("\n ---------------------------\n %d|",i);else printf("\n ===========================\n %d|",i);

for(j=1;j<10;j++)

{

if(xianxi[i][j]=='*')printf(" *|");

else

{

switch(mobang[i][j])

{

case 0: printf(" |");break;

case 1:case 2:case 3:case 4:case 5:case 6:case 7:case 8: printf("%2d|",mobang[i][j]);break;

case 9: printf(" #|");break;

default:;

}

}

}

}

if(zhonglei==1||count>=72)break;

printf("\n\n\n\n\nInput a number:");

count1=0;

flag1=0;

flag2=0;

while(1)

{

switch(count1)

{

case 0: {choice1=getchar(); if(choice1==10){ choice1=0;flag1=1; break;}}

case 1: {choice2=getchar(); if(choice2==10){ choice2=0;flag1=1; break;}}

default: if(getchar()=='\n') flag2=1;

}

if(flag1==1||flag2==1)break;

count1++;

}

if(flag1==1||choice1<49||choice1>57||choice2<49||choice2>57)continue;else {choice1-=48;choice2-=48;}

if(xianxi[choice1][choice2]==' ')continue;

if(mobang[choice1][choice2]==9){xianxi[choice1][choice2]=' ';zhonglei=1;}

else {

if(mobang[choice1][choice2]!=0) {xianxi[choice1][choice2]=' ';count++;}

else mark(mobang,xianxi,choice1,choice2);

}

}

if(zhonglei==1)printf("\n\n\n\nYou lose! GAME OVER!");

else printf("\n\n\n\nWell done, my hero! You win!");

getch();

return 0;

}

如果觉得《java扫雷随机地雷_原创扫雷(未添加随机分布地雷) 想看就进来看下吧》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。