sofia.micro.jeroo
Class Jeroo

java.lang.Object
  extended by greenfoot.sofiainternal.Actor
      extended by sofia.graphics.Shape
          extended by sofia.graphics.ImageShape
              extended by sofia.micro.Actor
                  extended by sofia.micro.ScriptableActor
                      extended by sofia.micro.jeroo.Jeroo
All Implemented Interfaces:
Script

public class Jeroo
extends ScriptableActor

Represents a Jeroo on Santong Island.

Version:
$Date: 2012/08/06 11:13 $
Author:
Stephen Edwards, Last changed by $Author: edwards $

Field Summary
static RelativeDirection AHEAD
          A constant that represents the direction straight in front of the Jeroo, in the direction it is currently facing.
static CompassDirection EAST
          A constant that means facing east, or to the right.
static RelativeDirection HERE
          A constant that represents the location where the Jeroo is currently standing.
static RelativeDirection LEFT
          A constant that represents the direction to the left of a Jeroo's current location or direction.
static CompassDirection NORTH
          A constant that means facing north, or up.
static RelativeDirection RIGHT
          A constant that represents the direction to the right of a Jeroo's current location or direction.
static CompassDirection SOUTH
          A constant that means facing south, or down.
static CompassDirection WEST
          A constant that means facing west, or to the left.
 
Constructor Summary
Jeroo()
          Create a new Jeroo at the origin (0, 0), facing east, with no flowers.
Jeroo(int flowers)
          Create a new Jeroo at the origin (0, 0), facing east.
Jeroo(int x, int y)
          Create a new Jeroo, facing east, with no flowers.
Jeroo(int x, int y, CompassDirection direction)
          Create a new Jeroo with no flowers.
Jeroo(int x, int y, CompassDirection direction, int flowers)
          Create a new Jeroo.
Jeroo(int x, int y, int flowers)
          Create a new Jeroo facing east.
 
Method Summary
 void give(RelativeDirection direction)
          Give a flower to a Jeroo in a neighboring cell in the indicated direction.
 boolean hasFlower()
          Does this Jeroo have any flowers in its pouch?
 void hop()
          Move forward one space.
 void hop(int number)
          Hop number times in a row, where number is a positive integer.
protected  void incapacitate(java.lang.String message)
          Called under various error conditions to indicate that this Jeroo is out of commission and cannot carry out any more actions.
 boolean isFacing(CompassDirection direction)
          Is the Jeroo facing the indicated direction?
 void pick()
          Pick a flower from the current location.
 void plant()
          Plant a flower at the current location.
 boolean seesClear(RelativeDirection direction)
          Are there no obstacles (no net, no flower, no Jeroo, and no water) in the indicated direction?
 boolean seesFlower(RelativeDirection direction)
          Is there a flower in the indicated direction?
 boolean seesJeroo(RelativeDirection direction)
          Is there a Jeroo in the indicated direction?
 boolean seesNet(RelativeDirection direction)
          Is there a net in the indicated direction?
 boolean seesWater(RelativeDirection direction)
          Is there water in the indicated direction?
 void toss()
          Toss a flower one space ahead.
 void turn(RelativeDirection direction)
          Turn in the indicated direction, but stay in the same location.
 
Methods inherited from class sofia.micro.ScriptableActor
_gf_addToWorld, act, getScript, move, script, scriptStep, setGridLocation, setGridX, setGridY, setRotation, setScript, setScript, stopScript, turn, turnTowards, turnTowards
 
Methods inherited from class sofia.micro.Actor
addedToWorld, addOther, getGridX, getGridY, getImage, getIntersectingObjects, getNeighbors, getNickName, getObjectsAtOffset, getObjectsInRange, getOneIntersectingObject, getOneObjectAtOffset, getShape, getWorld, remove, setBounds, setImage, setImage, setNickName, setPosition, setPosition, setPositionAnchor, setPositionAnchor, setX, setY, toString
 
Methods inherited from class sofia.graphics.ImageShape
getSourceBounds, setBitmap, setSourceBounds, setSourceBounds
 
Methods inherited from class sofia.graphics.Shape
conditionallyRelayout, conditionallyRepaint, contains, contains, extendsOutside, getAlpha, getBounds, getColor, getHeight, getPosition, getPositionAnchor, getRotation, getRotationPivot, getShapeParent, getWidth, getX, getY, getZIndex, intersects, isInFrontOf, isVisible, move, notifyParentOfPositionChange, onBoundsResolved, rotateBy, setAlpha, setColor, setRotation, setRotation, setVisible, setZIndex
 
Methods inherited from class greenfoot.sofiainternal.Actor
_gf_getBoundingXs, _gf_getBoundingYs, _gf_getDelegate, _gf_getImage, _gf_getIntersectingObjects, _gf_getNeighbours, _gf_getObjectsAtOffset, _gf_getObjectsInRange, _gf_getOneIntersectingObject, _gf_getOneObjectAtOffset, _gf_getRotation, _gf_getX, _gf_getY, _gf_setImage, _gf_setImage, _gf_setLocation, _gf_setRotation, _gf_turn, addedToWorld, containsPoint, intersects
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

