Date: Thu, 01 May 2003 15:20:11 -0500 (CDT) From: Mark Jacobson To: 810-061-02@uni.edu Subject: Frogger help, Final at 10 a.m. next Thursday... Java students, Here are some directions and hints and help concerning the Frogger project: From: http://www.cns.uni.edu/~jacobson/061/lab6/frogger.htm "The purpose of an object of the Lane class is to constantly generate the vehicles that travel in a particular lane on your highway. As such, the lane does not actually correspond to any drawing on the screen. Instead, a Lane will be an ActiveObject that creates Vehicles. So a Lane generates Vehicles. It its an ActiveObject it has a start() statement and a run() method and a pause() between the generation of Vehicles. Van or jeep or taxi or car is generated every so often in any given Lane. "The constructor for a Lane is quite simple. The lane was already drawn as part of the background in our window controller so we do not need to update the display. One thing we know is that all the traffic in a lane should drive at the same speed so that cars do not run into each other. The lane should pick a random speed for all its cars to use. We have found speeds in the range .033 to .133 pixels/millisecond to be good. (That's approximately 1 pixel/30 milliseconds to 4 pixels/30 milliseconds.) You can choose a fixed speed for a Lane to, instead of picking it randomly. But a Lane will have a set speed and all Vehicles for that Lane will always go that same speed. A lane's main responsibility is to periodically place a new car on the screen. It will do this inside the run method. In the while loop of the run method, the lane should generate a car, wait a while to allow a gap between cars, generate another car, and so on. " How do you place a car on the screen? More on this later.... Notice how the Image argument is passed to the Lane contstructor. So the Lane will always generate the same kind of Vehicles. This makes it simpler! Its a Lane of always Jeeps always going at the same speed and in the same direction. ------ private Image vehiclePic; private Location whereAt; private DrawingCanvas canvas; public Lane( Image vehiclePic, Location whereAt, double velocity, Frog frog, DrawingCanvas canvas ) { this.velocity = velocity; this.frog = frog; this.vehiclePic = vehiclePic; this.whereAt = whereAt; this.canvas = canvas; <----- YOU MUST DO THIS TO RECORD in the PIV where the Applet window object is. The Image object in the argument list is named here vehiclePic. The Lane class extends ACTIVEOBJECT or we could not do animations, right? You cannot The assignment CLEARLY states: "In order to check if the vehicle runs over the frog, you also need to pass the frog as a parameter to the Vehicle constructor." That is why the Frog object was passed to the Lane constructor. So the Lane class, when it generates a new Vehicle object, can pass the FROG as a parameter when it requests the new Vehicle. Vehicle objects need to know about Frog objects, so they can find out if they have hit the Frog or not, right? Each Vehicle object needs to know this, but only needs to know about the one FROG object that is part of the game. There is only ONE Frog and it comes into existence at the beginning of the game. It would not make as much sense or be as easy a programming task to have the Frog object be notified upon the creation of every new Vehicle that came down the road or turnpike or Lane. public Lane( Image vehiclePic, Location whereAt, double velocity, Frog frog, DrawingCanvas canvas ) { this.velocity = velocity; this.frog = frog; this.vehiclePic = vehiclePic; this.whereAt = whereAt; this.canvas = canvas; <----- YOU MUST DO THIS TO RECORD in the could be rewritten as follows, avoiding the need for the keyword this to distinquish between the PIV for the current object, and the parameter. private Image vehiclePic; private Location whereAt; private DrawingCanvas canvas; public Lane( Image vPic, Location pt, double v, Frog f, DrawingCanvas c ) { velocity = v; frog = f; vehiclePic = vPic; Keyword this is now removed .... whereAt = pt; ---- canvas = c; this.canvas = c is same as canvas = c here. ---- Hope this helps on some of the tasks and your understanding. Remember, consume some ink and scratch paper as you read and reread and write down ideas and descriptions from the project assignment and study examples from web site or Williams College textbook or lecture notes that have concepts and code and techniques that can be applied to this project. If you do the project in this manner, you are also getting the best possible type of preparation for the final exam. And you will more likely get the project working correctly free of bugs sooner, even though the above approach seems like it might be SLOWER. Its not slower to do it the Wright way!!!! --- The exam is on Thursday, May 8th from 10:00 a.m. until 11:50 a.m. in our regular WRT 105 classroom. Mark