info.gridworld.actor
Class Bug

java.lang.Object
  extended by info.gridworld.actor.Actor
      extended by info.gridworld.actor.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 red bug.
Bug(Color bugColor)
          Constructs a bug of a given color.
 
Method Summary
 void act()
          Moves if it can move, turns otherwise.
 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 info.gridworld.actor.Actor
getColor, getDirection, getGrid, getLocation, moveTo, putSelfInGrid, removeSelfFromGrid, setColor, setDirection, 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 red bug.


Bug

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

Parameters:
bugColor - the color for this bug
Method Detail

act

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

Overrides:
act in class Actor

turn

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


move

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


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.