public class GameObject {
public void initialize (String initializer, GameObject parentObjectArg)
throws GameException { }
public void announce (String message) {}
public void doAction () { }
public void kill () {}
static public void setMasterGame (MasterGame argMasterGame) {}
static public MasterGame getMasterGame () {}
static public GameObject newInstance (String objectType, String initializer, GameObject owner)
throws CantCreateObjectException {}
public String toString () {}
class LeaveInfo {
RealObject leaver;
Room.RoomPassage leavePassage;
boolean okay;
} // end inner class LeaveInfo
} // end class GameObject
class RealObject extends GameObject implements Cloneable, Spyable {
// overrides initialize
public void doAction ()
{
String retval;
/* We'd like to have a separate Spreadable subclass, but
lacking multiple inheritance, this seems like the best way
to handle it.
*/
if (Math.random () < getSpreadability())
spread ();
retval = getLongDescription ();
if (contents.size() > 0)
retval = retval + " " + getShortDescription () + " contains " +
contents.size() + " object(s).";
announce (retval);
super.doAction ();
}
public double getSpreadability () {}
void spread () {}
protected boolean isPredicate (String predicate)
throws GameException {}
Room roomOf () { }
RealObject getParent() {}
void setParent(RealObject newParent) {}
public void kill () { }
public String getShortDescription () { }
public String getLongDescription ()
{
if (longDescription.length () == 0)
return "Length of " + name + ".lD = 0";
else if (!(longDescription.substring (0, 1).equals ("@")))
return longDescription;
else
{
DescriptionLineProcessor lp = new DescriptionLineProcessor ();
Utility.processFile (longDescription.substring (1), lp);
return lp.toString ();
}
} // end GetLongDescription
class DescriptionLineProcessor implements LineProcessor {
public boolean processLine (String line, int number) {}
public void noSuchFile (String gameFile) {}
public void ioException (String gameFile, IOException e) {}
public String toString () {}
} // end class DescriptionLineProcessor
void register (GameObject child) { }
void unregister (GameObject child) { }
public boolean checkLeave (LeaveInfo leaveinfo) {}
public void goodbye (LeaveInfo leaveinfo)
{ // may be overridden by subclasses
}
public void hello (RealObject enterer) {}
void tellAll (ContentsMessager argMessager, boolean iterate) {}
protected void preClone () {} // placeholder for subclasses
protected Object clone () {}
protected boolean wanderVia (Room.RoomPassage wanderPassage, String msg) {}
public String runSpy () {}
class ContentsMessager {
ContentsMessager (Object argObject) {}
final void tellChildren (RealObject argReal, boolean iterate) {}
void descendantMessage (RealObject argReal) {} }} /* end class RealObject */
class Room extends RealObject {
class RoomPassage {
RoomPassage (Passage argPassage, String argDirection) { }
public String toString () {}
public Room getOuterReference () {return Room.this;}
} // end inner class RoomPassage
public void doAction ()
{
announce ("\n************** " + name + "*******************");
super.doAction ();
if (passages.size() > 0)
announce ("There are " + passages.size() + " passages.");
announce ("************** " + name + "*******************\n");
}
public void enter (RealObject enterer) {}
public boolean canLeave (RealObject leaver, Room.RoomPassage leavePassage) {}
public void leave (RealObject leaver, RoomPassage leavePassage) {}
} // end class Room
class Outside extends Room {
public String getLongDescription ()
{
String weather;
if ((masterGame.getTime().getHour() + 6) / 12 == 1) // 6 ... 17
weather = "sunny";
else
weather = "night time";
return super.getLongDescription() + " It is " + weather + " out here.";
}
} // end class Outside
class Wanderer extends RealObject {
// overrides initialize
public void doAction ()
{
announce ("In " + roomOf());
if (Math.random() < mobility && roomOf().passages.size() > 0 &&
parentObject == roomOf())
{ wanderVia ((Room.RoomPassage) roomOf().passages.randomEntry(), "Ran off to @.");
}
}
} // end class Wanderer
class Animal extends Wanderer {
public void doAction()
{
if (!(lots of code here to maybe eat something))
super.doAction();
} // end doAction
} // end class Animal
class Mouse extends Animal implements Food{
Mouse() {}
public void doAction ()
{
if (parentObject == roomOf() || Math.random() > .3333)
super.doAction ();
else
{
announce ("Escapes!");
// code here to implement escape
}
}
}
/* Food implementation */
public double getCalories () {}
public boolean isVegetarian () {}
public void eatMe () {}
} // end Mouse
class Trap extends RealObject{
// overrides initialize & hello
} // end class Trap
class Ensnarler extends RealObject {
// overrides initialize, checkLeave
} // end class Ensnarler
class Vines extends Ensnarler {
public void doAction ()
{
super.doAction ();
ensnarlRate = .02 + .98 * ensnarlRate;
growth = .01 + .99 * growth;
}
// overrides getSpreadability (), preClone ()
} // end class Vines
class Cat extends Animal {
Cat() {}
} // end class Cat
class FoodHunk extends RealObject implements Food {
// overrides initialize & implements Food
public String getLongDescription()
{
if (pieces > 10)
return "a large hunk of " + shortDescription;
if (pieces > 4)
return "a small hunk of " + shortDescription;
return "a morsel of " + shortDescription;
}
} // end class FoodHunk
class Toddler extends Wanderer {
Toddler() {}
public void goodbye (LeaveInfo leaveInfo)
{
byeMessage = "Waves byebye at " + leaveInfo.leaver + ".";
byeCount = 5;
announce (byeMessage);
}
public void doAction ()
{
if (--byeCount > 0)
announce (byeMessage);
else
super.doAction ();
}
} // end class Toddler
class Dog extends Animal {
Dog() {}
public void goodbye (LeaveInfo leaveInfo)
{
if (Math.random () < .6)
followInfo = leaveInfo;
}
public void doAction ()
{ if (followInfo == null)
super.doAction ();
else
{
wanderVia (followInfo.leavePassage,
"Follows " + followInfo.leaver + " to @.");
followInfo = null;
}
if (Math.random() < .4)
announce ("barks");
}
} // end class Dog
class Passage extends GameObject {
// overrides initialize , doAction
Passage ()
public Room otherEnd (Room thisEnd) {}
} // end class Passage
class Horolog extends RealObject { }
// overrides initialize
public String getLongDescription ()
{
return Utility.replace (super.getLongDescription (),
"@", masterGame.getTime().format (timeFormat));
}
} // end class Horolog