java扫雷编程难吗_自己编的控制台扫雷程序谁要

本文介绍了一个简单的扫雷游戏实现方法,包括游戏的核心逻辑、胜利条件判断及游戏结束处理等。通过具体的Java代码展示了如何进行点击操作、判断输赢状态以及显示游戏结果。

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

}

}

}

private void liftclickend(int l, int h) {

try{

liftclick(l-1,h-1);

}

catch(ArrayIndexOutOfBoundsException e){}

try{

liftclick(l-1,h);

}

catch(ArrayIndexOutOfBoundsException e){}

try{

liftclick(l-1,h+1);

}

catch(ArrayIndexOutOfBoundsException e){}

try{

liftclick(l,h-1);

}

catch(ArrayIndexOutOfBoundsException e){}

try{

liftclick(l,h+1);

}

catch(ArrayIndexOutOfBoundsException e){}

try{

liftclick(l+1,h-1);

}

catch(ArrayIndexOutOfBoundsException e){}

try{

liftclick(l+1,h);

}

catch(ArrayIndexOutOfBoundsException e){}

try{

liftclick(l+1,h+1);

}

catch(ArrayIndexOutOfBoundsException e){}

}

private boolean urlose(){

for(int i=0;i<=length-1;i++)

for(int j=0;j<=height-1;j++)

{

if(hasboom[i][j]==true&&clicked[i][j]==true)

return false;

}

return true;

}

private boolean urwon(){

for(int i=0;i<=length-1;i++)

for(int j=0;j

{

if(hasboom[i][j]==false&&clicked[i][j]==false)

return false;

if(hasboom[i][j]==true&&clicked[i][j]==true)

return false;

}

return true;

}

public boolean end(){

if(urlose()==false||urwon()==true)

return true;

else

return false;

}

public void realout(){

for(int i=0;i<=length-1;i++)

{

for(int j=0;j<=height-1;j++)

{

if(hasboom[i][j])

outboom();

else

outnum(number[i][j]);

}

System.out.println();

}

}

private void outnum(int i){

switch(i){

case 0:System.out.print("0");break;

case 1:System.out.print("1");break;

case 2:System.out.print("2");break;

case 3:System.out.print("3");break;

case 4:System.out.print("4");break;

case 5:System.out.print("5");break;

case 6:System.out.print("6");break;

case 7:System.out.print("7");break;

case 8:System.out.print("8");break;

}

}

private void outboom() {

System.out.print("*");

}

public void runout(){

for(int i=0;i<=length-1;i++)

{

for(int j=0;j<=height-1;j++)

{

outs(i,j);

}

System.out.println();

}

}

private void outs(int i, int j) {

if(clicked[i][j]&&hasboom[i][j])

{

System.out.print("*");return;

}

if(clicked[i][j]&&hasboom[i][j]==false)

{

System.out.print(number[i][j]);return;

}

if(clicked[i][j]==false&&locked[i][j])

{

System.out.print("x");return;

}

else

System.out.print("#");

}

public void start(){

Scanner read=new Scanner(System.in);

System.out.println("please input the length,the height and the boom's nnumber");

int b=read.nextInt();

int c=read.nextInt();

int d=read.nextInt();

System.out.println("you hava a new game:length"+b+"\theight"+c+"\tbooms"+d);

set(b,c,d);

setall();

int k=0;

do{

runout();

System.out.println("please input 1 or 2,1=lift click 2=right click");

int a=read.nextInt();

System.out.println("please input where is you click");

int l=read.nextInt();

int h=read.nextInt();

try{

click(a,l-1,h-1);

}

catch(ArrayIndexOutOfBoundsException e){

System.out.println("please inpit the true number");

}

if(end())

k=1;

}while(k!=1);

if(urwon())

System.out.println("you are won!");

else

System.out.println("you are lose!");

realout();

}

public void start(int b,int c,int d){

Scanner read=new Scanner(System.in);

set(b,c,d);

setall();

int k=0;

do{

runout();

System.out.println("please input 1 or 2,1=lift click 2=right click");

int a=read.nextInt();

System.out.println("please input where is you click");

int l=read.nextInt();

int h=read.nextInt();

try{

click(a,l-1,h-1);

}

catch(ArrayIndexOutOfBoundsException e){

System.out.println("please inpit the true number");

}

if(end())

k=1;

}while(k!=1);

if(urwon())

System.out.println("you are won!");

else

System.out.println("you are lose!");

realout();

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值