import java.awt.Color; import becker.robots.*; import becker.robots.icons.CircleIcon; import becker.robots.icons.LabelIcon; /** * This class builds a race track for use * in program 5 * @author Doug Twitchell * */ public class RaceTrack extends City { /** * The color of carrots */ private static Color carrotOrange = new Color(255, 131, 0); /** * @param args */ public RaceTrack(){ super(-3, 3, 28, 23, 32); // create the race track this.createRaceTrack(); //create carrot patches //YOU MAY CHANGE THE PARAMETERS TO THESE TO MOVE //THE CARROT PATCH, BUT REMEMBER TO MAKE SURE //THAT ONE OF THE CARROTS IS ON THE RACE TRACK this.createCarrotPatch(2, 8, 6, Direction.NORTH); this.createCarrotPatch(2, 11, 3, Direction.NORTH); this.createCarrotPatch(5, 20, 2, Direction.EAST); this.createCarrotPatch(11, 15, 8, Direction.SOUTH); this.createCarrotPatch(11, 12, 8, Direction.SOUTH); } /** * Creates a race track by building a set * of walls * DO NOT MODIFY */ private void createRaceTrack() { //build race track Wall wall1 = new Wall(this, 3, 7, Direction.NORTH); Wall wall2 = new Wall(this, 3, 8, Direction.NORTH); Wall wall3 = new Wall(this, 3, 9, Direction.NORTH); Wall wall4 = new Wall(this, 3, 10, Direction.NORTH); Wall wall5 = new Wall(this, 3, 11, Direction.NORTH); Wall wall6 = new Wall(this, 3, 12, Direction.NORTH); Wall wall7 = new Wall(this, 3, 13, Direction.NORTH); Wall wall8 = new Wall(this, 3, 14, Direction.NORTH); Wall wall9 = new Wall(this, 3, 15, Direction.NORTH); Wall wall10 = new Wall(this, 3, 16, Direction.NORTH); Wall wall11 = new Wall(this, 3, 17, Direction.NORTH); Wall wall12 = new Wall(this, 3, 18, Direction.NORTH); Wall wall13 = new Wall(this, 3, 18, Direction.EAST); Wall wall14 = new Wall(this, 4, 19, Direction.NORTH); Wall wall15 = new Wall(this, 4, 19, Direction.EAST); Wall wall16 = new Wall(this, 5, 19, Direction.EAST); Wall wall17 = new Wall(this, 6, 19, Direction.EAST); Wall wall18 = new Wall(this, 7, 19, Direction.EAST); Wall wall19 = new Wall(this, 8, 19, Direction.EAST); Wall wall20 = new Wall(this, 9, 19, Direction.EAST); Wall wall21 = new Wall(this, 9, 19, Direction.SOUTH); Wall wall22 = new Wall(this, 10, 18, Direction.EAST); Wall wall23 = new Wall(this, 10, 18, Direction.SOUTH); Wall wall24 = new Wall(this, 10, 17, Direction.SOUTH); Wall wall25 = new Wall(this, 10, 16, Direction.SOUTH); Wall wall26 = new Wall(this, 10, 15, Direction.SOUTH); Wall wall27 = new Wall(this, 10, 14, Direction.SOUTH); Wall wall28 = new Wall(this, 10, 13, Direction.SOUTH); Wall wall29 = new Wall(this, 10, 12, Direction.SOUTH); Wall wall30 = new Wall(this, 10, 11, Direction.SOUTH); Wall wall31 = new Wall(this, 10, 10, Direction.SOUTH); Wall wall32 = new Wall(this, 10, 9, Direction.SOUTH); Wall wall33 = new Wall(this, 10, 8, Direction.SOUTH); Wall wall34 = new Wall(this, 10, 7, Direction.SOUTH); Wall wall35 = new Wall(this, 10, 6, Direction.SOUTH); Wall wall36 = new Wall(this, 10, 6, Direction.WEST); Wall wall37 = new Wall(this, 9, 5, Direction.SOUTH); Wall wall38 = new Wall(this, 9, 5, Direction.WEST); Wall wall39 = new Wall(this, 8, 5, Direction.WEST); Wall wall40 = new Wall(this, 7, 5, Direction.WEST); Wall wall41 = new Wall(this, 6, 5, Direction.WEST); Wall wall42 = new Wall(this, 5, 5, Direction.WEST); Wall wall43 = new Wall(this, 4, 5, Direction.WEST); Wall wall44 = new Wall(this, 3, 6, Direction.NORTH); Wall wall45 = new Wall(this, 4, 5, Direction.NORTH); Wall wall46 = new Wall(this, 3, 6, Direction.WEST); //put in the guide walls at the corners new Wall(this, 2, 4, Direction.SOUTH); new Wall(this, 2, 4, Direction.EAST); new Wall(this, 2, 20, Direction.SOUTH); new Wall(this, 2, 20, Direction.WEST); new Wall(this, 11, 4, Direction.NORTH); new Wall(this, 11, 4, Direction.EAST); new Wall(this, 11, 20, Direction.NORTH); new Wall(this, 11, 20, Direction.WEST); //finish line this.labelIntersection(5, 4, "Finish"); } private void createCarrotPatch(int s, int a, int length, Direction dir){ if(dir == Direction.EAST){ for(int i = 0; i < length; i++){ this.putCarrot(s, a + i); } } else if(dir == Direction.WEST){ for(int i = 0; i < length; i++){ this.putCarrot(s, a - i); } } else if(dir == Direction.SOUTH){ for(int i = 0; i < length; i++){ this.putCarrot(s + i, a); } } else if(dir == Direction.NORTH){ for(int i = 0; i < length; i++){ this.putCarrot(s - i, a); } } } /** * Puts a carrot (orange colored Thing) at street s and avenue a * @param s * @param a * DO NOT MODIFY */ private void putCarrot(int s, int a){ // System.out.println("putting " + s + "," + a); Thing carrot = new Thing(this, s, a); carrot.setIcon(new CircleIcon(carrotOrange)); } /** * Labels and intersection by putting a thing there * with a label as an icon * @param s * @param a * @param label * DO NOT MODIFY */ private void labelIntersection(int s, int a, String label) { Thing labelThing = new Thing(this, s, a); LabelIcon labelIcon = new LabelIcon(); labelIcon.setLabel(label); labelThing.setIcon(labelIcon); } }