Getting the Pucks to Bounce Off Each Other

In the Aquarium application, one fish could swim behind another, but that doesn't work for multiple pucks on the same surface; instead, they're going to bounce off each other. Now that the pucks have all been moved, the run method works through them all to see if any pucks have hit each other. If so, it bounces them (and after the pucks have bounced, the run method checks again to see if they've hit a goal). Here's how the code checks whether one puck has struck another, taking special care not to move a blocker (that is, a Puck object whose immovable method returns true) if it was hit:

 int struckPuck = -1; for (int loopIndex3 = 0; loopIndex3 < 13; loopIndex3++){ Puck testPuck = (Puck)pucks.elementAt ...

Get Java™ After Hours: 10 Projects You'll Never Do at Work now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.