CSCI 1321 (Principles of Algorithm Design II), Spring 2010:
Homework 2

Credit

Design 20 points; code 40 points.

Overview

In this assignment you will begin to construct your game following the description that you handed in for the last assignment. You will do this by creating several new classes and interfaces. What classes you create will depend on the design of your particular game. What you will be constructing now is the beginning of the ``playing field'' -- the background on which the game is played. To do this, you will write what may seem like a lot of classes, but some of them can be very short, and for others you will have access to source code for the equivalent classes in Dr. Lewis's starter game.

Before reading further, review the Project Description, particularly the section ``The game framework''.

Design

The design for this assignment will include descriptions of all the classes and interfaces you will write (for this assignment) and their methods. As in the previous assignment, you will write these descriptions in the form of comments for the classes you need; they will then appear in the HTML documentation generated by Eclipse (or with the javadoc command). As before, what you turn in does not set in stone the code you write for this assignment or later assignments, but you should try to at least plan fairly carefully what you will do for this assignment.

Step-by-step instructions

Code

For this assignment, you have to write a number of classes, described in the next section (``Classes for this assignment''). This section describes the overall procedure.

Step-by-step instructions

Classes for this assignment

(Read, or at least skim, all of this section before starting your design.)

Interfaces

As you may have noticed from browsing the API for the game framework, many classes and interfaces are generics defined in terms of two basic types, one that extends Block and one that extends GameEntity. These two interfaces are themselves generics defined in terms of Block and GameEntity, and if this sounds to you like infinite recursion -- yes, but this can be avoided by you writing your own class or interface for each of these basic types. I'll call these YourBlock and YourEntity here, but you should give them names related to your game (e.g., PacManBlock and PacManEntity). You will then use these types everywhere the framework wants types that extend Block or GameEntity. YourBlock, and all of your game entity classes will be For example: In Homework 1 you had a MainFrame<BasicBlock,BasicEntity>. In this assignment you will replace that with a MainFrame<YourBlock,YourEntity>.

Once you have definitions for YourBlock and YourEntity, for this assignment you will write several additional classes, described below. (This is not as overwhelming as it might sound; for most of these classes you have starter code that you just need to modify.) These classes will replace corresponding starter-code classes (e.g., your class implement GameSetup will replace BasicGameSetup), which means you will need to make other changes (e.g., in your main method that you wrote for Homework 1).

Classes for which you get starter code

Here are the classes you will write by modifying starter code (linked from this page, at the bottom):

Screen class

You only need to write one class from scratch for this assignment, and that is your ``screen class'', which will implement the framework's Screen interface. (You could call it, e.g., PacManScreen.) This interface includes a number of methods, but code for most of them will be very short. To find out what methods you need in this class and what they are supposed to do, look at the project API for the Screen interface. (See below for some thoughts about a sensible order for implementing the methods.) At this point not all the methods will make sense to you; for those that don't (and the documentation should give you some hints about which ones these are), just write skeleton/stub versions, with comments that indicates you'll fill them in later. If one of these methods is supposed to return something, have it return 0 or null for now. It's up to you to decide what variables your class will need, but you will almost certainly need a two-dimensional array of blocks (i.e., a two-dimensional array of YourBlocks) and a list of game entities. For the list of game entities, for now you should use the GameEntityList class in the framework. (Later you will write your own replacement for this class.) GameEntityList is described in the project API and included in this assignment's JAR file.

For initial testing, you should write your game setup class so that it directly creates a screen and fills it with blocks. Once you're reasonably confident that your screen and block classes are working, you may want to use Dr. Lewis's screen editor (see ``Links and files'' below) to actually build screens for your game. This is a nice visual tool that allows you to build screens using your block classes and save them in a binary format that can be read into your game in the constructor of your game setup class. There is commented-out code in the starter version of this class that you can use as a model for doing this. Warning: Do not put too much effort at this point into creating elaborate screens using the screen editor; almost any change you later make to your screen or block classes will make it necessary to start over (because the saved binary-format representation will no longer be valid -- later in the semester we'll talk about why). However, do try out the screen editor, to make sure the parts of your screen and block classes that interact with it are working right.

The methods you need fall into several groups, and you might want to implement them group by group in order:

Files and links



Berna Massingill
2010-03-30