Creating the Pucks

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()); ...

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.