import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * The controller for a game.  The controller handles the time and
 * the player's input.
 *
 * @author Jim Glenn
 * @version 0.1 from LiberationGame of 1/8/2009 (from CalaverasCrossingControl)
 */

public class GameControl extends KeyAdapter
{
    /**
     * The game model this controller is connected to.
     */

    protected GameModel model;

    /**
     * Creates a controller connected to the given game model and view.
     *
     * @param g a game
     */

    public GameControl(GameModel m)
    {
	model = m;

	Timer t = new Timer(1000 / 20,
			    new ActionListener() {
				public void actionPerformed(ActionEvent e)
				{
				    timerTick();
				}
			    });
	t.start();
    }

    /**
     * Handles timer events.
     */

    public synchronized void timerTick()
    {
	model.update();
    }
}

