CS 51 Test Program # 2
Brickout
Due: Wednesday, May 7th at 4:00 PM
(Design due: Wednesday April 30th, in class)

A test program is a laboratory that you complete on your own, without the help of others. It is a form of take-home exam. You may consult your text, your notes, your lab work, or our on-line examples and web pages, but use of any other source for code is forbidden. You may not discuss these problems with anyone aside from the course instructor. You may only ask the TA's for help with hardware problems or difficulties in retrieving your program from a disk or network.

Introduction

The game Brickout (originally known as breakout) was an early video game conceived in the mid-70's at Atari as a follow-up to Pong. The history, which is described at the website http://classicgaming.gamespy.com/View.php?view=Articles.Detail&id=395, involves the young Steve Jobs and Steve Wozniak, who later were the cofounders of Apple.

The idea of the game is to use a ball and paddle to knock out bricks in a wall. Rather than explain it, you will find it easier to check out the demo below.




If you want to experience something a bit more elaborate, you can download a working Mac version version on-line.

Our simplified game begins with a set of 10 rows of 10 bricks each at the top of the board, and with a paddle at the bottom. When the user clicks on the screen the first ball appears in the center of the screen, just under the bottom-most row of bricks. It starts by moving generally downward (usually at an angle) and then bounces off the paddle, the side walls and top of the court, and the bricks remaining on the screen. Each time a brick is hit by the ball, the ball bounces off, but the brick is destroyed.

If a ball goes off the bottom of the screen then it is lost. The player can use up to three balls while playing a game. If the player destroys all of the bricks before the third ball is lost, then they win. Otherwise they lose. When the game is over, the user can click again on the screen to start a new game. This results in drawing a new set of bricks and a moving ball.

There can only be one ball in play at a time. Thus if the player clicks when a ball is still in play, the click should be ignored.

An interesting effect occurs when all of the bricks in a column have been destroyed and the ball slips through. At that time the ball will bounce around in the portion of the window, destroying bricks, until it falls through another hole and returns to the lower portion of the court. Interestingly, this effect should occur naturally with no extra effort on your part. Your program merely keeps the ball bouncing around, no matter where it happens to be on the court.

Game Details

You should begin the game by drawing the playing field, the paddle, and the bricks on the canvas. The top two rows of bricks are red, the next two are orange, then yellow, green, and finally cyan. The constants in the starter project work with a window that is 400 pixels wide and 500 pixels tall.

The x-speed should be determined by a random double generator. We have found that a motion in the y-direction of 0.2 pixels per millisecond and a motion in the x-direction of 0.1 to 0.4 per millisecond results in a very playable game. Please make sure that the ball travels at a constant speed per millisecond in this game (like the vehicles in Frogger), even if the pauses take longer than expected.

Program Design

Your program should consist of four classes:

BrickOut:
The class that is responsible for all user interaction, it is responsible for drawing the initial configuration on the canvas and responding to mouse clicks and moves, and displaying the state of the game.

MovingBall:
The class that generates the animated ball that bounces around the court. It is responsible for moving the ball around the court, bouncing off of the court walls, bricks, and the paddle.

BrickSet:
The class responsible for drawing and managing the bricks. It contains an instance variable representing the two-dimensional array of bricks. It has a method
	public boolean bounce(FilledRect ball)
    

that determines whether the ball overlaps a ball, returning a boolean and removing any bricks that it overlaps. We have provided a private method getElementAt(x,y). If a brick is at location (x,y), then getElementAt(x,y) will return the Slot (see below) corresponding to the array entry of that brick. If there is no brick in that location then the method returns null.

Slot:
This class is provided for you. The constructor creates an object representing a pair of a row and column. It has methods getRow() and getCol().

As indicated in the heading of this document, you will need to turn in a design plan for your BrickOut program well before the program itself. This design should be a clear and concise description of your planned organization of the program. Note that this design counts for 20% of your grade on the project, so please take this requirement seriously.

