//Assignment 3: Add code in action to make Karl get to the red
//   dot in the fewest steps possible.
// USE LOOPS!!!
//Show your teacher when you are finished.

import java.awt.*;
import java.applet.*;


public class Robot_Assign3 extends Applet
{
    RobotWorld dirt; //The World Object
    Robot Karl; //The Robot Object
    Button go;
    
    
    public void init ()
    {   //set up the button
	go = new Button ("GO");
	add (go);

	//Add the World, add some walls
	dirt = new RobotWorld ();
	for (int i=0; i<9; i++)
	{ dirt.placeWall (1, i);
	 
	}
	for (int i=2; i<8; i++)
	{ dirt.placeWall(i,1);
	  dirt.placeWall(i+2,3);
	  dirt.placeWall(i,5);
	  dirt.placeWall(i+2,7);
	 } 
	dirt.placeDot (2,0);
	//Add Karl, top left
	Karl = new Robot ();
    }


    public boolean action (Event e, Object o)
    {
	Graphics g = getGraphics ();
	if (e.target == go)
	{   //Add code to turn Karl around and get to the red dot here.
	    Karl.move (g, dirt);
	
	}
      
	return true;
    }


    public void paint (Graphics g)
    {//Draw Karl and the World
	dirt.drawWorld (g);
	Karl.drawRobot (g);

    }
}

