java.lang.ObjectActor
Bug
public class Bug
A Bug is an actor that can move and turn. It drops flowers as
it moves.
The implementation of this class is testable on the AP CS A and AB exams.
| Constructor Summary | |
|---|---|
Bug()
Constructs a default bug |
|
Bug(java.awt.Color bugColor)
Constructs a bug of a given color. |
|
Bug(int row,
int column)
Constructs a bug at the given location. |
|
| Method Summary | |
|---|---|
void |
act()
Moves if it can move, turns otherwise. |
void |
addToGrid()
|
boolean |
canMove()
Tests whether this bug can move forward into a location that is empty or contains a flower. |
void |
move()
Moves the bug forward, putting a flower into the location it previously occupied. |
void |
turn()
Turns the bug 45 degrees to the right without changing its location. |
| Methods inherited from class Actor |
|---|
getColor, getDirection, getGrid, getLocation, moveTo, putSelfInGrid, removeSelfFromGrid, setColor, setDirection, setLocation, toString |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Bug()
public Bug(java.awt.Color bugColor)
bugColor - the color for this bug
public Bug(int row,
int column)
row - the row for this bugcolumn - the column for this bug| Method Detail |
|---|
public void act()
act in class Actorpublic void addToGrid()
public boolean canMove()
public void move()
public void turn()