Include in your design a sketch of each class (excluding the Slot class) including the types and names of all instance variables and constants you plan to use, and the headers of all methods you expect to write. You should write a brief description of the purpose/function of each instance variable and method. These should be sufficient to form the comments on each of these in your final program.

In addition, you should provide pseudo-code for any method whose implementation is at all complicated. In particular, if a method is complicated enough that it will invoke other methods you write (rather than just invoking methods provided by Java or our library), or involves a loop, then include pseudo-code for the method so that we will see how you expect to use your own methods.

Implementation Order

Begin by downloading the starter project from the handouts web page. We strongly encourage you to proceed as suggested below to ensure that you can turn in a running program. While a partial program will not receive full credit, a program that does not run at all generally receives a lower grade. Moreover it is easier to debug a program if you know that some parts do run correctly.

There is a great deal of functionality to aim for in this test program. Do not worry if you cannot implement all of the functionality. Get as much of it working as you can. As we have done throughout the semester, we will consider both issues of correctness and the quality of your code when grading your program. It is always best to have full functionality, but you are better off having most of the functionality and a beautifully organized program than all of the functionality with a program that is sloppy, poorly commented, etc.

Extra Points

We have deliberately left out many features of some of the fancier versions of Brickout. As a result, there are many additional features you could add to your program. We will give 1-2 points for each extension, for a maximum of 6 points extra credit. Some possible extensions are:

Please do keep in mind that creating a well structured and well documented program that meets the regular requirements for the assignment is worth much more than the extra credit features.

Turning it in

Your design should be either neatly written or typed, and it should be turned in on paper at the beginning of class on Wednesday, April 30th. We will NOT return the design to you before the program is due. Thus you should keep a copy of your design.

Submit your code in the usual way by exporting and dragging your project into the Dropoff folder for your section. Name your folder with your last name followed by TP2. Also, be sure to double check your work for correctness, organization and style.

This program is due at 4 p.m. on May 7th, the last day of classes. While you may turn your program in late, you will be assessed a 10 point penalty for each day it is late. I.e., if you turn it in by 4 p.m. on May 8th, you will receive a 10 point penalty. If you turn it in at 4 p.m. on May 9th, you will receive a 20 point penalty, etc.

Grading Point Allocations

Value

Feature
Design preparation (20 pts total)
2 pts Variable and constant names and types
2 pts Method signatures
2 pts English descriptions
2 pts Pseudocode
4 pts Plausibility
Syntax Style (14 pts total)
6 pts. Descriptive and helpful comments
2 pts. Good names
2 pts. Good use of constants
2 pts. Appropriate formatting
2 pts. Appropriate use of public/private
Code Quality (17 pts total)
4 pts. Conditionals and loops
3 pts. Efficiency issues
4 pts. Parameters, variables, and scoping
3 pts. Appropriate selection of arrays or recursive data structures
3 pts. Correct use of arrays or recursive data structure
Organization (6 pts total, 2 for each class)
Appropriate methods, parameters, instance variables and constants
Setup (16 pts total)
2 pts. board drawn correctly
8 pts. bricks drawn correctly
2 pts. paddle drawn correctly
2 pts. initial message correct
2 pts. paddle tracks mouse correctly
Ball (14 points total)
2 pts. ball created w/ random speed when user clicks
2 pts. ball bounces around court walls and paddle correctly
2 pts. ball makes noise when it bounces
2 pts. ball bounces correctly off bricks
2 pts. ball destroys bricks correctly
2 pts. ball goes off bottom of court cleanly
2 pts. only one ball on court at a time

Grading Point Allocations

Value

Feature
Scoring (4 points total)
2 pts. number of balls left displayed properly
2 pts. number of bricks left displayed properly
Winning and Losing (9 points total)
3 pts. Player loses if three balls lost
3 pts. Player wins if all bricks are destroyed
3 pts. Game can be restarted after win or loss


Computer Science 051
Department of Computer Science
Pomona College