summaryrefslogtreecommitdiff
path: root/src/ch/epfl/maze/physical/Animal.java
blob: 9123d825e7b3f140a75e409cc3c3b01c3eaa31f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package ch.epfl.maze.physical;

import ch.epfl.maze.util.Direction;
import ch.epfl.maze.util.Vector2D;

/**
 * Animal inside a {@code World} that can move depending on the available
 * choices it has at its position.
 *
 * @author Pacien TRAN-GIRARD
 */

abstract public class Animal {

    private Vector2D position;

    /**
     * Constructs an animal with a specified position.
     *
     * @param position Position of the animal in the labyrinth
     */

    public Animal(Vector2D position) {
        this.position = position;
    }

    /**
     * Retrieves the next direction of the animal, by selecting one choice among
     * the ones available from its position.
     *
     * @param choices The choices left to the animal at its current position (see
     *                {@link ch.epfl.maze.physical.World#getChoices(Vector2D)
     *                World.getChoices(Vector2D)})
     * @return The next direction of the animal, chosen in {@code choices}
     */

    abstract public Direction move(Direction[] choices);

    /**
     * Updates the animal position with a direction.
     * <p>
     * <b>Note</b> : Do not call this function in {@code move(Direction[]
     * choices)} !
     *
     * @param dir Direction that the animal has taken
     */

    public final void update(Direction dir) {
        this.position = this.position.addDirectionTo(dir);
    }

    /**
     * Sets new position for Animal.
     * <p>
     * <b>Note</b> : Do not call this function in {@code move(Direction[]
     * choices)} !
     *
     * @param position
     */

    public final void setPosition(Vector2D position) {
        this.position = position;
    }

    /**
     * Returns position vector of animal.
     *
     * @return Current position of animal.
     */

    public final Vector2D getPosition() {
        return this.position;
    }

    abstract public Animal copy();
}