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