vooga.gameEngine.game
Class GameRelatedObject

java.lang.Object
  extended by vooga.gameEngine.game.GameRelatedObject
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
AbstractGame, AbstractPlayer, GameItem, GameRelatedController, GameStatusCommunicator

public abstract class GameRelatedObject
extends java.lang.Object
implements java.io.Serializable

Class GameRelatedObject is the superclass for all objects used in a game. This class sets up an event framework that allows events to be fired by an object and their listeners to be automatically updated.

Author:
Justin C. Klaassen, Jeremy Walch, Scott Brothers, Geoffrey Lawler, Jake Harer
See Also:
Serialized Form

Constructor Summary
protected GameRelatedObject()
          Creates and initializes a GameRelatedObject.
 
Method Summary
 void addEventListener(java.util.EventListener listener)
          Adds an EventListener to the GameRelatedObject.
 void clearListeners()
          Clears the listeners that are listening to this GameRelatedObject.
 boolean equals(java.lang.Object o)
           
 void fire(java.util.EventObject event)
           Calls the all methods of every registered listener that takes the given event's type as the parameter.
 void fire(java.util.EventObject event, java.util.EventListener listener)
          Fires an event to a specific listener.
 void fire(java.util.EventObject event, java.lang.String methodName)
          Determines if any registered listeners have a method matching the given methodName and event's type as the parameter; if so it invokes the method on each of the listeners.
 java.util.Map<java.lang.Class<? extends java.util.EventListener>,java.util.Set<java.util.EventListener>> getEventListeners()
          Method for getting all of the listeners associated with this object.
 int getID()
          Returns this GameRelatedObject's ID, which was derived from the system timer at the time of its instantiation.
 int getListenerCount()
          Returns the number of listeners registered on this GameRelatedObject .
 void removeEventListener(java.util.EventListener listener)
          Removes an EventListener from the GameItem.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GameRelatedObject

protected GameRelatedObject()
Creates and initializes a GameRelatedObject.

Method Detail

getID

public final int getID()
Returns this GameRelatedObject's ID, which was derived from the system timer at the time of its instantiation. This Integer is expected to be unique for each instance of GameRelatedObject

Returns:
Integer representation of this object's unique ID

getListenerCount

public int getListenerCount()
Returns the number of listeners registered on this GameRelatedObject . Intended to be similar in usage to Observable.countObservers().

Returns:
int number of listeners

addEventListener

public final void addEventListener(java.util.EventListener listener)
Adds an EventListener to the GameRelatedObject.

Parameters:
listener - to be added

removeEventListener

public final void removeEventListener(java.util.EventListener listener)
Removes an EventListener from the GameItem. If the GameRelatedObject is not being listened to by the EventListener then nothing will occur. The actual removing will only occur when the set of listeners is not in use.

Parameters:
listener - to be removed

clearListeners

public final void clearListeners()
Clears the listeners that are listening to this GameRelatedObject.


getEventListeners

public final java.util.Map<java.lang.Class<? extends java.util.EventListener>,java.util.Set<java.util.EventListener>> getEventListeners()
Method for getting all of the listeners associated with this object.

Returns:
a Map of EventListeners that are organized in bins according to their class

fire

public final void fire(java.util.EventObject event)

Calls the all methods of every registered listener that takes the given event's type as the parameter. If a listener is a GameItem, then it's relevant method is only called if GameItem#isEnabled() is true.

Convenience method for calling fire(event, null).

Parameters:
event - to be fired

fire

public final void fire(java.util.EventObject event,
                       java.lang.String methodName)
Determines if any registered listeners have a method matching the given methodName and event's type as the parameter; if so it invokes the method on each of the listeners. If methodName is null, then all methods with the event's type as the parameter will be invoked. If a listener is a GameItem, then it's relevant method is only called if GameItem#isEnabled() is true.

For example: If the event is a TimeEvent, a TimeListener is registered for this GameRelatedObject, and "timeChanged" is the methodName, then the TimeListener.timeUpdated(TimeUpdateEvent) method will be invoked with event as the parameter.

Parameters:
event - to be fired
methodName - to be invoked

fire

public final void fire(java.util.EventObject event,
                       java.util.EventListener listener)
Fires an event to a specific listener.

Parameters:
event - to fire
listener - to fire the event to

equals

public final boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object