import objectdraw.*; import java.awt.Color; // maintains a collection of FilledRects public class BreakoutBricks { // the array used to hold the rectangles private FilledRect[] bricks; // the number of rectangles currently in the array private int numBricks = 0; // Create a collection that can hold 'size' rectangles public BreakoutBricks(int size) { bricks = new FilledRect[size]; } // add a new rectangle to the collection (if there is room) public void add(FilledRect newRect) { bricks[numBricks] = newRect; numBricks++; } // return a rectangle that overlaps the ball and remove it from the // collection, otherwise return null public FilledRect getIntersectedBrick(FilledOval ball) { for (int pos = 0; pos < numBricks; pos++) { if (ball.overlaps(bricks[pos])) { FilledRect result = bricks[pos]; bricks[pos] = bricks[numBricks - 1]; numBricks--; result.removeFromCanvas(); return result; } } return null; } }