Class RealObject

java.lang.Object
  |
  +--GameObject
        |
        +--RealObject
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable, Spyable
Direct Known Subclasses:
Ensnarler, FoodHunk, Horolog, Room, Trap, Wanderer

class RealObject
extends GameObject
implements java.lang.Cloneable, Spyable

A Real Object is currently anything other than a passage.


Inner Class Summary
(package private)  class RealObject.ContentsMessager
          A class that's used for sending identical messages to lots of objects, usually all those in a Room.
(package private)  class RealObject.DescriptionLineProcessor
          This class is used in a callback context to process lines in a long description file.
 
Inner classes inherited from class GameObject
GameObject.LeaveInfo
 
Field Summary
(package private)  MyVector contents
          List of other objects contained within this one.
protected  java.lang.String longDescription
          A long description of the object, more or less.
protected  RealObject parentObject
          The object we're contained within.
protected  java.lang.String shortDescription
          A short description of the object, suitable for use in a list.
(package private)  MyVector spreadto
          This is a list of rooms to which this object and its clones have spread in order to avoid duplication.
 
Fields inherited from class GameObject
masterGame, name
 
Constructor Summary
(package private) RealObject()
           
 
Method Summary
 boolean checkLeave(GameObject.LeaveInfo leaveinfo)
          Checks if we're okay about somebody leaving the room we're in.
protected  java.lang.Object clone()
          Clone myself and register as necessary.
 void doAction()
          Figure out what we want to do when we get our 15 microseconds of fame.
 java.lang.String getLongDescription()
          What's our long description? Often overridden by subclasses.
(package private)  RealObject getParent()
          Find out what we're in.
 java.lang.String getShortDescription()
          Unregister this object from everything.
 double getSpreadability()
          Find out how likely this object is to spread to another Room.
 void goodbye(GameObject.LeaveInfo leaveinfo)
          Called when somebody leaves the room we're in.
 void hello(RealObject enterer)
          Called when somebody enters the room we're in.
 void initialize(java.lang.String initializer, GameObject parentObjectArg)
          Initialize this object.
protected  boolean isPredicate(java.lang.String predicate)
          Check if a condition applies to this object.
protected  void preClone()
          This is called before cloning an object, in case the object wants to divide up its resources.
(package private)  void register(GameObject child)
          Called when we become a parent.
(package private)  Room roomOf()
          Tell what room we're in
 java.lang.String runSpy()
          Give information to somebody who's spying on us.
(package private)  void setParent(RealObject newParent)
          Set a new parent object.
(package private)  void spread()
          Try to spread to another room through a passage.
(package private)  void tellAll(RealObject.ContentsMessager Messager, boolean iterate)
          This method is used to get this object and all the objects contained in this one to run some code.
(package private)  void unregister(GameObject child)
          Called when we are no longer parent to an object.
protected  boolean wanderVia(Room.RoomPassage wanderPassage, java.lang.String msg)
          Move from here to somewhere else, if we can, and make sure that the whole world knows about it.
 
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

contents

final MyVector contents
List of other objects contained within this one.

longDescription

protected java.lang.String longDescription
A long description of the object, more or less. There are plenty of variations used by subclasses.

parentObject

protected RealObject parentObject
The object we're contained within. Could be null.

shortDescription

protected java.lang.String shortDescription
A short description of the object, suitable for use in a list.

spreadto

final MyVector spreadto
This is a list of rooms to which this object and its clones have spread in order to avoid duplication. This was a poor implementation choice (can you come up with two reasons?) and should be changed. Instead, give each truly new object a unique ID (maybe a string, maybe a more interesting object) and you can then check if there are any of them in the destination room.
Constructor Detail

RealObject

RealObject()
Method Detail

checkLeave

public boolean checkLeave(GameObject.LeaveInfo leaveinfo)
Checks if we're okay about somebody leaving the room we're in. Another default implementation, overridden by Entangler.
Parameters:
leaveinfo - Information about who's trying to leave and where they want to go
Returns:
true or false according to whether it's okay.

clone

protected java.lang.Object clone()
Clone myself and register as necessary.
Overrides:
clone in class java.lang.Object
Returns:
a copy of myself, but with a new name.

