import java.awt.Color;
import java.awt.Image;

import objectdraw.*;

//@width 900
//@height 600
public class RacingCows extends WindowController {
    private static final int START_X = 720;
    private static final int FINISH_X = 120;
    private static final int LEFT = 20;
    private static final int RIGHT = START_X + 100;
    private static final int TOP = 20;
    private static final int LANE_WIDTH = 110;
    private static final int LANE1_BOTTOM = TOP + LANE_WIDTH;
    private static final int LANE2_BOTTOM = LANE1_BOTTOM + LANE_WIDTH;
    private static final int LANE3_BOTTOM = LANE2_BOTTOM + LANE_WIDTH;
    private static final int BOTTOM = LANE3_BOTTOM + LANE_WIDTH;
    
    private static final int BUTTON_TOP = 500;
    private static final int BUTTON_LEFT = 700;
    private static final int BUTTON_INSET = 5;
    private static final int BUTTON_WIDTH = 80;
    private static final int BUTTON_HEIGHT = 30;
    
    
    // The gif image of the purple cow
    private Image purpleCowGif;
    
    // The cows that will race
    private VisibleImage cow1, cow2, cow3, cow4;
    
    private FramedRect goBox;
    
    // Reads an image from a file and displays it on the canvas.
    public void begin() {
        purpleCowGif = getImage("cow.gif");
        
        Line startLine = new Line (START_X, TOP, START_X, BOTTOM, canvas);
        Line finishLine = new Line (FINISH_X, TOP, FINISH_X, BOTTOM , canvas);
        
        // Draw lane dividers
        new Line (LEFT, LANE1_BOTTOM, RIGHT, LANE1_BOTTOM, canvas);
        new Line (LEFT, LANE2_BOTTOM, RIGHT, LANE2_BOTTOM, canvas);
        new Line (LEFT, LANE3_BOTTOM, RIGHT, LANE3_BOTTOM, canvas);
 
        cow1 = new VisibleImage (purpleCowGif, START_X, TOP, canvas);
        cow2 = new VisibleImage (purpleCowGif, START_X, LANE1_BOTTOM, canvas);
        cow3 = new VisibleImage (purpleCowGif, START_X, LANE2_BOTTOM, canvas);
        cow4 = new VisibleImage (purpleCowGif, START_X, LANE3_BOTTOM, canvas);
        
        Text name = new Text("Racing Cows With Smooth Amination", FINISH_X, BOTTOM + 30, canvas);
        name.setFontSize(30);
        name.setColor(new Color(100, 0, 100));

        goBox = new FramedRect(BUTTON_LEFT, BUTTON_TOP, BUTTON_WIDTH, BUTTON_HEIGHT,canvas);
        new Text("Go!", BUTTON_LEFT + BUTTON_INSET, BUTTON_TOP + BUTTON_INSET, canvas);
        
        resize(900,600);
    }

    // When the user clicks the mouse, start the race
    public void onMouseClick(Location point) {
        if (goBox.contains(point)) {
            new SmoothCow (cow1, FINISH_X);
            new SmoothCow (cow2, FINISH_X);
            new SmoothCow (cow3, FINISH_X);
            new SmoothCow (cow4, FINISH_X);
        }
    }
}
