Class Animal

java.lang.Object
greenfoot.Actor
Animal

public class Animal extends greenfoot.Actor
Animal. This is the base class for all animals. In addition to the standard Actor methods, it provides methods to check for being at the edge of the world, as well as seeing and eating other classes.
Version:
2.0
Author:
Michael Kolling
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Test if we are close to one of the edges of the world.
    boolean
    canSee(Class clss)
    Return true if we can see an object of class 'clss' right where we are.
    void
    eat(Class clss)
    Try to eat an object of class 'clss'.
    void
    Move forward in the current direction.

    Methods inherited from class greenfoot.Actor

    act, addedToWorld, getImage, getIntersectingObjects, getNeighbours, getObjectsAtOffset, getObjectsInRange, getOneIntersectingObject, getOneObjectAtOffset, getRotation, getWorld, getWorldOfType, getX, getY, intersects, isAtEdge, isTouching, move, removeTouching, setImage, setImage, setLocation, setRotation, sleepFor, turn, turnTowards

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Animal

      public Animal()
  • Method Details

    • move

      public void move()
      Move forward in the current direction.
    • atWorldEdge

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

      public boolean canSee(Class clss)
      Return true if we can see an object of class 'clss' right where we are. False if there is no such object here.
    • eat

      public void eat(Class clss)
      Try to eat an object of class 'clss'. This is only successful if there is such an object where we currently are. Otherwise this method does nothing.