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

Credit

Design 20 points; code 40 points.

Overview

In this assignment you will begin to design and implement a class for your ``player'' -- the little character that goes running around on your screen. (If your game doesn't have something fitting that description then you should come to talk to me about what you need to do for this assignment.) For this assignment the player needs to do two things:

You should try to take the design a little further and also think about what will be needed in your player for other aspects of the game (e.g., interacting with other game entities). You probably won't get it completely right at this point, but thinking now about all the functionality you eventually need will probably help you spot potential problems earlier.

Design

The design for this assignment will include a description of the player class you will write and its methods. The comments at the top of the class should describe (1) how your player responds to mouse or keyboard input (e.g., ``my player moves up, down, and sideways when the user presses the arrow keys'') and (2) how your player interacts with your block classes.

To fit into the game framework properly, the class needs to implement two interfaces: the ``general entity type'' (YourEntity) you wrote for the previous assignment, and also the framework's Player interface (parameterized with your block and entity types -- i.e., this class should implement Player<YourBlock,YourEntity>).

As before, for the design step you can just provide skeleton or stub code for the methods. You should also look again at your descriptions of classes you wrote for previous homeworks and see if they need to be improved or updated. Remember that I want at least a short comment about every class and every method. Writing these comments before writing the code encourages you to ``think first, then code''. They also help human readers of your code understand how everything fits together.

Step-by-step instructions

Code

As with the previous homework, for this assignment you will be writing and editing a fair bit of code, but most if not all of it will be in classes you have already written. The class for your player could easily be the largest class in your game. However, you don't have to write all of it now; you just need to make a start on implementing the functionality you want. Over time you will probably also write other private and public methods for your player that help it get things done and allow it to interact with other parts of your game. See the next section (``Classes for this assignment'') for details; this section just summarizes the overall procedure.

Step-by-step instructions

Classes for this assignment

Most if not all of the coding you do for this assignment will consist of filling in methods in your player class. As with the screen class in Homework 2, the methods fall into several groups, and you may find it easiest to implement them group by group in the following order. I suggest doing this in two phases -- one in which you do the minimum needed for the game to run, and one in which you make the player respond to keyboard and/or mouse input.

Phase one

When you have written code for all of the above methods, you should be able to start the game and have it come up without crashing or freezing, though the player will not (yet!) respond to input.

Phase two

The combination of update and listener methods should give you a player class that takes input from the keyboard or mouse and uses it to move around any screens that you have built. The movement should be appropriate for the blocks that are present -- for example, if you have wall blocks or other obstacles, the player should not be able to move through them. In a side-view game the player should also fall if not supported by something, and you might want to implement some way for the user to make the player jump. If you have blocks that are supposed to change when the player moves onto them, you should implement that as well in this homework.

Using the screen editor

This might also be a good time to start using Dr. Lewis's screen editor (links to information on starting and using it below) to lay out screen(s) for your game. (You don't have to, but the alternative is to create the layout with code in the constructor(s) of your screen class, which can get tedious for all but the simplest layouts.) This tool saves the layout you create in a file (name decided by you); commented-out code in BasicGameSetup shows how to then read from this file into your game. I recommend that you not invest a great deal of time right now making elaborate layouts; files you create may become unreadable if you make certain kinds of changes to your classes, so you should save this kind of polishing until later in the semester.

Files and links



Berna Massingill
2010-03-30