EAST

public static final CompassDirection EAST
A constant that means facing east, or to the right.


SOUTH

public static final CompassDirection SOUTH
A constant that means facing south, or down.


WEST

public static final CompassDirection WEST
A constant that means facing west, or to the left.


NORTH

public static final CompassDirection NORTH
A constant that means facing north, or up.


LEFT

public static final RelativeDirection LEFT
A constant that represents the direction to the left of a Jeroo's current location or direction.


RIGHT

public static final RelativeDirection RIGHT
A constant that represents the direction to the right of a Jeroo's current location or direction.


AHEAD

public static final RelativeDirection AHEAD
A constant that represents the direction straight in front of the Jeroo, in the direction it is currently facing.


HERE

public static final RelativeDirection HERE
A constant that represents the location where the Jeroo is currently standing.

Constructor Detail

Jeroo

public Jeroo()
Create a new Jeroo at the origin (0, 0), facing east, with no flowers.


Jeroo

public Jeroo(int flowers)
Create a new Jeroo at the origin (0, 0), facing east.

Parameters:
flowers - The number of flowers the Jeroo is holding.

Jeroo

public Jeroo(int x,
             int y)
Create a new Jeroo, facing east, with no flowers.

Parameters:
x - The x-coordinate of the Jeroo's location.
y - The y-coordinate of the Jeroo's location.

Jeroo

public Jeroo(int x,
             int y,
             CompassDirection direction)
Create a new Jeroo with no flowers.

Parameters:
x - The x-coordinate of the Jeroo's location.
y - The y-coordinate of the Jeroo's location.
direction - The direction the Jeroo is facing.

Jeroo

public Jeroo(int x,
             int y,
             int flowers)
Create a new Jeroo facing east.

Parameters:
x - The x-coordinate of the Jeroo's location.
y - The y-coordinate of the Jeroo's location.
flowers - The number of flowers the Jeroo is holding.

Jeroo

public Jeroo(int x,
             int y,
             CompassDirection direction,
             int flowers)
Create a new Jeroo.

Parameters:
x - The x-coordinate of the Jeroo's location.
y - The y-coordinate of the Jeroo's location.
direction - The direction the Jeroo is facing.
flowers - The number of flowers the Jeroo is holding.
Method Detail

hop

public void hop()
Move forward one space. It is an error if the hopping Jeroo lands in the water, lands on another Jeroo, or hops onto a net. A Jeroo can hop onto a flower.


hop

public void hop(int number)
Hop number times in a row, where number is a positive integer.

Parameters:
number - The number of spaces to move (greater than zero).

pick

public void pick()
Pick a flower from the current location. Nothing happens if there is no flower at the current location.


plant

public void plant()
Plant a flower at the current location. Nothing happens if the Jeroo does not have a flower to plant.


toss

public void toss()
Toss a flower one space ahead. The tossed flower is lost forever. If the flower lands on a net, the net is disabled.


give

public void give(RelativeDirection direction)
Give a flower to a Jeroo in a neighboring cell in the indicated direction. Nothing happens if the giving Jeroo has no flowers or if there is no Jeroo in the indicated direction. (give(HERE); is meaningless.)

Parameters:
direction - The direction to give (LEFT, RIGHT, or AHEAD).

turn

public void turn(RelativeDirection direction)
Turn in the indicated direction, but stay in the same location. (turn(AHEAD); and turn(HERE); are meaningless.)

Parameters:
direction - The direction to turn (LEFT or RIGHT).

hasFlower

public boolean hasFlower()
Does this Jeroo have any flowers in its pouch?

Returns:
True if this Jeroo has at least one flower.

isFacing

public boolean isFacing(CompassDirection direction)
Is the Jeroo facing the indicated direction?

Parameters:
direction - The direction to check (NORTH, SOUTH, EAST, or WEST).
Returns:
True if this Jeroo is facing the specified direction.

seesFlower

public boolean seesFlower(RelativeDirection direction)
Is there a flower in the indicated direction?

Parameters:
direction - The direction to check.
Returns:
True if there is a flower in the specified direction.

seesJeroo

public boolean seesJeroo(RelativeDirection direction)
Is there a Jeroo in the indicated direction?

Parameters:
direction - The direction to check.
Returns:
True if there is a flower in the specified direction.

seesNet

public boolean seesNet(RelativeDirection direction)
Is there a net in the indicated direction?

Parameters:
direction - The direction to check.
Returns:
True if there is a net in the specified direction.

seesWater

public boolean seesWater(RelativeDirection direction)
Is there water in the indicated direction?

Parameters:
direction - The direction to check.
Returns:
True if there is water in the specified direction.

seesClear

public boolean seesClear(RelativeDirection direction)
Are there no obstacles (no net, no flower, no Jeroo, and no water) in the indicated direction?

Parameters:
direction - The direction to check.
Returns:
True if there are no obstacles in the specified direction.

incapacitate

protected void incapacitate(java.lang.String message)
Called under various error conditions to indicate that this Jeroo is out of commission and cannot carry out any more actions.

Parameters:
message - A log message to print about the event.


Greenfoot homepage