summaryrefslogtreecommitdiff
path: root/src/ch/epfl/maze/util/Action.java
blob: 491627f1d0f686978c707aad619117cccb33723f (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package ch.epfl.maze.util;

/**
 * Immutable action that encapsulates a choice made by an animal and information
 * about it, such as if it was successful or not, and if the animal will die
 * <i>while</i> performing it.
 * 
 */

public final class Action {

	/* variables defining the action */
	private final Direction mDirection;
	private final boolean mSuccess;
	private final boolean mDies;

	/**
	 * Constructs a successful action of an animal towards a specified
	 * direction, that does not die between two squares.
	 * 
	 * @param dir
	 *            Direction towards which the action needs to be performed
	 */

	public Action(Direction dir) {
		if (dir != null) {
			mDirection = dir;
		} else {
			mDirection = Direction.NONE;
		}
		mSuccess = true;
		mDies = false;
	}

	/**
	 * Constructs an action of an animal towards a specified direction, with a
	 * specified success, that does not die between two squares.
	 * 
	 * @param dir
	 *            Direction towards which the action needs to be performed
	 * @param successful
	 *            Determines whether this action was successful
	 */

	public Action(Direction dir, boolean successful) {
		mDirection = dir;
		mSuccess = successful;
		mDies = false;
	}

	/**
	 * Constructs an action of an animal towards a specified direction, with a
	 * specified success, and that also specifies if the animal dies between two
	 * squares.
	 * 
	 * @param dir
	 *            Direction towards which the action needs to be performed
	 * @param successful
	 *            Determines whether this action was successful
	 * @param dies
	 *            Determines whether the action will die between two squares
	 */

	public Action(Direction dir, boolean successful, boolean dies) {
		mDirection = dir;
		mSuccess = successful;
		mDies = dies;
	}

	/**
	 * Retrieves the direction towards which the action shall move.
	 * 
	 * @return Direction of the action
	 */

	public Direction getDirection() {
		return mDirection;
	}

	/**
	 * Determines if the action was successful or not.
	 * 
	 * @return <b>true</b> if the action was successful, <b>false</b> otherwise
	 */

	public boolean isSuccessful() {
		return mSuccess;
	}

	/**
	 * Determines if the animal performing the action dies while moving from a
	 * square to another.
	 * 
	 * @return <b>true</b> if the action dies between two squares, <b>false</b>
	 *         otherwise
	 */

	public boolean diesBetweenSquares() {
		return mDies;
	}
}