doAction

public void doAction()
Figure out what we want to do when we get our 15 microseconds of fame.
Overrides:
doAction in class GameObject

getLongDescription

public java.lang.String getLongDescription()
What's our long description? Often overridden by subclasses.
Returns:
a String with a long description of the object, generally a full sentence.

getParent

RealObject getParent()
Find out what we're in. This is here mostly because the Predicate hierarchy isn't allowed to be inner classes.
Returns:
The object we're in. Could be null for objects in limbo.

getShortDescription

public java.lang.String getShortDescription()
Unregister this object from everything. Should lead to it being garbage collected in short order. public void kill () { if (parentObject != null) parentObject.unregister (this); super.kill (); } /** What's our short description? Generally not overridden in subclasses.
Returns:
a String with a short description of the object, e.g., suitable for inclusion in a comma-delimited list.

getSpreadability

public double getSpreadability()
Find out how likely this object is to spread to another Room. In general, never, but subclasses may differ.
Returns:
Probability that on this turn, this object will try to spread to another room

goodbye

public void goodbye(GameObject.LeaveInfo leaveinfo)
Called when somebody leaves the room we're in. Default do-nothing implementation, overridden by various subclasses.
Parameters:
leaveinfo - Information about who's trying to leave and where they want to go

hello

public void hello(RealObject enterer)
Called when somebody enters the room we're in. Default do-nothing implementation, overridden by various subclasses.
Parameters:
enterer - who's there? (We don't know where they came from. Or why.)

initialize

public void initialize(java.lang.String initializer,
                       GameObject parentObjectArg)
                throws GameException
Initialize this object.
Overrides:
initialize in class GameObject
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.

isPredicate

protected boolean isPredicate(java.lang.String predicate)
                       throws GameException
Check if a condition applies to this object. It does this by instantiating a object of the Predicate hierarchy (based on the information passed in) which does the actual checking.
Parameters:
predicate - A string of the type [!] type : details, where type invokes a class named Checktype.
Returns:
true if the current object fulfills the predicate, false otherwise.
Throws:
GameException - if the type is not valid. Any other weird conditions should be trapped by the evaluator and turned into a false return value.
See Also:
Predicate

preClone

protected void preClone()
This is called before cloning an object, in case the object wants to divide up its resources. As usual, the superclass implementation is a no-op.

register

void register(GameObject child)
Called when we become a parent. Mazel Tov! Have a cigar! With unregister, used to keep current the list of child objects.
Parameters:
child - the object of which we are now the proud parent.

roomOf

Room roomOf()
Tell what room we're in
Returns:
If we're a Room, us; else the Room object that contains us. Could be null.

runSpy

public java.lang.String runSpy()
Give information to somebody who's spying on us.
Specified by:
runSpy in interface Spyable
Returns:
A string telling about all the things in our Room.

setParent

void setParent(RealObject newParent)
Set a new parent object. Handles registering and unregistering as necessary.
Parameters:
newParent - the new parent object; could be null if we're escaping from the world.

spread

void spread()
Try to spread to another room through a passage. Won't go to a room where a shoot of ours already exists.

tellAll

void tellAll(RealObject.ContentsMessager Messager,
             boolean iterate)
This method is used to get this object and all the objects contained in this one to run some code. This could either do exactly the same thing for all the objects or call to a method that's overridden on subclasses.
Parameters:
Messager - instance of a class which contains a method containing the code you want run.
iterate - true to pass this on to objects contained in the contents of this one.

unregister

void unregister(GameObject child)
Called when we are no longer parent to an object. Well, it feels that way, even though it just went off to college.
Parameters:
child - the object of which we once were parent.

wanderVia

protected boolean wanderVia(Room.RoomPassage wanderPassage,
                            java.lang.String msg)
Move from here to somewhere else, if we can, and make sure that the whole world knows about it.
Parameters:
wanderPassage - the RoomPassage out which we want to go.
msg - a string to announce our departure. It may contain an at sign, which would be replaced with the name of the room to which we're going.
Returns:
whether we successfully left.