added a method to the Universe class

This commit is contained in:
Ninja-Jambon 2024-02-21 11:28:42 +01:00
parent a01ed1abaa
commit 6f117982d0
3 changed files with 34 additions and 8 deletions

View file

@ -3,7 +3,14 @@
public class AppLaser { public class AppLaser {
public static void main(String [] args) { public static void main(String [] args) {
Universe universe = new Universe(20, 10); Universe universe = new Universe(20, 10, 2, 3, 12);
universe.addObstacle(4, 4);
universe.addObstacle(5, 4);
universe.addObstacle(6, 4);
universe.addObstacle(7, 4);
universe.addObstacle(8, 4);
universe.addObstacle(9, 4);
universe.print(); universe.print();
} }

View file

@ -8,30 +8,39 @@ public class Universe {
// Constructors // Constructors
public Universe(int length, int height) { public Universe(int length, int height, int i_start, int j_start, int dir_start) {
this.grid = new int[height][length]; this.grid = new int[height][length];
this.height = height; this.height = height;
this.length = length; this.length = length;
int i, j; int i, j;
for (i = 1; i < this.height - 1; i++) { for (i = 1; i < this.height - 1; i++) {
for (j = 1; j < this.length - 1; j++) { for (j = 1; j < this.length - 1; j++) {
grid[i][j] = 0; this.grid[i][j] = 0;
} }
} }
for (i = 0; i < this.height; i++) { for (i = 0; i < this.height; i++) {
grid[i][0] = -1; this.grid[i][0] = -1;
grid[i][length - 1] = -1; this.grid[i][length - 1] = -1;
} }
for (j = 0; j < this.length; j++) { for (j = 0; j < this.length; j++) {
grid[0][j] = -1; this.grid[0][j] = -1;
grid[height - 1][j] = -1; this.grid[height - 1][j] = -1;
} }
this.grid[i_start][j_start] = dir_start;
} }
// Methods // Methods
public void addObstacle(int pos_i, int pos_j) {
if (this.grid[pos_i][pos_j] == 0) {
this.grid[pos_i][pos_j] = -1;
}
else {}
}
public void print() { public void print() {
int i, j; int i, j;
for (i = 0; i < this.height; i++) { for (i = 0; i < this.height; i++) {

View file

@ -24,3 +24,13 @@ Le truc avec la pile:
- position i sur le plateau - position i sur le plateau
- position j sur le plateau - position j sur le plateau
- n le nombre de choix testés pour cette situation (de 0 à 3) - n le nombre de choix testés pour cette situation (de 0 à 3)
types de cases:
- 0 case vide
- -1 obstacle
- 2 miroir gauche
- 3 miroir droite
- 10 départ nord
- 11 départ sud
- 12 départ est
- 13 départ ouest