From 6f117982d0f618c4f1f9e37d2c57cfeac11811ea Mon Sep 17 00:00:00 2001 From: Ninja-Jambon Date: Wed, 21 Feb 2024 11:28:42 +0100 Subject: [PATCH] added a method to the Universe class --- AppLaser.java | 9 ++++++++- Universe.java | 21 +++++++++++++++------ algo.txt | 12 +++++++++++- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/AppLaser.java b/AppLaser.java index 5b84b87..b98606d 100644 --- a/AppLaser.java +++ b/AppLaser.java @@ -3,7 +3,14 @@ public class AppLaser { 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(); } diff --git a/Universe.java b/Universe.java index e4b3656..5249255 100644 --- a/Universe.java +++ b/Universe.java @@ -8,30 +8,39 @@ public class Universe { // 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.height = height; this.length = length; int i, j; for (i = 1; i < this.height - 1; i++) { for (j = 1; j < this.length - 1; j++) { - grid[i][j] = 0; + this.grid[i][j] = 0; } } for (i = 0; i < this.height; i++) { - grid[i][0] = -1; - grid[i][length - 1] = -1; + this.grid[i][0] = -1; + this.grid[i][length - 1] = -1; } for (j = 0; j < this.length; j++) { - grid[0][j] = -1; - grid[height - 1][j] = -1; + this.grid[0][j] = -1; + this.grid[height - 1][j] = -1; } + + this.grid[i_start][j_start] = dir_start; } // 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() { int i, j; for (i = 0; i < this.height; i++) { diff --git a/algo.txt b/algo.txt index fe0efe9..424ee8b 100644 --- a/algo.txt +++ b/algo.txt @@ -23,4 +23,14 @@ Le truc avec la pile: - Situation: - position i sur le plateau - position j sur le plateau - - n le nombre de choix testés pour cette situation (de 0 à 3) \ No newline at end of file + - 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 \ No newline at end of file