Excerpt from Description of Exercise

Objective: To gain experience defining constructor and method parameters and using active objects.

The Scenario.

For this lab, we would like you to implement a game called Boxball. This is a simple game in which the player attempts to drop a ball into a box. Boxball has 3 levels of difficulty. With each increasing level, the box gets smaller, and the player is required to drop the ball from a greater height.

When the game begins, the playing area is displayed along with three buttons that allow the player to select a level of difficulty. The player drops a ball by clicking the mouse in the region of the playing area above the minimum height line. If the ball falls completely within the box, the box is moved to a random location. Otherwise, it remains where it is. In either case, the player may go again, dropping another ball.

The boxball playing area should appear as follows:

You will need to define three classes: a Box class, a Ball class, and a Boxball class that extends WindowController. The Boxball class should be responsible for drawing the playing area when the program starts. It should also handle the player's mouse clicks.

The Box class will allow you to create and manipulate the box at the bottom of the playing area. A box is responsible for knowing how to move to a new random location when the ball lands in the box.

The Ball class should allow you to create a ball that falls at a constant rate. When the ball reaches the bottom of the playing area, the player should be told whether the ball landed in the box. The ball should then disappear.

Handouts Describing the Exercise

Student Resources for Lab Exercise

Sample solutions