Due: Wednesday, October 16th, 11:00 AM
Pair programming, with a partner of your choice, so long as your are both in the same lab.
A central characteristic of many video games is that the playing area is divided into a rather course grid of cells and the movable game elements, called sprites, move smoothly in a horizontal or vertical direction between the centers of the grid cells. Frequently the sprites change appearance when they are moving so they appear to be facing in the direction of motion. In many cases when they are in motion there is also some crude form of animation suggesting a sprite activity in addition to their gliding motion, such as walking, eating, blinking, or waving a sword. These characteristics provide enough realism and versatility for satisfying play in many games, while providing enough constraints (such as allowing only horizontal or vertical motion and stopping only at fixed grid positions) to make the game more efficient and much easier to program than it would be without the constraints.
In this assignment you will be programming all of these game elements. The resulting code will be usable with minor modification to build complete games. This assignment's sprite appearance and animation is similar to that of the famous PackMan game. The assignment provides experience with threads (objectdraw ActiveObjects), for and while loops, and optionally, simple use of an array.
Choose your partner and begin work on the following assignment.
Use Netscape to view this applet and others in this course, since Internet Explorer on STD machines, and many home machines, by default does not use Java 1.4. (Or in IE select Tools>Internet Options>Advanced>Java (Sun)>Use Java 2..., exit IE, and start it again. Unfortunately on an STC machine you have to do this every time you log in.)
This assignment is to implement a FrameWindowController class with behavior similar to the above applet. It should have the following properties:
A number of details are left unspecified, such as the number of rows and columns, the color of the sprite, how wide the open mouth is, and so on. You may choose any values for these details as long is it is easy to see that your program has the above functionality.
Here is the CRC design to be used in this assignment:
Class MoveSprite
Responsibilities Draw the grid, creates the sprite, and handles mouse press events.
Collaborators SpriteClass Sprite
Responsibilities Display the sprite (with mouth closed or open in the direction of motion), moves the sprite, animates the sprite motion, and reports whether the sprite is moving.
Collaborators Timer
Class Timer
Responsibilities Call the sprite when a given time interval has expired.
CollaboratorsSprite
For this assignment, use the following contracts (public members):
MoveSpriteTimer
Submit moveSprite.jar in the same way as the last assignment.
Note: As always, you do not have to follow suggestions presented as hints, though if you do something in a significantly more difficult way, that will be considered bad style. On the other hand, if you can figure out a better way, that would be excellent style. Failure to follow design guidelines that are not presented as hints may result in substantial loss of credit. If you think there is a better way of doing those things and want to do it your way, obtain permission first.