import javax.swing.JFrame;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Random;

public class HuntSimulator {
    private static final int FRAME_WIDTH = 520;
    private static final int FRAME_HEIGHT = 590;
	public static Hunter hu1 = new Hunter(Color.red);
	public static Hunter hu2 = new Hunter(Color.magenta);

    public static void main (String [] args) {
	JFrame frame = new JFrame ("Hunt Simulator");

	frame.addWindowListener
	    (new WindowAdapter () {
		    public void windowClosing (WindowEvent e) {
			System.exit (0);
		    }
		}
	     );

	// Add support for keyboard input using a KeyListener

	frame.addKeyListener(new KeyAdapter () {
                    public void keyPressed (KeyEvent e) {
                      if (e.getKeyCode() == 87) {
                        System.err.println("up");
                        hu1.dir = new Direction (-1,0);
                        hu1.started = true;
                      }
                      if (e.getKeyCode() == 65) {
                        System.err.println("left");
                        hu1.dir = new Direction (0, -1);
                        hu1.started = true;
                      }
                      if (e.getKeyCode() == 83) {
                        System.err.println("down");
                        hu1.dir = new Direction (1, 0);
                        hu1.started = true;
                      }
                      if (e.getKeyCode() == 68) {
                        System.err.println("right");
                        hu1.dir = new Direction (0,1);
                        hu1.started = true;
                      }
                      if (e.getKeyCode() == 73) {
                        System.err.println("up");
                        hu2.dir = new Direction (-1,0);
                        hu2.started = true;
                      }
                      if (e.getKeyCode() == 74) {
                        System.err.println("left");
                        hu2.dir = new Direction (0, -1);
                        hu2.started = true;
                      }
                      if (e.getKeyCode() == 75) {
                        System.err.println("down");
                        hu2.dir = new Direction (1, 0);
                        hu2.started = true;
                      }
                      if (e.getKeyCode() == 76) {
                        System.err.println("right");
                        hu2.dir = new Direction (0,1);
                        hu2.started = true;
                      }
                      }
                    
                  }
                );

	Grid grid = new Grid (50, 50);
	Simulator ca = new Simulator (FRAME_HEIGHT, FRAME_WIDTH, grid);

	Container content = frame.getContentPane ();

	// Add objects to the simulation.

	grid.setObjectAt(0,0,hu1);
	grid.setObjectAt(49,49,hu2);
    Random ra = new Random();
    for (int i = 0; i < 10; i++) {
    	grid.setObjectAt(ra.nextInt(50), ra.nextInt(50), new Food());
    }
	for (int i = 0; i < 5; i++) {
    	grid.setObjectAt(ra.nextInt(50), ra.nextInt(50), new Stalker());
	}

	if (content != null) {
	    content.add (ca, BorderLayout.CENTER);
	} else {
	    System.err.println ("ERROR: No content pane");
	}

	frame.pack ();
	frame.show ();
    ca.start();
    }
}