summaryrefslogtreecommitdiff
path: root/src/ch/epfl/maze/physical/Animal.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/ch/epfl/maze/physical/Animal.java')
-rw-r--r--src/ch/epfl/maze/physical/Animal.java24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/ch/epfl/maze/physical/Animal.java b/src/ch/epfl/maze/physical/Animal.java
index 3697c32..34a1136 100644
--- a/src/ch/epfl/maze/physical/Animal.java
+++ b/src/ch/epfl/maze/physical/Animal.java
@@ -13,6 +13,18 @@ import ch.epfl.maze.util.Vector2D;
13abstract public class Animal { 13abstract public class Animal {
14 14
15 private Vector2D position; 15 private Vector2D position;
16 private Direction direction;
17
18 /**
19 * Constructs an animal with a specified position and direction.
20 *
21 * @param position Position of the animal in the labyrinth
22 * @param direction Direction the animal is facing
23 */
24 public Animal(Vector2D position, Direction direction) {
25 this.position = position;
26 this.direction = direction;
27 }
16 28
17 /** 29 /**
18 * Constructs an animal with a specified position. 30 * Constructs an animal with a specified position.
@@ -20,7 +32,7 @@ abstract public class Animal {
20 * @param position Position of the animal in the labyrinth 32 * @param position Position of the animal in the labyrinth
21 */ 33 */
22 public Animal(Vector2D position) { 34 public Animal(Vector2D position) {
23 this.position = position; 35 this(position, Direction.NONE);
24 } 36 }
25 37
26 /** 38 /**
@@ -44,6 +56,7 @@ abstract public class Animal {
44 */ 56 */
45 public final void update(Direction dir) { 57 public final void update(Direction dir) {
46 this.position = this.position.addDirectionTo(dir); 58 this.position = this.position.addDirectionTo(dir);
59 this.direction = dir;
47 } 60 }
48 61
49 /** 62 /**
@@ -67,6 +80,15 @@ abstract public class Animal {
67 return this.position; 80 return this.position;
68 } 81 }
69 82
83 /**
84 * Returns the direction of the Animal.
85 *
86 * @return The current direction of the Animal
87 */
88 public final Direction getDirection() {
89 return this.direction;
90 }
91
70 abstract public Animal copy(); 92 abstract public Animal copy();
71 93
72} 94}