Class Creature

java.lang.Object
  extended by greenfoot.Actor
      extended by Creature

public abstract class Creature
extends greenfoot.Actor

A Creature is the base class for all alien beings in this scenario. It provides the basic abilities of creatures in this world.

Version:
1.1
Author:
Michael Kolling, Barry Brown

Constructor Summary
Creature(Ship ship)
          Create a creature at its ship.
 
Method Summary
 void act()
          Act - must be called as part of subclass act.
 boolean atShip()
          True if we are at our space ship.
 boolean atWater()
          Return true if we have just seen water in front of us.
 boolean atWorldEdge()
          Test if we are close to one of the edges of the world.
 boolean carryingTomato()
          Check whether we are carrying a tomato.
protected  void dropTomato()
          Drop the tomato we are carrying.
abstract  java.lang.String getCurrentImage()
          This method must be defined in subclasses.
 void loadTomato()
          Load a tomato onto *another* creature.
 void move()
          Move forward roughly in the current direction.
protected  boolean randomChance(int percent)
          Return 'true' in exactly 'percent' number of calls.
 boolean removeTomato()
          Remove the tomato currently carried (and return true).
 boolean seePaint(java.lang.String color)
          Check whether we can see paint of a given color where we are sitting.
 void spit(java.lang.String color)
          Spit a drop of paint onto the ground.
 void turn(int angle)
          Turn 'angle' degrees towards the right (clockwise).
 void turnHome()
          Turn in the direction facing the home ship.
 
Methods inherited from class greenfoot.Actor
addedToWorld, getHeight, getImage, getIntersectingObjects, getNeighbours, getObjectsAtOffset, getObjectsInRange, getOneIntersectingObject, getOneObjectAtOffset, getRotation, getWidth, getWorld, getX, getY, intersects, setImage, setImage, setLocation, setRotation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Creature

public Creature(Ship ship)
Create a creature at its ship.

Method Detail

act

public void act()
Act - must be called as part of subclass act. This ensures single movement in each act round.

Overrides:
act in class greenfoot.Actor

atShip

public final boolean atShip()
True if we are at our space ship.


atWater

public boolean atWater()
Return true if we have just seen water in front of us.


atWorldEdge

public boolean atWorldEdge()
Test if we are close to one of the edges of the world. Return true if we are.


carryingTomato

public final boolean carryingTomato()
Check whether we are carrying a tomato.


dropTomato

protected final void dropTomato()
Drop the tomato we are carrying. If we are at the ship, it is counted. If not, it's just gone...


getCurrentImage

public abstract java.lang.String getCurrentImage()
This method must be defined in subclasses. It gives subclasses the chance to specify their own images.


loadTomato

public final void loadTomato()
Load a tomato onto *another* creature. This works only if there is another creature and a tomato pile present, otherwise this method does nothing.


move

public void move()
Move forward roughly in the current direction. Sometimes we get a little off course.


randomChance

protected boolean randomChance(int percent)
Return 'true' in exactly 'percent' number of calls. That is: a call randomChance(25) has a 25% chance to return true.


removeTomato

public final boolean removeTomato()
Remove the tomato currently carried (and return true). Return false if we were not carrying one.


seePaint

public boolean seePaint(java.lang.String color)
Check whether we can see paint of a given color where we are sitting.


spit

public void spit(java.lang.String color)
Spit a drop of paint onto the ground. We can spit in three colors: "red", "orange", and "purple". (All other strings will be mapped to one of these.)


turn

public void turn(int angle)
Turn 'angle' degrees towards the right (clockwise).


turnHome

public void turnHome()
Turn in the direction facing the home ship.