summaryrefslogtreecommitdiff
path: root/src/ch/epfl/maze/util/Action.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/ch/epfl/maze/util/Action.java')
-rw-r--r--src/ch/epfl/maze/util/Action.java101
1 files changed, 101 insertions, 0 deletions
diff --git a/src/ch/epfl/maze/util/Action.java b/src/ch/epfl/maze/util/Action.java
new file mode 100644
index 0000000..491627f
--- /dev/null
+++ b/src/ch/epfl/maze/util/Action.java
@@ -0,0 +1,101 @@
1package ch.epfl.maze.util;
2
3/**
4 * Immutable action that encapsulates a choice made by an animal and information
5 * about it, such as if it was successful or not, and if the animal will die
6 * <i>while</i> performing it.
7 *
8 */
9
10public final class Action {
11
12 /* variables defining the action */
13 private final Direction mDirection;
14 private final boolean mSuccess;
15 private final boolean mDies;
16
17 /**
18 * Constructs a successful action of an animal towards a specified
19 * direction, that does not die between two squares.
20 *
21 * @param dir
22 * Direction towards which the action needs to be performed
23 */
24
25 public Action(Direction dir) {
26 if (dir != null) {
27 mDirection = dir;
28 } else {
29 mDirection = Direction.NONE;
30 }
31 mSuccess = true;
32 mDies = false;
33 }
34
35 /**
36 * Constructs an action of an animal towards a specified direction, with a
37 * specified success, that does not die between two squares.
38 *
39 * @param dir
40 * Direction towards which the action needs to be performed
41 * @param successful
42 * Determines whether this action was successful
43 */
44
45 public Action(Direction dir, boolean successful) {
46 mDirection = dir;
47 mSuccess = successful;
48 mDies = false;
49 }
50
51 /**
52 * Constructs an action of an animal towards a specified direction, with a
53 * specified success, and that also specifies if the animal dies between two
54 * squares.
55 *
56 * @param dir
57 * Direction towards which the action needs to be performed
58 * @param successful
59 * Determines whether this action was successful
60 * @param dies
61 * Determines whether the action will die between two squares
62 */
63
64 public Action(Direction dir, boolean successful, boolean dies) {
65 mDirection = dir;
66 mSuccess = successful;
67 mDies = dies;
68 }
69
70 /**
71 * Retrieves the direction towards which the action shall move.
72 *
73 * @return Direction of the action
74 */
75
76 public Direction getDirection() {
77 return mDirection;
78 }
79
80 /**
81 * Determines if the action was successful or not.
82 *
83 * @return <b>true</b> if the action was successful, <b>false</b> otherwise
84 */
85
86 public boolean isSuccessful() {
87 return mSuccess;
88 }
89
90 /**
91 * Determines if the animal performing the action dies while moving from a
92 * square to another.
93 *
94 * @return <b>true</b> if the action dies between two squares, <b>false</b>
95 * otherwise
96 */
97
98 public boolean diesBetweenSquares() {
99 return mDies;
100 }
101}