com.holub.life
Class Clock

java.lang.Object
  extended by com.holub.life.Clock

public class Clock
extends Object

The Clock class handles the timing of gameboard updates. It creates its own menu (which sets the clock speed), and sends notifications off to any observers every time the clock "ticks."

Revisions

12-8-2004 AIH Added a kludge to the clock-tick handler that checks whether any menu item is active before it allows the clock to tick. This mod fixes a bug that caused the running game to overwrite any displayed menus. See menuIsActive() for details.


Nested Class Summary
static interface Clock.Listener
          Implement this interface to be notified about clock ticks.
 
Method Summary
 void addClockListener(Clock.Listener observer)
          Add a listener that's notified every time the clock ticks: Clock.instance().addClockListener ( new Clock.Listener() { public void tick() { System.out.println("tick!")
static Clock instance()
          The clock is a singleton.
 void startTicking(int millisecondsBetweenTicks)
          Start up the clock.
 void stop()
          Stop the clock
 void tick()
          Force the clock to "tick," even if it's not time for a tick.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

instance

public static Clock instance()
The clock is a singleton. Get a reference to it by calling Clock.instance(). It's illegal to call new Clock().


startTicking

public void startTicking(int millisecondsBetweenTicks)
Start up the clock.

Parameters:
millisecondsBetweenTicks - The number of milliseconds between ticks. A value of 0 indicates that the clock should be stopped.

stop

public void stop()
Stop the clock


addClockListener

public void addClockListener(Clock.Listener observer)
Add a listener that's notified every time the clock ticks:
  Clock.instance().addClockListener
  (     new Clock.Listener()
        {       public void tick()
                {       System.out.println("tick!");
                }
                }
  );
  


tick

public void tick()
Force the clock to "tick," even if it's not time for a tick. Useful for forcing a tick when the clock is stopped. (Life uses this for single stepping.)