/*
 * Graphics and Computation - 433-380
 * Project 2
 * 06 May 2006
 *
 * Brad Plant   - bkplant
 * Adam Peacock - adamdp
 */

import com.sun.opengl.util.Animator;
import java.util.Vector;
import java.util.Enumeration;


/**
 * This class provides a central place to store all the active
 * objects in the game that need to be accessed by different
 * classes.
 */
public class Game
{
	/**
	 * Store the landscape object.
	 */
	private static Landscape landscape;

	/**
	 * Store the navigation graph
	 */
	private static NavigationGraph navigationGraph;

	/**
	 * Store the on screen display object
	 */
	private static OSD osd;

	/**
	 * Store the animator object.
	 */
	private static Animator animator;

	/**
	 * Store the way points
	 */
	private static WayPoint[][] wayPoints;

	/**
	 * A list of all the game objects.
	 * I.e. objects that can be drawn.
	 */
	private static Vector gameObjects = new Vector();

	/**
	 * ghosts is used to reference the 
	 * matrix for the ghosts
	 */
	private static Vector ghosts = new Vector();

	/**
	 * Look behind (rear vision mirror)
	 */
	private static boolean lookBehind = false;

	/**
	 * Pacman 
	 */
	private static Pacman pacman;

	/**
	 * Set the landscape object.
	 *
	 * @param l The new landscape.
	 */
	public static void setLandscape(Landscape l)
	{
		landscape = l;
	}

	
	/**
	 * Get the landscape object.
	 *
	 * @return Returns the landscape object.
	 */
	public static Landscape getLandscape()
	{
		return landscape;
	}


	/**
	 * Set the navigation graph.
	 *
	 * @param n The navigation graph.
	 */
	public static void setNavigationGraph(NavigationGraph n)
	{
		navigationGraph = n;
	}


	/**
	 * Get the navigation graph.
	 *
	 * @return Return the navigation graph.
	 */
	public static NavigationGraph getNavigationGraph()
	{
		return navigationGraph;
	}


	/**
	 * Set the on screen display object.
	 *
	 * @param o The on screen display object.
	 */
	public static void setOSD(OSD o)
	{
		osd = o;
	}


	/**
	 * Get the on screen display object.
	 *
	 * @return Returns the on screen display object.
	 */
	public static OSD getOSD()
	{
		return osd;
	}


	/**
	 * Set the animator.
	 *
	 * @param a The animator to be set.
	 */
	public static void setAnimator(Animator a)
	{
		animator = a;
	}


	/**
	 * Get the animator.
	 *
	 * @return Returns the animator object.
	 */
	public static Animator getAnimator()
	{
		return animator;
	}

	
	/**
	 * Stop animation
	 */	
	public static void animatorStop() {
		if(animator.isAnimating())
			animator.stop();
	}

	
	/**
	 * Start animation
	 */	
	public static void animatorStart() {
		animator.start();
	}

	
	/** 
	 * changeAnimatorState flips the animation 
	 * from stop to start / vice verser
	 */
	public static void changeAnimationState() {
		if(animator.isAnimating())
			animator.stop();
		else 
			animator.start();
	}


	/**
	 * Set the way points.
	 *
	 * @param w The way points to be set.
	 */
	public static void setWayPoints(WayPoint[][] w)
	{
		wayPoints = w;
	}


	/**
	 * Get the way points.
	 *
	 * @return Returns <b>all</b> the way points.
	 */
	public static WayPoint[][] getWayPoints()
	{
		return wayPoints;
	}


	/**
	 * Add a game object to the list.
	 *
	 * @param gameObject The game object to be added.
	 */
	public static void addGameObject(GameObject gameObject)
	{
		gameObjects.add(gameObject);
	}


	/**
	 * Get the list of game objects.
	 *
	 * @return Returns the list of game objects/
	 */
	public static Enumeration getGameObjects()
	{
		return gameObjects.elements();
	}


	public static Pacman getPacman()
	{
		return pacman;
	}


	public static void setPacman(Pacman p)
	{
		pacman = p;
	}


	/**
	 * Set the look behind variable.
	 * I.e. set whether the object setting the camera should look
	 * behind itself or not.
	 *
	 * @param l Whether the object setting the camera should look
	 * behind itself.
	 */
	public static void setLookBehind(boolean l)
	{
		lookBehind = l;
	}


	/**
	 * Get the look behind variable.
	 * I.e. get whether the object setting the camera should look
	 * behind itself or not.
	 *
	 * @return Returns whether the object setting the camera should
	 * look behind itself.
	 */
	public static boolean getLookBehind()
	{
		return lookBehind;
	}

	/** 
	 * anyScorePillsVisible returns a boolean to say
	 * whether any score pills are still visible.
	 */ 
	public static boolean anyScorePillsVisible() {
		for(int i = 0; i < gameObjects.size(); i++) {
			try {
				ScorePill p = (ScorePill)gameObjects.elementAt(i);
				if(p.getVisibility() == true)
					return true;
			}
			catch(ClassCastException e) {
			}
		}
		return false;
	}
}
