/*	This Applet was created by Michael Morton for use by the Math Forum.
You may use pieces of code only with the consent of the Math Forum. 
*/

/*		TRAFFIC JAM
	Traffic Jam is an Applet where pieces are moved in order to reach 
a goal. It is split into 3 parts: the Canvas, the Controls, and the History.
This Main code loads the 9 images, and sets up the lay-out of the 3 pieces. 
There is one small function which just relays the color changes from the 
Controls to the Canvas.

CANVAS:
	The Canvas is where the main things happen. There are 9 small 
picts (which may not all be shown at once) across the screen. These are
movable by clicks (if it is a legal move). The counter updates on each
click, to show the total moves. The goal_strings are printed if the
goal is reached.

CONTROLS:
	The Controls are used to: 1) Change colors of various things, 
2) Change the level of difficulty, 3) Show/Hide the History, and ReDraw it.

HISTORY:
	The History prints out little squares in the same colors as the
images. It keeps track of what was clicked, and where things were/are.

*/

import java.awt.*;
import java.util.*;
import java.applet.Applet;

public class Jam extends java.applet.Applet {
	final int NUM_PICS = 9;	
	Image all_pics[] = new Image[NUM_PICS];

	JamCan can;		// CANVAS
	Controls jamcontrols;	// CONTROLS
	HistWindow history;	// HISTORY


	public void init() {
		// Load the Pics
		for (int i = 0; i < NUM_PICS; i++)
			all_pics[i] = getImage(getCodeBase(), i+".gif");


		// Make the 2 main Frames
		can = new JamCan(this, all_pics);
		jamcontrols = new Controls(this);
	
		// Make the History Window
		history = new HistWindow(this);
		history.resize(220,550);

		//Set Layout FOR 2 Frames
		this.setLayout(new GridLayout(2,1,10,10));

		//Add the Frames to the Panels
		add(can);
		add(jamcontrols);

	}

	//This Function handles the update of colors from the Control Frame.
	//Hopefully this function is self-evident.
	void update_jamcolor(String choice, String col) {
		Color theColor = Color.black;

		if (col.equals("Blue")) theColor = Color.blue;
		else if (col.equals("Red")) theColor = Color.red;
		else if (col.equals("Green")) theColor = Color.green;
		else if (col.equals("Black")) theColor = Color.black;
		else if (col.equals("White")) theColor = Color.white;
		
		can.updatecolor(choice, theColor);
	}

}





