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. Override a bug to draw shapes in the actor world.

copyright© 2005 Cay S. Horstmann (http://horstmann.com)

Author:
Cay Horstmann

Constructor Summary
Bug()
          Constructs a red bug.
Bug(Color color)
          Constructs a bug of a given color.
 
Method Summary
 void act()
          Override this method to define the action of this actor.
 boolean canMove()
          Tests whether this bug can move forward.
 void move()
          Moves this bug forward.
 void turn()
          Makes this bug turn by 45 degrees to the right.
 
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 color)
Constructs a bug of a given color.

Parameters:
color - the color for this bug
Method Detail

act

public void act()
Description copied from class: Actor
Override this method to define the action of this actor.

Specified by:
act in class Actor

turn

public void turn()
Makes this bug turn by 45 degrees to the right.


move

public void move()
Moves this bug forward. The bug may replace other actors or fall outside the grid. Call canMove to check whether it is safe to move.


canMove

public boolean canMove()
Tests whether this bug can move forward. The bug must be in a grid, the next forward location must be valid, and it must either be empty or occupied by a flower.

Returns:
true if this bug can move.