CSCI 1321 (Principles of Algorithm Design II), Fall 2005:
Homework 6
Design 20 points; code 40 points.
At this point your game should be fairly close to being playable;
most of the logic for making things move around and interact should
be in place.
In this homework, you will add GUI-related features to your game.
Not all games will need similar functionality, but I want you to add
features to meet the following two requirements.
First, you need something that displays information that changes as
the game runs. Most people will do this by adding a ``game status
panel'' to the game. (If this won't work for you, come talk to me.)
You add a game status panel by having
getGameStatusPanel in your player class return something
other than null for at least one value of the input variable.
Second, you need something that interacts with
a human user, either the person playing the game or the person
developing it, in some way other than by using the keyboard and mouse
listeners in your player class.
You have several options here; choose at least one that makes sense
for your game:
- Add an ``edit properties'' panel to at least one of
your game entity, block, or screen classes.
These panels
are accessed by the screen editor when you select one of the
``Properties'' choices from the ``Edit Left'' or ``Edit Right''
menu. You can use these panels to edit anything about your
classes that should be different for different instances --
the speed of an enemy, for example.
You add an ``edit properties'' panel to a class by having its
editPropertiesPanel return something other than null.
- Add a game status panel that gets and processes input
from the person playing the game.
For example, you could
have a button or text box that allows the user to change how
fast the player moves, or how smart the enemies are.
You do this as described above. Notice that after getting
input from a game status panel you need to restore focus to
the main game panel. Details on request.
- Add items to the game's menu bar or to the ``File''
menu that when selected do something that requires additional
user input. For example, you could have a menu item that
pops up a dialog box that asks how fast the player should move.
You do this by adding to the code in your game setup class
that defines the existing menu bar.
The design for this assignment will include descriptions of any
new classes you will write (maybe none) and revised descriptions of
classes you modify.
This assignment is about having you write GUIs. The
most important
part of it is for you to write code that creates game status
panels for your player to return. Note that your player can
return four separate panels, but you only have to use one. This
panel should display relevant information about the game in some
reasonably appealing format.
The framework calls your getGameStatusPanel four times
with different values of the input parameter (north, south,
east, and west). Your code should compare this input
parameter to the four constants (NORTH_PANEL, etc.)
and return null if you don't want to add a status panel
in that direction and a Container (usually a JPanel
is a good choice) if you do.
In addition to building and returning the panel in
getGameStatusPanel, you need to write
code that will update the panel depending on what happens in the
game. So if you display a score, it needs to be changed when the
player does something that increases the score. The same is true
for any other pieces of information that you display that are
altered during the course of the game.
In addition to the game status panel, you need to make something
that takes
input from the user and makes some change based on it.
As described earlier, you have several choices.
- Add an ``edit properties'' panel to at least one of
your game entity, block, or screen classes.
You do this by having its
editPropertiesPanel return something other than null.
Usually a JPanel is a good choice. It can contain
buttons, text fields, or whatever you need to get the
input you want.
- Add something to a game status panel that gets and processes input
from the person playing the game.
Again you could use buttons, text fields, etc.
Notice that after getting
input from a game status panel you need to restore focus to
the main game panel. Details on request.
- Add items to the game's menu bar or to the ``File''
menu that when selected do something that requires additional
user input.
You do this by adding to the code in your game setup class
that defines the existing menu bar. The existing code should
give you an idea of how this works, or check the Java library
API.
To help you debug, in the class in which you write one of these
panels you can define a main method that creates a
JFrame, adds your panel to it, and displays it.
The Java GUI libraries are quite extensive, and we only had
time in class to cover a few basic classes.
The Java library API at Sun's Web site covers everything,
though, and many classes point to tutorials that can be very
helpful. There are also several GUI examples linked from the
``Sample programs'' page.
- In the project you created in the design phase,
fill in code for the classes you created or revised
in the design phase to make them behave as you described.
You can also continue to fill in things
you haven't done in previous steps -- additional types of
blocks and entities, interactions among game elements, etc.
- Revise and debug until you're happy with how your code
compiles and executes.
- Generate HTML documentation for your project as described
in the
Project Description.
Check that the generated documentation is okay;
point a browser at
http://www.cs.trinity.edu/~yourusername/CSCI1321/HW6/Final
and check that all your classes and documentation comments show up.
- Turn in your code by sending me mail with all of the files I
need to compile and run your game as attachments. This
includes all (.java files), any file(s) created
using the screen editor, and any file(s) containing images.
All of these files will probably be in the same directory
containing your Eclipse project (same name as the project,
in your Eclipse workspace directory), unless you put them
somewhere else.
You don't need to send me .class files or the JAR file,
but if it's simplest for you just to send me all the files
in the directory for your Eclipse project, do that.
It's better to send a bit too much than not enough!
The project description
now contains notes on how to easily send me your whole
project (use tar to create a single file and send
that); it's at the end of the ``Code'' subsection.
Please use a subject line such as ``csci 1321 code 6''.
- The JAR file for this assignment,
PAD2F05Assn6.jar.
(This JAR file is essentially the same as the one for
Homework 5, included again here for completeness.)
- Project Description.
- Project API (Lewis game framework).
- Java library API.
- Help for Dr. Lewis's
screen editor
program.
Instructions for starting the program can be found
under ``Project tools'' near the end of the
Project Description.
- Help for Dr. Lewis's
image editor
program.
Instructions for starting the program can be found
under ``Project tools'' near the end of the
Project Description.
This is a nice program for creating images for your blocks
and entities,
but if you have another favorite tool, you can probably use
that. Ask me for details about loading images from files.
Berna Massingill
2005-11-17