Package model
Class Ghost
java.lang.Object
model.Actor
model.Ghost
A ghost in the game. This abstract class models the common behaviors and attributes of all ghosts
including their appearance and different behavioral states:
- WAIT: The ghost is not currently present in the maze, its `delay` specifies how long before it enters.
- CHASE: The ghost is actively seeking PacMann. Catching up to PacMann will stop the round.
- FLEE: The ghost is running away to its designated location on the board. If PacMann catches up to this ghost, it will leave the board and enter its WAIT state.
Subclasses are responsible for specifying the `target()` vertices of that ghost in its CHASE and FLEE states.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe three possible behavior states of ghostsNested classes/interfaces inherited from class model.Actor
Actor.DPair, Actor.Location -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected doubleWhen in the FLEE state, the number of milliseconds remaining before this ghost returns to its CHASE stateprivate final ColorThe color of this ghost in its CHASE stateprivate List<MazeGraph.MazeEdge> The edges comprising the most recently calculated path to this ghosts' `target()`private final intThe total number of milliseconds before this ghost enters the maze in its CHASE stateprotected Ghost.GhostStateThe current behavioral state of this ghostprivate doubleWhen in the FLEE state, the number of milliseconds remaining before this ghost returns to its CHASE state -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoubleReturn the current base speed of this actor, before factoring in the weight of the edge they are traversing.color()Return this ghost's color (for painting)doubleReturn the amount of time remaining on this ghost's FLEE timerIn their WAIT state, the ghosts move from side to side in their box, otherwise, their bounding box location is delegated up to `Actor.getBoundingBoxUL`.Return the list of Edges in this actor's current planned path through the maze (if any).doubleReturn the amount of game time (in ms) that this actor is able to travel at its current speed before reaching a vertex or changing state.nextEdge()Returns the first edge along the shortest path from this ghost's `currentVertex()` to its `target()`.voidpropagate(double dt) Calculate the new position for this actor after `ms` milliseconds of game time have elapsed.voidreset()Transition this ghost to its WAIT state and reset the `waitTimeRemaining` to this ghost's `INITIAL_DELAY`voidrespawn()Transition this ghost to its WAIT state when it is caught in its FLEE state, and resets `waitTimeRemaining`.voidTransition this ghost to its FLEE state and reset the `fleeTimeRemaining`.state()Return the current state of this ghostprotected abstract MazeGraph.MazeVertextarget()Return the vertex that this ghost is targetingvoidGhosts do not take any actions when visiting verticesdoubleReturn the amount of time remaining on this ghost's WAIT timerMethods inherited from class model.Actor
currentEdge, edgeSpeed, location, nearestVertex, traverseEdge
-
Field Details
-
state
The current behavioral state of this ghost -
initialDelay
private final int initialDelayThe total number of milliseconds before this ghost enters the maze in its CHASE state -
waitTimeRemaining
private double waitTimeRemainingWhen in the FLEE state, the number of milliseconds remaining before this ghost returns to its CHASE state -
fleeTimeRemaining
protected double fleeTimeRemainingWhen in the FLEE state, the number of milliseconds remaining before this ghost returns to its CHASE state -
ghostColor
The color of this ghost in its CHASE state -
guidancePath
The edges comprising the most recently calculated path to this ghosts' `target()`
-
-
Constructor Details
-
Ghost
Construct a ghost associated to the given `model` with specified color and initial delay
-
-
Method Details
-
target
Return the vertex that this ghost is targeting -
state
Return the current state of this ghost -
color
Return this ghost's color (for painting) -
fleeTimeRemaining
public double fleeTimeRemaining()Return the amount of time remaining on this ghost's FLEE timer -
waitTimeRemaining
public double waitTimeRemaining()Return the amount of time remaining on this ghost's WAIT timer -
getBoundingBoxUL
In their WAIT state, the ghosts move from side to side in their box, otherwise, their bounding box location is delegated up to `Actor.getBoundingBoxUL`.- Overrides:
getBoundingBoxULin classActor
-
visitVertex
Ghosts do not take any actions when visiting vertices- Specified by:
visitVertexin classActor
-
nextEdge
Returns the first edge along the shortest path from this ghost's `currentVertex()` to its `target()`. -
guidancePath
Description copied from class:ActorReturn the list of Edges in this actor's current planned path through the maze (if any). This is intended to be used for visualizing actors' intended behavior. Sequence of edges must form a continuous path (e.g., `ans.get(i).dst().equals(ans.get(i+1).src())`).- Specified by:
guidancePathin classActor
-
reset
public void reset()Transition this ghost to its WAIT state and reset the `waitTimeRemaining` to this ghost's `INITIAL_DELAY` -
baseSpeed
public double baseSpeed()Description copied from class:ActorReturn the current base speed of this actor, before factoring in the weight of the edge they are traversing. -
startFlee
public void startFlee()Transition this ghost to its FLEE state and reset the `fleeTimeRemaining`. Has no effect if the ghost is in its WAIT state. -
respawn
public void respawn()Transition this ghost to its WAIT state when it is caught in its FLEE state, and resets `waitTimeRemaining`. Requires that this ghost is currently in the FLEE state. -
propagate
public void propagate(double dt) Calculate the new position for this actor after `ms` milliseconds of game time have elapsed. In the WAIT state, this updates its delay and spawns the ghost into the maze in its CHASE state when the delay reaches 0. In the FLEE state, the `fleeTimeRemaining` is updated and the ghost reverts to its CHASE state when this reaches 0. Otherwise, delegates to `Actor.updateLocation()`. -
maxPropagationTime
public double maxPropagationTime()Description copied from class:ActorReturn the amount of game time (in ms) that this actor is able to travel at its current speed before reaching a vertex or changing state. Return POSITIVE_INFINITY if this actor is standing still and has no anticipated state changes.- Overrides:
maxPropagationTimein classActor
-