CS102 Lab4
COMP-102 Breakout part 2
Due April 18th at Midnight (You have 3 weeks for this lab)
Introduction:
In this lab you will build on your
last lab to build a complete (though simple) one level breakout game.
You will add bricks, a paddle and check to see if the game has been won
or lost.
Objective:
The high level objectives of this lab are:
- Work with collections and iterators
- Continue to Explore event driven programming, this time responding to user events for graphical (But not GUI) interaction.
What you must do:
Expand your program from last time to include two more classes, the
Paddle class and the Brick class. The UML diagram below adds thess new
classes, but leaves you much more flexibility to implement this part of
the project. Your intutition about the best way to implement this small
project may be different and since there is no following project, you
can try out your design. Note however that you must have a List of
Blocks as an instance variable in your GamePanel class and use that
list to store all of your Blocks for the game
Added Program functionality
In addition to the basic functionality that you added last time, your game needs to be able to do the following exta things
- Your new game button should reset the board to the start setup and restart everything
- If the ball ever goes below the paddle, you should report
(graphically, using the game board) that the game has been lost. All
play should stop at that point.
- Add a paddle, allow the use to move the paddle either using the keyboard or the mouse.
- If the ball hits the paddle, it should bounce off, continuing
in the same x direction (though of course reversing the y direction)
- Add blocks.
- You must keep track of the blocks in a list and use an iterator to look at each one whenever you wish to look at them.
- You need to have at least four rows of blocks with at least 9 blocks in each row.
- The blocks should be at least as long as twice the size of your ball.
- The blocks should have at least two alternating colors.
- Whenever the ball hits one of the blocks, the block should
dissappear and the ball should bounce in the reverse direction. If it
is easier, you may reverse both the x and y velocities of the ball.
- If the player has removed all of the blocks, you should report that the game has been won.
Other requirements
As always
Where should you start?
If you are comfortable with programming labs of this size, you are
welcome to do the work in any order that you like. If you are not as
comfortable with the idea of starting in on a project of this size with
this much freedom to innovate (or to shoot yourself in the foot) then I
have the following suggestions for where to begin and what order to
build these components.
- Write a block class. (it should know at least its own position -
and probably its color - you might need constants for height and width
as well)
- Create the List of blocks. (instance variable, and fill the instance variable)
- Display the blocks on the screen (add to your paintComponent or
put it in another method which is called by paintComponent - be sure to
pass the Graphics object if using this latter technique)
- Create the paddle class (again it needs to know its position and size)
- Display the paddle.
- Get the paddle moving
- start working on collision detection (consider changing the
getNewPos method in your Ball class so that it takes both the paddle
and the List. check for collisions before returning a new position
- check to see if the game has been lost and act appropriately if so
- remove bricks that have been hit
- reset the game board when new game is pressed
really 7-9 could be done in any order so long as 1-6 are done first.
Extra Credit Available
For extra credit, play a sound whenever the ball destroys a brick, and another if the player loses. Extra credit is only
available for those who have finished all of the required sections of
the lab and will be applied to the lab portion of your grade.
Extra credit will be applied to the lab portion of your grade and will be worth 7 points on this project.
For those who didn't quite get the last project working
Because this project relies on the last one, I will make my solution to
the last project is available. I don't want to
influence anyone who is trying to take the 50% penalty and turn in the
first project a day late.
Submitting:
When your program is ready, you need to write a readme.txt file
that provides me the following information:
-
Your name
-
The name of your java files (and
the names of any extra non-public classes that are contained in the
file.
-
The implementation decisions that
you made. Why did you solve the problem the way that you did? (since
you are being given more freedom on this project, this part will be
worth more than usual)
-
Directions on running and using
your program. Especially anything that might not be the same for all
students. (example: how do I move the paddle, which class contains the main method?)
-
And any problems or bugs left in your program. If your
program doesn't quite work in some situations, tell me about it. If
your program doesn't run or compile, I want to know that before I
try.
When your readme and your code is ready, zip up your files and
email them to me as you did in the last three labs.