June 2005
Beginner to intermediate
336 pages
6h 29m
English
The computer is supposed to move its blocker to intercept as many of the pucks as it can before they hit its goal. Here's how that works—if any puck is on track to hit the computer's goal, it calculates how long the puck will take to get there. It then moves to intercept the one that will hit the goal first. This is how the code calculates the next Y coordinate, impactY, at which a puck will hit the computer's goal:
int lowestTime = 10000; int impactY = -1; for (int loopIndex3 = 0; loopIndex3 < 12; loopIndex3++){ Puck movingPuck = (Puck)pucks.elementAt (loopIndex3); Rectangle r = movingPuck.rectangle; Point mPosition = new Point(r.x, r.y); Point mVelocity = movingPuck.velocity; if(mVelocity.x > 0 && !movingPuck.gone()){ ...Read now
Unlock full access