diff --git a/src/Grid.java b/src/Grid.java new file mode 100644 index 0000000..a0cff7e --- /dev/null +++ b/src/Grid.java @@ -0,0 +1,43 @@ +import java.util.Arrays; + +public class Grid { + private Square[][] grid; + + public Grid(int taille) { + this.grid = new Square[taille][taille]; + for (int i = 0; i < taille; i++) { + for (int j = 0; j < taille; j++) { + this.grid[i][j] = new Square(i, j); + } + } + } + + public void setWall(int x, int y) throws ArrayIndexOutOfBoundsException { + this.grid[x][y].setWall(); + } + + public void setExit(int x, int y) throws ArrayIndexOutOfBoundsException { + for (Square[] line : this.grid) { + for (Square square : line) { + if (square.isExit()) square.setEmpty(); + } + } + this.grid[x][y].setExit(); + } + + public int getRows() { + return this.grid.length; + } + + public int getColumns() { + return this.grid[0].length; + } + + public boolean isWall(int x, int y) { + return this.grid[x][y].isWall(); + } + + public boolean isExit(int x, int y) { + return this.grid[x][y].isEmpty(); + } +} \ No newline at end of file diff --git a/src/GridController.java b/src/GridController.java new file mode 100644 index 0000000..3e80b63 --- /dev/null +++ b/src/GridController.java @@ -0,0 +1,29 @@ +public class GridController { + private Grid model; + private GridView view; + + public GridController(Grid model, GridView view) { + this.model = model; + this.view = view; + } + + public void setGridExit(int x, int y) { + this.model.setExit(x, y); + } + + public void setGridWall(int x, int y) { + this.model.setWall(x, y); + } + + public boolean isGridWall(int x, int y) { + return this.model.isWall(x, y); + } + + public boolean isGridExit(int x, int y) { + return this.model.isExit(x, y); + } + + public void updateView() { + this.view.printGridInfo(this.model.getRows(), this.model.getColumns()); + } +} diff --git a/src/GridView.java b/src/GridView.java new file mode 100644 index 0000000..c199432 --- /dev/null +++ b/src/GridView.java @@ -0,0 +1,5 @@ +public class GridView { + public void printGridInfo(int rows, int columns) { + System.out.println("Grid size: " + rows + "x" + columns); + } +} diff --git a/src/Square.java b/src/Square.java new file mode 100644 index 0000000..c998045 --- /dev/null +++ b/src/Square.java @@ -0,0 +1,42 @@ +public class Square { + private final int row; + private final int column; + private int type = 0; + + public Square(int row, int column) { + this.row = row; + this.column = column; + } + + public int getRow() { + return this.row; + } + + public int getColumn() { + return this.column; + } + + public boolean isWall() { + return this.type == 1; + } + + public boolean isExit() { + return this.type == 2; + } + + public boolean isEmpty() { + return this.type == 0; + } + + public void setWall() { + this.type = 1; + } + + public void setExit() { + this.type = 2; + } + + public void setEmpty() { + this.type = 0; + } +}