/**
 * <p>
 * Copyright © 2009-2010, Bruce-Robert Pocock
 * </p>
 * <p>
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 * </p>
 * <p>
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 * </p>
 * <p>
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 * </p>
 * 
 * @author brpocock
 */

package org.starhope.vergil.game;

import java.io.IOException;
import java.net.UnknownHostException;

import org.starhope.appius.except.UserDeadException;
import org.starhope.vergil.logic.GameImplementor;
import org.starhope.vergil.net.AppianClient;

/**
 * This is the static class that dispatches calls to the specific
 * GameImplementor for ths local client implementation
 * 
 * @author brpocock
 * 
 */
public class Virgil {

	private static AppianClient client;
	/**
	 * WRITEME
	 */
	private static GameImplementor gameImplementor;

	/**
	 * WRITEME
	 * 
	 * @param hostName WRITEME
	 * @param portNumber WRITEME
	 */
	public static void connectClient (final String hostName,
			final int portNumber) {
		Virgil.client = new AppianClient ();
		try {
			Virgil.client.connect (hostName, portNumber);
		} catch (final UnknownHostException e) {
			Virgil.reportBug (e);
		} catch (final IOException e) {
			Virgil.reportBug (e);
		} catch (final UserDeadException e) {
			Virgil.reportBug (e);
		}

	}

	/**
	 * WRITEME
	 * 
	 * @return WRITEME
	 */
	public static String getImplementorCanonicalName () {
		return Virgil.gameImplementor.getClass ().getCanonicalName ();
	}

	/**
	 * WRITEME
	 * 
	 * @return WRITEME
	 */
	public static String getImplementorCopyright () {
		return Virgil.gameImplementor.getGameCopyright ();
	}

	/**
	 * WRITEME
	 * 
	 * @return WRITEME
	 */
	public static String getImplementorSubtitle () {
		return Virgil.gameImplementor.getGameSubtitle ();
	}

	/**
	 * WRITEME
	 * 
	 * @return WRITEME
	 */
	public static String getImplementorTitle () {
		return Virgil.gameImplementor.getGameTitle ();
	}

	/**
	 * WRITEME
	 * 
	 * @return WRITEME
	 */
	public static boolean isDebug () {
		return Virgil.gameImplementor.isDebug ();
	}

	/**
	 * WRITEME
	 * 
	 * @param string WRITEME
	 */
	public static void reportBug (final String string) {
		Virgil.gameImplementor.reportBug (string);
	}

	/**
	 * WRITEME
	 * 
	 * @param string WRITEME
	 * @param t
	 */
	public static void reportBug (final String string, final Throwable t) {
		Virgil.gameImplementor.reportBug (string, t);
	}

	/**
	 * WRITEME
	 * 
	 * @param t WRITEME
	 * 
	 */
	public static void reportBug (final Throwable t) {
		Virgil.gameImplementor.reportBug (t);
	}

	/**
	 * WRITEME
	 * 
	 * @param implementation WRITEME
	 */
	public static void setImplementation (
			final GameImplementor implementation) {
		Virgil.gameImplementor = implementation;
		Virgil.gameImplementor.logEvent ("game.start",
		"Set implementation through Publius Vergilius Maro");
	}

}
