import java.applet.Applet;
import java.awt.*;
//handles the horse drawing

public class horse 
{
    private Applet surface;
    private Color colour;
    private int x;
    private int y;
    private String name;
    
    public horse (Applet surface2, Color colour2, String name2)
    {
	colour = colour2;
	surface = surface2;
	name = name2;
    }

    public String getName ()
    {
	return name;
    }
    
    public void startHorse (int x2, int y2)
    { //Pre: x2, y2 is a valid point on the screen. x2<500.
	//Post: enters starting values for the horse's position
	x = x2;
	y = y2;
	drawHorse ();
    }


    public void eraseHorse ()
    {
	drawit (Color.white, Color.white);
    }


    public void drawHorse ()
    {
	drawit (colour, Color.black);
    }


    public void drawit (Color c1, Color c2)
    { //Pre: horse is properly initialized, x and y are a valid position
	//Post: horse of the right colour is drawn at position x,y
	Graphics g = surface.getGraphics();

	g.setColor (c1);
	//Put the points in an array
	int XArray [] = {85, 88, 95, 95, 92, 83, 78, 75, 76, 71, 79, 69, 65, 74, 64, 63, 58, 50, 44, 54, 55, 48, 39, 46, 42, 33, 39, 28, 32, 27, 23, 28, 26, 18, 15, 1, 0, 10, 16, 27, 40, 60, 67, 79, 85};
	int YArray [] = {1, 6, 13, 16, 19, 16, 23, 26, 32, 38, 50, 58, 55, 50, 41, 45, 54, 61, 59, 51, 40, 36, 46, 55, 58, 46, 36, 43, 61, 63, 42, 37, 27, 28, 32, 34, 31, 29, 21, 17, 14, 16, 13, 6, 1};
	for (int i = 0 ; i < 45 ; i++)
	{
	    XArray [i] += x;
	    YArray [i] += y;
	}
	//Draw the horse
	g.fillPolygon (XArray, YArray, 45);

	//Draw the border
	g.setColor (c2);
	g.drawPolygon (XArray, YArray, 45);
	g.drawString (name, x+30,y+30);
	g.drawLine (595,0,595,1000);
    }


    public void moveHorse ()
    { //Pre: x<500
	//Post: x is increased by a random amount between 1 and 30
	x += (int) ((Math.random () * (30 - 1)) + 1);
    }


    public boolean checkit ()
    { //Pre: none
	//Post: returns true if x>500 - the horse has finished the race
	if (x > 500)
	    return true;
	else
	    return false;
    }



}

