CSCI 1321 (Principles of Algorithm Design II), Fall 2007:
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

Like the previous homework, this one will have you writing and editing a fair bit of code. 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, just the beginnings of it. Over time you will probably also wind up writing other private and public methods for your player that help it get things done as well as allow it to interact with other parts of your game. Some of the key things you will write are the following.

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.

As mentioned above, the player's position is represented as a Location (a class in the game framework). Notice that this class is immutable. The value passed to setPartialsInWhole determines whether entities move around in whole-block units or in smaller steps. A value of 1 makes things such as collision detection easier, but a larger value gives you smoother motion. The partialMove method is useful for moving entities around without having to keep track of whether you are about to run off the edge of your screen.

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.

Step-by-step instructions

Files and links



Berna Massingill
2008-09-12