June 2005
Beginner to intermediate
336 pages
6h 29m
English
The pucks are represented by the sprite class Puck. The constructor of this class is responsible for storing all the information passed to it—the image for the puck, the type of puck (0 for a standard puck, 1 for the computer's blocker, and 2 for the user's blocker), the rectangle named edges corresponding to the dimensions of the rink, and so on. The constructor also sets up the puck's (random) initial position and velocity. Here's what the Puck constructor looks like:
public Puck(Image image1, int type, int maxVelocity, Rectangle edges, Component rink) { this.rink = rink; this.image1 = image1; if (type > 0){ doNotMove = true; } this.maxVelocity = maxVelocity; this.edges = edges; random = new Random(System.currentTimeMillis()); ...Read now
Unlock full access