/* 
	JCavernApplet.java

	Title:			JCavern And Glen
	Author:			Bill Walker
	Description:	
*/

package jcavern;

import java.awt.*;
import java.net.*;
import java.awt.event.*;
import java.applet.*;

/**
 * JCavernApplet is the launcher for the java version of cavern and glen.
 *
 * @author	Bill Walker
 */
public class JCavernApplet extends Applet
{
	/** * A view of the game world */
	private WorldView			mWorldView;
	
	/** * A view of the player statistics */
	private PlayerView			mPlayerView;
	
	/** * A model of the game world */
	private World				mWorld;
	
	/** * The representation of the player */
	private Player				mPlayer;
	
	private static TextArea		gLogView;

	/**
	 * Creates game world, player, viewers.
	 */
	public JCavernApplet()
	{
	}
	
	public static void log(String aString)
	{
		if (gLogView != null)
		{
			gLogView.append(aString);
			gLogView.append("\n");
		}
	}

	/**
	 * Installs KeyListener for keyboard commands.
	 */
	public void start()
	{
		mWorldView.requestFocus();
        mWorldView.addKeyListener(new KeyboardCommandListener(mWorld, mPlayer));
	}

	// Get applet information
	public String getAppletInfo() 
	{
		return "JCavern 0.0, Bill Walker";
	}

	// Initialize the applet
	public void init()
	{
		try
		{
			MonsterFactory.loadPrototypes(new URL(getDocumentBase(), "./monster.dat"));
	
			// Create a player and a view of the player
			mPlayer  = new Player("Bill");
			mPlayerView = new PlayerView(mPlayer);
			mPlayer.setMission(MonsterFactory.createMission(mPlayer));
	
			// Create a world  and a view of the world
			mWorld = new World();
			mWorld.placeRandomTrees();
			mWorld.placeRandomCastles();
			mWorld.placeRandomTreasureChests(mPlayer);
			mWorld.placeWorthyOpponents(mPlayer, 10);
			mWorldView = new WorldView(mWorld);
	
			gLogView = new TextArea(5, 60);
			gLogView.setEditable(false);
			
			mWorldView.setSize(500, 200);		
			add(mWorldView);
			mWorld.addObserver(mWorldView);
			
			mPlayerView.setSize(500, 150);		
			add(mPlayerView);
			mPlayer.addObserver(mPlayerView);
			
			add(gLogView);
			
			// Put the player in the world
			mWorld.place(mWorld.getRandomEmptyLocation(), mPlayer);
		}
		catch(ThingCollisionException tce)
		{
			System.out.println("JCaverApplet.init " + tce);
		}
		catch(MalformedURLException mue)
		{
			System.out.println("JCaverApplet.init " + mue);
		}
	}

}

@@ -1231,16 +1231,129 @@
 it()%0A%09%7B%0A
+%09%09setBackground(Color.black);%0A%09%09setForeground(Color.orange);%0A%09%09setFont(new Font(%22Monospaced%22, Font.PLAIN, 12));%0A%0A
 %09%09try%0A%09%09
@@ -1684,171 +1684,33 @@
 d = 
-new World();%0A%09%09%09mWorld.placeRandomTrees();%0A%09%09%09mWorld.placeRandomCastles();%0A%09%09%09mWorld.placeRandomTreasureChests(mPlayer);%0A%09%09%09mWorld.placeWorthyOpponents(mPlayer, 10
+World.createWorld(mPlayer
 );%0A%09
@@ -1816,16 +1816,97 @@
 false);%0A
+%09%09%09gLogView.setBackground(Color.black);%0A%09%09%09gLogView.setForeground(Color.orange);%0A
 %09%09%09%0A%09%09%09m
@@ -2121,137 +2121,42 @@
 %09%0A%09%09
-%09// Put the player in the world%0A%09%09%09mWorld.place(mWorld.getRandomEmptyLocation(), mPlayer);%0A%09%09%7D%0A%09%09catch(ThingCollisionException tc
+%7D%0A%09%09catch(JCavernInternalError jci
 e)%0A%09
@@ -2203,14 +2203,30 @@
 nit 
+internal error 
 %22 + 
-tc
+jci
 e);%0A

Use new factory method in World for creating a world