我基本写了一个布尔数组[x] [y],x,y是坐标,如果它的确存在,则会炸弹。
我在吸气剂方面遇到麻烦,
我到目前为止
boolean[][] bombArray = new boolean[Total_Columns][10];
for(x=0,x<Total_Colmns,x++){
bombArray[x][0] = true;
}
public boolean getBombArray(int x,int y){
if(bombArray[x][y] .equals(true){
return true;
}
else{
return false;
}
}
我的主像这样
main()
boolean isBomb = myPanel.getBombArray(x,y) //x and y being the cursor coordinates
if(isBomb){
....
....
....
....
{
else{
....
....
....
}
基本上网格会像这样
*********
......
......
......
......
......
......
......
......
但是我的get不能正常工作,它总是抛出异常
最佳答案
这行:
if(bombArray[x][y] .equals(true){
在花括号前缺少右括号。
您的函数的正确版本是:
public boolean getBombArray(int x,int y){
// bombArray[x][y] has type 'boolean', which isn't an object, it's a primitive
// (don't use .equals() on primitives)
if(bombArray[x][y] == true){
return true;
} else{
return false;
}
}
但是您可以将其显着简化为我认为更清晰的一些东西:
public boolean getBombArray(int x,int y){
// bombArray[x][y] is true if there's a bomb, false otherwise
return bombArray[x][y];
}