Class FoodHunk
java.lang.Object
|
+--GameObject
|
+--RealObject
|
+--FoodHunk
- All Implemented Interfaces:
- java.lang.Cloneable, java.lang.Comparable, Food, Spyable
- class FoodHunk
- extends RealObject
- implements Food
This class implements food objects that when you eat them, they continue to exist, but
get smaller. This is reflected in their descriptions. But eventually, of course, they
go away completely.
|
Constructor Summary |
(package private) |
FoodHunk()
|
|
Method Summary |
void |
eatMe()
Decrement the number of pieces and maybe go away. |
double |
getCalories()
Accessor for calories. |
java.lang.String |
getLongDescription()
Construct a varying long description. |
void |
initialize(java.lang.String initializer,
GameObject parentObjectArg)
This is a somewhat standard initialize method, but it makes use
of a specially-formatted longDescription of the form
calories ; pieces ; vegetarian,
where calories indicates the number of calories per piece,
pieces is the number of times this can be eaten before disappearing, and
vegetarian is either "true" or "false"--we look only at the first character
to see if it's 't'. |
boolean |
isVegetarian()
Is this thing veggie? |
| Methods inherited from class RealObject |
checkLeave, clone, doAction, getParent, getShortDescription, getSpreadability, goodbye, hello, isPredicate, preClone, register, roomOf, runSpy, setParent, spread, tellAll, unregister, wanderVia |
| Methods inherited from class java.lang.Object |
, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
FoodHunk
FoodHunk()
eatMe
public void eatMe()
- Decrement the number of pieces and maybe go away.
- Specified by:
eatMe in interface Food
getCalories
public double getCalories()
- Accessor for calories.
- Specified by:
getCalories in interface Food
- Returns:
- the number of calories in one piece of this.
getLongDescription
public java.lang.String getLongDescription()
- Construct a varying long description.
- Overrides:
getLongDescription in class RealObject
- Returns:
- the short description preceded by a phrase describing the number of pieces left.
Should probably depend on how many pieces we started with.
initialize
public void initialize(java.lang.String initializer,
GameObject parentObjectArg)
throws GameException
- This is a somewhat standard
initialize method, but it makes use
of a specially-formatted longDescription of the form
calories ; pieces ; vegetarian,
where calories indicates the number of calories per piece,
pieces is the number of times this can be eaten before disappearing, and
vegetarian is either "true" or "false"--we look only at the first character
to see if it's 't'.
- Overrides:
initialize in class RealObject
- Following copied from class:
RealObject
- Parameters:
initializer - A string delimited by tildes, indicating the name,
short description, and long description of the object.
Subclasses may have additional fields. Should probably throw a Game
Exception if pieces are missing.- Throws:
ClassCastException - if the parentObjectArg is not a RealObject.
isVegetarian
public boolean isVegetarian()
- Is this thing veggie?
- Specified by:
isVegetarian in interface Food
- Returns:
- true if the thing claims not to contain meat (not certified by an orthodox
rabbi) or else false