/* * Filename: RaceTrack.java * Last Modified on Feb 27, 2006 * * Course: ITK 168 * Semester: Spring 06 * */ import java.awt.Color; import becker.robots.*; import becker.robots.icons.*; /** * This class builds a race track for use in program 5. * * The track is basically rectangular with special corners that make them easier to locate. * There are carrot patches placed around the track. * There are no carrots placed inside the corners. * The default constructor has directions for varying the placement of the carrot patches * * @author Doug Twitchell - modified by Shirley White * @version 2 - this version is generic with constants to make it easier to modify * */ public class RaceTrack extends City { // you may change these values public static final int TRACK_HT = 10; //The height of the track public static final int TRACK_WD = 10; //The width of the track // do not change this value private static Color carrotOrange = new Color(255, 131, 0); /** * default constructor will create the complete race track with carrot patches */ public RaceTrack(){ // you may change these numbers to change the size of the original window super(-5, -2, 28, 23, 32); // create the race track - do not remove or change this call this.createRaceTrack(); //create carrot patches - read method comment for details on how to do this //you may change any of the following - these are just samples //these 3 will be on the north side of the track // note the first param does not change - 2 this.createCarrotPatch(2, 6, 3, Direction.NORTH); this.createCarrotPatch(2, 8, 6, Direction.NORTH); this.createCarrotPatch(2, RaceTrack.TRACK_WD+5, 3, Direction.NORTH); //these 3 will be on the west side of the track // note the second param does not change - 4 this.createCarrotPatch(4, 4, 2, Direction.WEST); this.createCarrotPatch(10, 4, 2, Direction.WEST); this.createCarrotPatch(RaceTrack.TRACK_HT+2, 4, 8, Direction.WEST); //these 3 will be on the south side of the track // note the first param does not change - RaceTrack.TRACK_HT+4 this.createCarrotPatch(RaceTrack.TRACK_HT+4, 6, 8, Direction.SOUTH); this.createCarrotPatch(RaceTrack.TRACK_HT+4, 10, 8, Direction.SOUTH); this.createCarrotPatch(RaceTrack.TRACK_HT+4, RaceTrack.TRACK_WD+5, 8, Direction.SOUTH); //these 3 will be on the east side of the track // note the second param does nto change - RaceTrack.TRACK_WD+7 this.createCarrotPatch(4, RaceTrack.TRACK_WD+7, 2, Direction.EAST); this.createCarrotPatch(6, RaceTrack.TRACK_WD+7, 10, Direction.EAST); this.createCarrotPatch(RaceTrack.TRACK_HT+2, RaceTrack.TRACK_WD+7, 8, Direction.EAST); } /* * DO NOT MODIFY * Use this method to create carrot patches. * * The length parameter may be any reasonable number * * Take care in setting the other parameter values as described here: * * if the street=2, the avenue may be any number between 6 and * the RaceTrack.TRACK_WD+5 - with Direction.NORTH * * if the street=RaceTrack.TRACK_HT+4, the avenue may be any number * between 6 and the RaceTrack.TRACK_WD+5 - with Direction.SOUTH * * if the avenue is 4, the street may be any number between 4 and * the RaceTrack.TRACK_HT+2 - with Direction.WEST * if the avenue is RaceTrack.TRACK_WD+7, the street may be any * number between 4 and RaceTrack.TRACK_HT+2 - with Direction.EAST * DO NOT MODIFY */ private void createCarrotPatch(int street, int avenue, int length, Direction dir){ if(dir == Direction.EAST){ for(int i = 0; i < length; i++){ this.putCarrot(street, avenue + i); } } else if(dir == Direction.WEST){ for(int i = 0; i < length; i++){ this.putCarrot(street, avenue - i); } } else if(dir == Direction.SOUTH){ for(int i = 0; i < length; i++){ this.putCarrot(street + i, avenue); } } else if(dir == Direction.NORTH){ for(int i = 0; i < length; i++){ this.putCarrot(street - i, avenue); } } } /* * DO NOT MODIFY * Creates a race track by building a set of walls * DO NOT MODIFY */ private void createRaceTrack() { //build race track for(int i=0; i