Class Animal

java.lang.Object
  |
  +--GameObject
        |
        +--RealObject
              |
              +--Wanderer
                    |
                    +--Animal
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable, Spyable
Direct Known Subclasses:
Cat, Mouse

class Animal
extends Wanderer

Animals wander and also eat.


Inner classes inherited from class RealObject
RealObject.ContentsMessager, RealObject.DescriptionLineProcessor
 
Inner classes inherited from class GameObject
GameObject.LeaveInfo
 
Field Summary
(package private)  boolean eaten
          This is a temporary variable used only in doAction and its anonymous inner class, but it would be a lot of effort and inconvenience to encapsulate it, so I didn't.
protected  double hunger
          How hungry are we? 0.0 means not at all; 100.0 means we'll try every turn.
protected  boolean vegetarian
          Vegetarians eat only vegetarian food; non-vegetarians eat only meat.
 
Fields inherited from class Wanderer
mobility
 
Fields inherited from class RealObject
contents, longDescription, parentObject, shortDescription, spreadto
 
Fields inherited from class GameObject
masterGame, name
 
Constructor Summary
(package private) Animal()
           
 
Method Summary
 void doAction()
          If we're hungry enough, search the room for a food item and eat it if it matches our diet.
 
Methods inherited from class Wanderer
initialize
 
Methods inherited from class RealObject
checkLeave, clone, getLongDescription, getParent, getShortDescription, getSpreadability, goodbye, hello, isPredicate, preClone, register, roomOf, runSpy, setParent, spread, tellAll, unregister, wanderVia
 
Methods inherited from class GameObject
announce, compareTo, getMasterGame, kill, listen, newInstance, setMasterGame, toString
 
Methods inherited from class java.lang.Object
, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

eaten

boolean eaten
This is a temporary variable used only in doAction and its anonymous inner class, but it would be a lot of effort and inconvenience to encapsulate it, so I didn't.

hunger

protected double hunger
How hungry are we? 0.0 means not at all; 100.0 means we'll try every turn.

vegetarian

protected boolean vegetarian
Vegetarians eat only vegetarian food; non-vegetarians eat only meat.
Constructor Detail

Animal

Animal()
Method Detail

doAction

public void doAction()
If we're hungry enough, search the room for a food item and eat it if it matches our diet. Currently, that just checks the vegetarian flag, but it should probably call some new method which can get overridden. That would make it easier to implement Dog as an Animal without mucking up Cat.
Overrides:
doAction in class Wanderer
See Also:
Food