diff options
author | Pacien TRAN-GIRARD | 2015-11-24 12:56:50 +0100 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2015-11-24 12:56:50 +0100 |
commit | 5f9be99e7ebd4a90e666e6efbe9e9d4b3b8008e7 (patch) | |
tree | f551b9193ef29660bacf1c0f25707bbd407f9200 /src/ch/epfl/maze/physical/Animal.java | |
parent | fb492341a1d05590c5230e8e0bd5e48f530944fe (diff) | |
download | maze-solver-5f9be99e7ebd4a90e666e6efbe9e9d4b3b8008e7.tar.gz |
Move directional attribute to Animal
Diffstat (limited to 'src/ch/epfl/maze/physical/Animal.java')
-rw-r--r-- | src/ch/epfl/maze/physical/Animal.java | 24 |
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; | |||
13 | abstract public class Animal { | 13 | abstract 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 | } |