Due March 26th at Midnight
(this seems like a long way off, but its not, its the week after break)
Introduction:
In this lab you will build the first
part of a one level bounce-like game. In this level you will create the
game board and have a colored ball bounce around the game board, making
sure that the ball never leaves the board.
Objective:
The high level objectives of this lab are:
- Use a UML diagram to help you begin writing your program from a given program design.
- Implement all four of the object oriented relationships that we have studied in class.
- Explore event driven programming that is not based on user intereaction (using the javax.swing.Timer class)
- Use user-defined graphics to extend your GUIs.
What you must do:
You must write three classes, implementing the design in the UML diagram below. Your project will show a ball bouncing around the screen. A picture of my solution can be found below the UML diagram.
My project:
You must implement these three classes:
You must have the instance variables
and methods shown in the diagram above. A brief description of what
each method should do is given below. You are welcome to add any
additional instance variables or methods that you want.
Method functionality
- Class Ball
- Constructor should set the ball color and do any other setup that needs to be done.
- getColor simply returns the _color instance variable (so that the gameboard can know what color to draw the ball.
- setBoardSize should set the _bHeight and _bWidth instance variables with the width and height of the board respectively.
- getNewPos should calculate
the appropriate new postion of the ball following its current
trajectory and return the new upper left hand corner postion of the
ball.
- Class App
- The Constructor should
create the components and set them up, especially the objects in the
has-a relationship. Create the timer and start it.
- actionPerformed should respond to the new game and the Quit button
- the new game button can be ignored for now
- use System.exit(0) for the behavior of the quit button
- Class GamePanel
- Constructor should implement the has-a relationship and do any other setup
- actionPerformed should cause the panel to repaint itself.
- paintComponent over rides the parent class version. You should do the drawing of the ball in this method.
Extra Credit Available
For extra credit, make the color of
the ball change once each second. You may make this a slow progression
through the colors, or a random color each second. 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
Extra Requirements:
You must satisfy the following usual constraints on your program
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?
-
Directions on running and using
your program. Especially anything that might not be the same for all
students. (example: how will you query user input for the type of
game and the number of bets?)
-
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 two labs.