CSC 120 Programming Assignment 6

Note: You should not work on this assignment during lecture or lab class-time unless:
  1. You have completed all of the in-class assigned work for the day, and
  2. You have permission from the instructor.

This assignment must be submitted to the PA6 D2L dropbox before the beginning of class on the due date.

Overview:

Write a Java Application program that declares, instantiates and uses an array of objects. In addition to the MUFrame.java and MUPanel.java files, your program must include at least two additional class definitions:

Instructions:

  1. Create an application called PA6. It should contain two classes named MUFrame and MUPanel.  Start with the three files in the MUFrame with GUI designer .zip file available on the Student Resources page of the course web site.

  2. The “obstacle” class should have a constructor that determines the position of the object randomly, or with a formula.  That way, the obstacle objects in the array can be instantiated with a loop, instead of individually.  For example, if you want to have 100 obstacles in your program, you can write a loop that is three lines long and is executed 100 times, instead of writing 100 separate instantiation statements.

  3. The program must have buttons that will be used to move the “hero” object around the graphical output window.  Use the designer to position the buttons outside the drawing panel of your application.

  4. Instantiate one “hero” object and an array of “obstacle” objects in the constructor method of the MUPanel.java file.

  5. There must be a goal that the user is attempting to attain.  The goal can either be an area of the screen that the “hero” is attempting to reach while avoiding the obstacles, one special obstacle that the “hero” will try to "capture" while avoiding all the OTHER obstacles, or somehow avoiding or capturing all the obstacles before something happens (the obstacles reach a certain point on the screen, a maximum number of button clicks has occurred, or a timer runs out).  See the examples below for some ideas -- let your imagination guide you, and have fun!

  6. The program must be able to detect when the “hero” has reached the goal, and display a message on screen when the goal is reached -- something like "You win!"

  7. When a button is clicked, the “hero” must move on screen appropriately.  Also, when any button is clicked, ALL of the obstacles must move somehow (either all the same way, or a randomly determined amount or direction).  Once again, see the examples to understand this feature.

  8. IMPORTANT:  The “hero” class must include a method that is capable of detecting when the “hero” ’s bounding box or drawing area has overlapped (or in other words, is touching) an obstacle.  This method should accept one parameter, which is an “obstacle” object, and returns a Boolean value.  If any part of the bounding rectangle for the obstacle object is within the bounding rectangle of the “hero” object, return true; else, return false.  This method will be called from the MUPanel.java file when the button is clicked -- after the “hero” and all obstacles have been moved, write a loop that will test each element in the array of obstacles to see if that obstacle has collided with the “hero”.

  9. Don't forget your comment header for MUPanel, and put a comment header in each of the “hero” and “obstacle” class files.

  10. As usual, make a .zip file from the entire PA6 folder from your H:\CSC120\Java space and submit it to the PA6 Dropbox in D2L before the due date.

Note: It is expected that each student will complete this assignment INDIVIDUALLY.

Examples (some of these include enhancements over and above the basic requirements):

Ideas for Enhancement of the Basic Requirements:

Use your creativity to enhance the basic requirements shown above.  You don't have to do this, but it might make your work more interesting for you.  Here are some suggestions for enhancing your project (you are not limited to this list - try things out!): There are many more fun things you could include in this project.  Enjoy!

Grading Rubric:

CSC 120, PA6, your name, date & Description comments in MUPanel.java. 3
The Description comment must include a discussion of the goal of the program; what is the “hero” object attempting to accomplish?  Should the “hero” be moved to a certain screen area, attempt to "capture" all of the obstacles, or what? 3
Project contains a “hero” class and one “hero” object that is drawn on screen and may be moved by button clicks or other GUI actions. 6
Project contains an “obstacle” class and an array of “obstacle” objects that are drawn on screen and have a different appearance from the “hero” object. 6
“hero” object moves correctly according to labels on the buttons. 7
all “obstacles” move, grow and/or shrink when every button controlling the “hero” is clicked. 8
Program detects when “hero” is overlapping any “obstacle” object and responds appropriately. 5
If “hero” reaches the goal, a message to that effect is displayed on screen. 4
Your code is easy to read, and indented consistently. 3
Total 45