该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
}
}
}
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();
}
}
本文介绍了一个简单的扫雷游戏实现方法,包括游戏的核心逻辑、胜利条件判断及游戏结束处理等。通过具体的Java代码展示了如何进行点击操作、判断输赢状态以及显示游戏结果。
2167

被折叠的 条评论
为什么被折叠?



