CS 204: Software Design

You may work with a partner for this assignment.

Animation with Java and inheritance

The purpose of this project is to get you warmed up on GUI programming in Java, and to start you thinking about program structures that make use of polymorphism and inheritance.

Run-time behavior

Your program will start with a class named Animation.java, which will have the main method that launches the program. You'll run your program via a command line like this:

java Animation sprites.txt 500 300

where sprites.txt contains a textual description of the various objects (sprites) that will be moving around in your animation, and 500 and 300 are examples of the animation window width and height, in pixels.

When you run this program, some sort of animation will take place. Spaceships in space, butterflies in a meadow, cars in a city, zombies in the park, or whatever strikes your fancy. The keys to this program will be the use of Java and adherence to the structure described in the next section, so the particulars of your animation don't matter a great deal.

I have provided a simple bouncing ball example in Animation.java, AnimationPanel.java, and Ball.java. I have also created a short sample FileScanner.java showing how to read a text file one line at a time and parse each line for structured information. Feel free to borrow any of this code for your program.

Program structure

Your program should model itself after the Animation/AnimationPanel/Ball program. Here's what I recommend. (If you have a better architecture, go for it, but I do want to see a top-level Sprite class plus at least two subclasses of Sprite.)

Sprite file format

The sprite file will consist of lines of text, one per sprite, of this format:

type x y vx vy [other info required by the sprite type]

For example:

goat 200 100 10 0 purple

would, presumably, cause the instantiation of an object of type Goat with initial position (200, 100) and initial velocity (10, 0) and initial color purple.

You are free to add features to your particular sprite types, making corresponding additions to the "other info" section of the sprite description line in the sprites file.