SAE21_2022/src/Grid.java

40 lines
1.1 KiB
Java
Raw Normal View History

public class Grid {
private Square[][] squares;
private Thesee thesee = new Thesee();
public Grid(int size) {
this.squares = new Square[size][size];
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
this.squares[i][j] = new Square(this, i, j);
2023-04-11 09:45:48 +02:00
}
}
}
/**
* Get the grid's size (number of squares on a row/column)
* @return The grid's size
*/
public int getSize() {
return this.squares.length;
2023-04-11 09:45:48 +02:00
}
/**
* Get a square from the grid
* @param row The row of the square
* @param column The column of the square
* @return The square at the given position
* @throws Exception If the position is out of grid's bounds
*/
public Square getSquare(int row, int column) throws Exception {
try {
return this.squares[row][column];
} catch (ArrayIndexOutOfBoundsException e) {
throw new Exception("No square found at position (" + row + ", " + column + ")");
2023-04-11 09:45:48 +02:00
}
}
public Thesee getThesee() {
return this.thesee;
2023-04-11 09:45:48 +02:00
}
}