CPSC 170 Post Lab 1
Break Out
Due Before Class on Friday, January 16th

bricks

For this assignment you modify your pong program from lab one to make the game Break Out. For those that do not know the game, Break Out is a game similar to Pong that consists of a user controlled paddle and a ball bouncing around the screen. Break Out also includes bricks (rectangles) at the opposite side of the screen as the paddle. When the ball bounces off of the bricks they disappear. The player wins the game by making all of the bricks disappear.

Details

Begin by creating a class that represents a brick. The class will need instance variables for the location and size of the brick. In addition to a constructor method that initializes the instance variables and getter and setter methods you should include a method that tests for the intersection of the brick and a ball. Think carefully about what parameters this method will need.

Next, add to the panel class an instance variable that is an array of Bricks and in the constructor initialize the array and all of the bricks in it. Add to the paintComponent method a loop that iterates over the entire array of bricks and for each brick, if it is visible, draws it. Finally, add a loop to the actionPerformed method that tests if the ball intersects with any of the bricks that are visible. If the ball does, then it should change the direction of the ball as if it hit the top of the window and set the brick that it hit to not be visible. Lastly add code that will display a congratulations message if all of the bricks are set to invisible.

Submission: Tar and submit your code on the course blackboard site.