Class Bug

java.lang.Object
  extended by Actor
      extended by Bug

public class Bug
extends Actor

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

Bug

public Bug()
Constructs a default bug


Bug

public Bug(java.awt.Color bugColor)
Constructs a bug of a given color.

Parameters:
bugColor - the color for this bug

Bug

public Bug(int row,
           int column)
Constructs a bug at the given location.

Parameters:
row - the row for this bug
column - the column for this bug
Method Detail

act

public void act()
Moves if it can move, turns otherwise.

Overrides:
act in class Actor

addToGrid

public void addToGrid()

canMove

public boolean canMove()
Tests whether this bug can move forward into a location that is empty or contains a flower.

Returns:
true if this bug can move.

move

public void move()
Moves the bug forward, putting a flower into the location it previously occupied.


turn

public void turn()
Turns the bug 45 degrees to the right without changing its location.