I'm trying to create a minesweeper clone for school and looking to create a variable board size, the below code works to create a 2d minefield but I get an arrayIndex out of bounds error when columns != rows. Any help would be appreciated. Amateur code so any other advice is welcome.
public void genBoard(int columns, int rows) {
board = new Tile[rows][columns];
for (int y = 0; y < rows; y++) {
for (int x = 0; x < board[y].length + 1; x++) {
board[x][y] = new Tile(x, y, 0, false);
}
}
}
[rows][cols](swapping method argument order for some reason. You then loopyoverrowsandxover cols. Finally you assign[x][y]- i.e.[cols][rows].x < board[y].length + 1- why +1 ?