From 655ac88f4e73b2df532a451aedf5a561ea1b0d2c Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Sat, 21 Nov 2015 10:36:18 +0100 Subject: Import project structure --- src/ch/epfl/maze/util/Action.java | 101 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 src/ch/epfl/maze/util/Action.java (limited to 'src/ch/epfl/maze/util/Action.java') 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 @@ +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 + * while 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 true if the action was successful, false otherwise + */ + + public boolean isSuccessful() { + return mSuccess; + } + + /** + * Determines if the animal performing the action dies while moving from a + * square to another. + * + * @return true if the action dies between two squares, false + * otherwise + */ + + public boolean diesBetweenSquares() { + return mDies; + } +} -- cgit v1.2.3