summaryrefslogtreecommitdiff
path: root/src/ch/epfl/maze/physical/Maze.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/ch/epfl/maze/physical/Maze.java')
-rw-r--r--src/ch/epfl/maze/physical/Maze.java30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/ch/epfl/maze/physical/Maze.java b/src/ch/epfl/maze/physical/Maze.java
index 71f2f80..e58a56a 100644
--- a/src/ch/epfl/maze/physical/Maze.java
+++ b/src/ch/epfl/maze/physical/Maze.java
@@ -7,10 +7,15 @@ import java.util.List;
7 * Maze in which an animal starts from a starting point and must find the exit. 7 * Maze in which an animal starts from a starting point and must find the exit.
8 * Every animal added will have its position set to the starting point. The 8 * Every animal added will have its position set to the starting point. The
9 * animal is removed from the maze when it finds the exit. 9 * animal is removed from the maze when it finds the exit.
10 *
11 * @author Pacien TRAN-GIRARD
10 */ 12 */
11 13
12public final class Maze extends World { 14public final class Maze extends World {
13 15
16 private final List<Animal> animals;
17 private final List<Animal> animalHistory;
18
14 /** 19 /**
15 * Constructs a Maze with a labyrinth structure. 20 * Constructs a Maze with a labyrinth structure.
16 * 21 *
@@ -19,19 +24,19 @@ public final class Maze extends World {
19 24
20 public Maze(int[][] labyrinth) { 25 public Maze(int[][] labyrinth) {
21 super(labyrinth); 26 super(labyrinth);
22 // TODO 27
28 this.animals = new ArrayList<>();
29 this.animalHistory = new ArrayList<>();
23 } 30 }
24 31
25 @Override 32 @Override
26 public boolean isSolved() { 33 public boolean isSolved() {
27 // TODO 34 return this.animals.isEmpty();
28 return false;
29 } 35 }
30 36
31 @Override 37 @Override
32 public List<Animal> getAnimals() { 38 public List<Animal> getAnimals() {
33 // TODO 39 return this.animals;
34 return new ArrayList<Animal>();
35 } 40 }
36 41
37 /** 42 /**
@@ -43,18 +48,18 @@ public final class Maze extends World {
43 */ 48 */
44 49
45 public boolean hasAnimal(Animal a) { 50 public boolean hasAnimal(Animal a) {
46 // TODO 51 return this.animals.contains(a);
47 return false;
48 } 52 }
49 53
50 /** 54 /**
51 * Adds an animal to the maze. 55 * Adds an animal to the maze at the start position.
52 * 56 *
53 * @param a The animal to add 57 * @param a The animal to add
54 */ 58 */
55 59
56 public void addAnimal(Animal a) { 60 public void addAnimal(Animal a) {
57 // TODO 61 a.setPosition(this.getStart());
62 this.animals.add(a);
58 } 63 }
59 64
60 /** 65 /**
@@ -64,11 +69,14 @@ public final class Maze extends World {
64 */ 69 */
65 70
66 public void removeAnimal(Animal a) { 71 public void removeAnimal(Animal a) {
67 // TODO 72 boolean contained = this.animals.remove(a);
73 if (contained) this.animalHistory.add(a);
68 } 74 }
69 75
70 @Override 76 @Override
71 public void reset() { 77 public void reset() {
72 // TODO 78 for (Animal a : this.animals) this.removeAnimal(a);
79 for (Animal a : this.animalHistory) this.addAnimal(a.copy());
80 this.animalHistory.clear();
73 } 81 }
74} 82}