View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Discussion 4 - Michael Levy

Discussion 4

Simulating the Rubber Ducky!
Each year, some little towns have rubber ducky races. Each participant purchases a rubber duck that has a number on it, with the proceeds typically going to some charity. The ducks are placed in lanes at the head of a river. When the lanes are opened, the ducks are off! The river currents will sweep forward the ducks in some lanes faster than ducks in other lanes, of course. Obstacles, like rocks, in a current will bump ducks into other currents.

You, being an intense competitor and a master hacker, have decided to simulate your local town’s race in order to optimize your duck’s performance. Make the assumption that all currents are in a linear (i.e., they travel in a straight line from a given lane to the finish line) at a set speed, and that obstacles in a current bump ducks randomly to one of the neighboring currents.

In designing this program I would have a total of four classes. I would have an Animator class, a Duck class, a RiverCurrent class, and an Obstacle class. The basic layout of the design would be that Animator takes care of drawing the duck(s), river, and obstacle(s). When its getting ready to draw things, it querries Duck to find out the ducks position on the course. Once it gets back the duck's position, it then updates the drawing and redraws everything to there new position. Since only the duck would be moving, as I would set up the program so you could see the entire course, only the duck would need to its position changed. As hinted at earlier, Duck would be responsible for keeping track of where its at. When asked for its position, Duck would first check with Obstacle to see if in its next movement it was going to hit an obstacle. If so Duck would randomly generate a direction and then notify Animator as to the change in its position. If Duck was not going to hit an obstacle, it would then go to RiverCurrent to find out how fast it is moving on the given current. RiverCurrent then would be responsible for holding the different speeds of the different currents and returning those speeds to Duck when asked for them. Finally, Obstacle, when instantiated, would create a random number of obstacles with positions inside the track and then store those locations so they can be looked up whenever Duck needs to move.

Link to this Page