CSCI 1321 (Principles of Algorithm Design II), Fall 2007:
Homework 6

Credit

Design 20 points; code 40 points.

Overview

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:

Design

The design for this assignment will include descriptions of any new classes you will write (maybe none) and revised descriptions of classes you modify.

Step-by-step instructions

Code

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.

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.

Step-by-step instructions

Files and links



Berna Massingill
2008-01-17