Ajout de la Grille
This commit is contained in:
parent
0a0e0342d7
commit
c8f37a583a
43
src/Grid.java
Normal file
43
src/Grid.java
Normal file
@ -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();
|
||||
}
|
||||
}
|
29
src/GridController.java
Normal file
29
src/GridController.java
Normal file
@ -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());
|
||||
}
|
||||
}
|
5
src/GridView.java
Normal file
5
src/GridView.java
Normal file
@ -0,0 +1,5 @@
|
||||
public class GridView {
|
||||
public void printGridInfo(int rows, int columns) {
|
||||
System.out.println("Grid size: " + rows + "x" + columns);
|
||||
}
|
||||
}
|
42
src/Square.java
Normal file
42
src/Square.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user