java.lang.ObjectActor
public class Actor
An Actor
is an entity with a color and direction that can act.
The API of this class is testable on the AP CS A and AB exams.
Constructor Summary | |
---|---|
Actor()
Constructs a blue actor that is facing north. |
Method Summary | |
---|---|
void |
act()
Reverses the direction of this actor. |
java.awt.Color |
getColor()
Gets the color of this actor. |
int |
getDirection()
Gets the current direction of this actor. |
info.gridworld.grid.Grid<Actor> |
getGrid()
Gets the grid in which this actor is located. |
info.gridworld.grid.Location |
getLocation()
Gets the location of this actor. |
void |
moveTo(info.gridworld.grid.Location newLocation)
Moves this actor to a new location. |
void |
putSelfInGrid(info.gridworld.grid.Grid<Actor> gr,
info.gridworld.grid.Location loc)
Puts this actor into a grid. |
void |
removeSelfFromGrid()
Removes this actor from its grid. |
void |
setColor(java.awt.Color newColor)
Sets the color of this actor. |
void |
setDirection(int newDirection)
Sets the current direction of this actor. |
java.lang.String |
toString()
Creates a string that describes this actor. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Actor()
Method Detail |
---|
public void act()
Actor
to define types of actors with different behavior
public java.awt.Color getColor()
public int getDirection()
public info.gridworld.grid.Grid<Actor> getGrid()
null
if this actor is
not contained in a gridpublic info.gridworld.grid.Location getLocation()
null
if this actor is
not contained in a gridpublic void moveTo(info.gridworld.grid.Location newLocation)
newLocation
is valid in the grid of this actor
newLocation
- the new locationpublic void putSelfInGrid(info.gridworld.grid.Grid<Actor> gr, info.gridworld.grid.Location loc)
loc
is valid in gr
gr
- the grid into which this actor should be placedloc
- the location into which the actor should be placedpublic void removeSelfFromGrid()
public void setColor(java.awt.Color newColor)
newColor
- the new colorpublic void setDirection(int newDirection)
newDirection
- the new direction. The direction of this actor is set
to the angle between 0 and 359 degrees that is equivalent to
newDirection
.public java.lang.String toString()
toString
in class java.lang.Object