所以我必须为一个任务写一个扫雷游戏。如果我为 Board 创建了一个类,其中包含两个 2D 数组,一个用于 board 值,一个用于保存用户是否已点击或未点击。我用两个二维数组的参数编写了方法。我将如何在我的主类中调用这些数组?
public class Board {
int x;
int y;
public char[][] board;
public char[][] reveal;
Board(int x, int y){
board = new char[x][y];
reveal = new boolean[x][y];
}
}
public class Mine{
public static void main(String[] args){
Board gameboard;
gameboard = new Board(5, 5);
???
Board.printBoard(board, reveal);
}
}
public void printBoard(char[][] board, boolean[][] test){
for(int i=0; i<=board.length; i+=1){
for(int j=0; j<board[i].length; j+=1){
if (test[i][j]==true){
System.out.print(board[i][j]);
}
else {
System.out.print('?');
}
}
System.out.println();
}
}