org.deken.game.trigger
Class Trigger

java.lang.Object
  extended by org.deken.game.trigger.Trigger
All Implemented Interfaces:
Updateable
Direct Known Subclasses:
LocationTrigger, SimpleTrigger

public abstract class Trigger
extends java.lang.Object
implements Updateable

Title: Trigger

Description: The Trigger base class, sets up the requirements for a trigger event. It needs to be updated every tick in the game loop. This class stores the listeners and activates them, when the checkTrigger is successful.

Copyright: Copyright (c) Sep 1, 2012

Version:
1.0
Author:
Gary Deken

Nested Class Summary
static class Trigger.TRIGGER_TIMES
           
 
Field Summary
protected  boolean activated
           
 
Constructor Summary
Trigger()
           
 
Method Summary
protected  void activateListeners()
          Activate the TriggerListeners that this Trigger has been activated.
 boolean addListener(TriggerListener listener)
          Adds a TriggerListener to this trigger, so that it will be notified when this trigger is invoked.
protected abstract  void checkTrigger(long elapseTime)
          Checks if the Trigger needs to be invoked.
protected  void deactivateListeners()
          Deactivate the TriggerListeners that this Trigger has been deactivated.
 java.lang.String getName()
           
 boolean removeListener(TriggerListener listener)
          Removes a TriggerListener from this trigger, so that it will no longer be notified when this trigger is invoked.
 void reset()
          Resets this Trigger so that it can be invoked again.
 void setName(java.lang.String name)
           
 void setTimesActivated(int timesActivated)
          Set the number of times this trigger can be activated.
 void setTimesActivated(Trigger.TRIGGER_TIMES times)
           
 void stopTrigger()
          Stops this Trigger from check if it needs to be activated.
 void update(long elapseTime)
          Every tick, this trigger checks if it needs to be activated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

activated

protected boolean activated
Constructor Detail

Trigger

public Trigger()
Method Detail

addListener

public boolean addListener(TriggerListener listener)
Adds a TriggerListener to this trigger, so that it will be notified when this trigger is invoked.

Parameters:
listener -
Returns:

getName

public java.lang.String getName()
Specified by:
getName in interface Updateable
Returns:

removeListener

public boolean removeListener(TriggerListener listener)
Removes a TriggerListener from this trigger, so that it will no longer be notified when this trigger is invoked.

Parameters:
listener -
Returns:

reset

public void reset()
Resets this Trigger so that it can be invoked again.


setName

public void setName(java.lang.String name)

setTimesActivated

public void setTimesActivated(int timesActivated)
Set the number of times this trigger can be activated. The Default is one.

Parameters:
timesActivated -

setTimesActivated

public void setTimesActivated(Trigger.TRIGGER_TIMES times)

stopTrigger

public void stopTrigger()
Stops this Trigger from check if it needs to be activated.


update

public void update(long elapseTime)
Every tick, this trigger checks if it needs to be activated. Once it is active it will turn itself off.

Specified by:
update in interface Updateable
Parameters:
elapseTime -

activateListeners

protected void activateListeners()
Activate the TriggerListeners that this Trigger has been activated.


checkTrigger

protected abstract void checkTrigger(long elapseTime)
Checks if the Trigger needs to be invoked. Sub-classes will implement this method and call activateListener() and deactivateListeners()

Parameters:
elapseTime -

deactivateListeners

protected void deactivateListeners()
Deactivate the TriggerListeners that this Trigger has been deactivated.