From 5f9be99e7ebd4a90e666e6efbe9e9d4b3b8008e7 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Tue, 24 Nov 2015 12:56:50 +0100 Subject: Move directional attribute to Animal --- src/ch/epfl/maze/physical/Animal.java | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/ch/epfl/maze/physical/Animal.java') 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; abstract public class Animal { private Vector2D position; + private Direction direction; + + /** + * Constructs an animal with a specified position and direction. + * + * @param position Position of the animal in the labyrinth + * @param direction Direction the animal is facing + */ + public Animal(Vector2D position, Direction direction) { + this.position = position; + this.direction = direction; + } /** * Constructs an animal with a specified position. @@ -20,7 +32,7 @@ abstract public class Animal { * @param position Position of the animal in the labyrinth */ public Animal(Vector2D position) { - this.position = position; + this(position, Direction.NONE); } /** @@ -44,6 +56,7 @@ abstract public class Animal { */ public final void update(Direction dir) { this.position = this.position.addDirectionTo(dir); + this.direction = dir; } /** @@ -67,6 +80,15 @@ abstract public class Animal { return this.position; } + /** + * Returns the direction of the Animal. + * + * @return The current direction of the Animal + */ + public final Direction getDirection() { + return this.direction; + } + abstract public Animal copy(); } -- cgit v1.2.3