COMP 310
Fall 2010

HW02:  Inheritance-based Ballworld

Home  Info  Owlspace  Resources

Assignment Instructions

The assignment is to create Ballworld implementation where the ball implementations are sub-classes of an abstract ball.

See the on-line demo of the inheritance-based Ballworld.   You are to replicate all the functionality of the demo, except that you can make your own kind of balls.

Requirements:

  1. Other than than the code for the individual concrete ball subclasses, no code in the rest of the system can reference a ball sub-class.
  2. Balls should bounce correctly off the sides of a panel on the main frame, not the entire frame.   Balls should bounce from their edges, not their middles or only one side.
  3. The application should be able to dynamically load any ball sub-class, given its fully qualified name at run-time (i.e. typed into a text field).
  4. The application should be able to clear out any balls that are already on the screen.
  5. At least 3 different types of ball sub-classes must be implemented which have distinct behaviors.  This can include changing colors, curving around, changing radius, etc.  

Turn-in instructions:  

  1. Add any instructions on how run your program in the comments of your main controller file.
  2. Commit your code.
  3. Tag your latest commit as "HW02".

Recommended Methodology

A structured, planned approach to this assignment will save you a lot of time and head scratching.  It is key to understand what processes are happening where and how information flows from part of the system to the other, in particular, between the model and the view.

Break your work down into pieces where you fully understand each piece BEFORE coding anything!  Work on getting one small piece working at a time before moving to the next part.

Design --> Code --> Test --> Fix Design --> Fix Code --> Retest --> etc.

DO NOT ATTEMPT TO CODE EVERYTHING AT ONCE!

What Processes Take Place in the Model vs in the View?

Building a Controller

Building a GUI

The Variant and Invariant Aspects of a Ball

 

 Understanding Painting and Animation

 

Dynamic Ball Loading

 

Bouncing Balls

Click for full size image
Ball bouncing off a wall

Provided Code

Don't kill yourself trying to re-invent what is given to you.  The following code snippets are provided to you:

 How to turn a ball

To change the direction of a ball without changing its speed, you need to rotate the velocity vector.   This can be easily accomplished by a simple matrix multiplication, which when multiplied out, becomes:

Vx, new = Vx, old cos(θ) - Vy, old sin(θ)

Vy, new = Vy, old cos(θ) + Vx, old sin(θ)

where θ is the counter-clockwise angle of rotation per timer tick.   That is, for a positive angle value above, the ball will turn to the left.    Sine and cosine are static methods of the Math class

Notes:

 

 

Grading Criteria:

  1. Replicating the behavior of the demo:
    1. Overall look: panel with controls plus separate display area -- 5
    2. Ability to type in ball class name - 5
    3. Ability to create the ball of the desired type - 15
    4. Ability to clear the balls - 10
    5. Ability to have multiple balls of multiple types on screen simultaneously - 15
    6. Correct bouncing behavior off edges of display area and edges of balls. - 10
    7. At least 3 different types of balls being made - 15
    8. Discretionary points - 5
  2. No references to concrete ball subclasses in code -- 15
  3. Other programming style and operational issues/discretionary points -- 5

 

 


© 2010 by Stephen Wong and Scott Rixner