Class MasterGame

java.lang.Object
  |
  +--GenerationGame
        |
        +--MasterGame

public class MasterGame
extends GenerationGame

This is the class that runs everything


Field Summary
(package private)  java.lang.String generationInfo
          A string used by announce to collect information on what's happening.
(package private)  java.util.GregorianCalendar masterTime
          The game time, unrelated to the real clock time
(package private)  MyVector objects
          A list of all the objects in the game
 
Fields inherited from class GenerationGame
gameFile
 
Constructor Summary
(package private) MasterGame(java.lang.String[] args)
          Create the game and do some initial bookkeeping
 
Method Summary
 void announce(GameObject thing, java.lang.String msg)
          Add an object's message to the current game state.
 void announce(java.lang.String msg)
          Add a message to the current game state for later display.
 GameObject findObjectByName(java.lang.String name)
          Given the name of an object, find it.
(package private)  java.lang.String getNextName(java.lang.String name)
          Generate an unused name with a given alphabetic beginning
 java.util.GregorianCalendar getTime()
          What time do we have?
static void main(java.lang.String[] args)
          Create a game and play it
 java.lang.String next()
          Move to the next generation by incrementing the time and letting all of our objects do something.
(package private)  void play()
          Start things going--note that this code can't be part of the static method main because it needs to instantiate an inner class.
 void register(GameObject thing)
          Learn that an object has come to be.
 java.lang.String sendMessage(java.lang.Object recipient, java.lang.String message)
          Send a message to an object and report the results
 java.lang.Object spySetup()
          Find an object to spy on (or perhaps otherwise manipulate).
 void unregister(GameObject thing)
          Learn that an object has ceased to be.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

generationInfo

java.lang.String generationInfo
A string used by announce to collect information on what's happening. It gets reset at the beginning of each event and is returned to the caller at the end.

masterTime

java.util.GregorianCalendar masterTime
The game time, unrelated to the real clock time

objects

final MyVector objects
A list of all the objects in the game
Constructor Detail

MasterGame

MasterGame(java.lang.String[] args)
Create the game and do some initial bookkeeping
Parameters:
args - as in main
Method Detail

announce

public void announce(GameObject thing,
                     java.lang.String msg)
Add an object's message to the current game state. Calls the one-argument form with the message prepended with the object's name (but a newline at the beginning of the message will remain at the beginning, before the name).
Parameters:
thing - who said it
what - they said

announce

public void announce(java.lang.String msg)
Add a message to the current game state for later display.
Parameters:
msg - The message to be added

findObjectByName

public GameObject findObjectByName(java.lang.String name)
                            throws CantFindObjectException
Given the name of an object, find it. We could use a dictionary or hashtable here, but we don't. Maybe some day, especially if we want to use this for really big games. Unfortunately, several places depend on the list of objects being a vector.
Parameters:
name - the name to find
Returns:
the object found
Throws:
CantFindObjectException - if no object is found

getNextName

java.lang.String getNextName(java.lang.String name)
Generate an unused name with a given alphabetic beginning
Parameters:
name - how the name should start, perhaps with some numbers at the end which will be discarded
Returns:
a new name with a number at the end to make it unique

getTime

public java.util.GregorianCalendar getTime()
What time do we have?
Returns:
the game time. Actually, we carefully return a clone of it so they can examine it and format it to their heart's content, but not muck up our timekeeping.

main

public static void main(java.lang.String[] args)
Create a game and play it
Parameters:
args - the usual

next

public java.lang.String next()
Move to the next generation by incrementing the time and letting all of our objects do something.
Overrides:
next in class GenerationGame
Returns:
a String reporting everything that happened.
See Also:
GameObject.doAction()

play

void play()
Start things going--note that this code can't be part of the static method main because it needs to instantiate an inner class.
Overrides:
play in class GenerationGame

register

public void register(GameObject thing)
Learn that an object has come to be.
Parameters:
thing - a new object that we need to remember.

sendMessage

public java.lang.String sendMessage(java.lang.Object recipient,
                                    java.lang.String message)
Send a message to an object and report the results
Overrides:
sendMessage in class GenerationGame
Parameters:
recipient - a Game Object to get the message
Returns:
a String reporting what happened

spySetup

public java.lang.Object spySetup()
Find an object to spy on (or perhaps otherwise manipulate). Asks the user to pick from a list.
Overrides:
spySetup in class GenerationGame
Returns:
the Game Object that the user selected. Defined as Object to comply with the interface.

unregister

public void unregister(GameObject thing)
Learn that an object has ceased to be.
Parameters:
thing - an old object that we need to forget.