package examples.timer;


import fang.*;


/**makes a timer appear on the screen
 * @author Jam Jenkins
 */
public class TimerLoop extends GameLoop
{
	/**the time sprite*/
	private StringSprite time;

	/**makes the timer sprite, adds it to
	 * the screen and starts the alarm going
	 * off every second
	 */
	public void startGame()
	{
		makeSprites();
		addSprites();
		setHelp("resources/TimerLoopHelp.txt");
		scheduleRelative(new TimerUpdate(), 1);
	}

	/**makes a string sprite to represent
	 * the time and starts it a 0.
	 */
	private void makeSprites()
	{
		time=new StringSprite("0", true);
		time.setHeight(0.5);
		time.setLocation(0.5, 0.5);
	}

	/**adds the time sprite to the canvas*/
	private void addSprites()
	{
		canvas.addSprite(time);
	}

	/**updates the time sprite to display
	 * the current time in seconds
	 * @author Jam Jenkins
	 */
	private class TimerUpdate implements Alarm
	{
		public void alarm()
		{
			time.setText(""+(int)getTime());
			scheduleRelative(this, 1);
		}
	}

	public static void main(String[] argv)
	{
		new TimerLoop().runAsApplication();
	}
}

