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

Credit

Design 20 points; code 40 points.

Overview

In this assignment you will continue working on the moving parts of your game, in particular the entities other than your player. You don't have to finish writing them for this assignment, but as before the more you do now the less you will have left to do at the end of the semester. You will also write a replacement for the ListBasedPriorityQueue class in the framework. This class should implement the PriorityQueue interface. (Later in the semester you will write a different implementation of a priority queue and compare the performance of the two implementations.)

Design

The design for this assignment will include descriptions of the classes you will write or modify (one for each kind of non-player game entity, plus the replacement for ListBasedPriorityQueue) and their methods. As before, for the design step you can write skeleton or stub versions of the new classes. 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. As your project gets bigger and more complex, the comments describing classes will become more important, since they help human readers of your code understand how everything fits together.

Step-by-step instructions

Code

For this assignment, you have to write or modify 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

For this assignment the coding job consists of two main pieces -- writing or modifying game-entity classes and possibly modifying your player class, and writing your PriorityQueue class.

Changes to game entity and player classes

One part of this homework is implementing at least one of your moving entities. To make an entity move, you need to fill in its getUpdateTime and update methods. getUpdateTime can be similar to what you wrote for your player (though perhaps asking to be updated less frequently). update should make the entity move in some way that's right for your game -- chasing the player, moving randomly, etc. You also need to write code that will handle interactions between your player and the moving game entities. For moving entities, this code can go in either the entity's or the player's update method. Choose whichever seems more reasonable to you, but be sure to take into account how often the different kinds of entities are being updated. Remember also that an entity that no longer wants to be updated can indicate this by returning -1 from getUpdateTime.

Homework 4 describes how to add entities to your game. Since the entities for this assignment move, you need to be sure they get put on the game's priority queue. This will happen automatically if you create the initial configuration with the screen editor. Otherwise, or for entities that are created during execution of the game, you can add them to the priority queue using methods in your game setup class.

Priority queue class

The other part of this homework is to write a replacement for the ListBasedPriorityQueue class. Like the existing class, your class needs to implement the PriorityQueue interface; look in the project API for this interface to find out what methods you need.

Implement this class using a linked list, as discussed in class. Probably the best approach is to maintain the list in sorted order, sorted by what's returned from getUpdateTime. Do not use any of the data-structure classes from the java.util package -- they would make the job simpler, and in Java programs you write in the future you should consider using them, but one of the objectives of this assignment is write your own.

Like the game entity list, this class can be a generic class, as the provided ListBasedPriorityQueue is, but it does not have to be. All the things you will store in the queue implement your general entity interface, so you can write the list to store only objects of this type.

This class could even include a main method to do some simple testing -- create a queue, fill it with instances of one or more of your entity types, etc. This isn't strictly necessary, but it's good practice and may help you debug your code. To do this, you will probably need a DummyEntity class that allows you to test. (For example, this class could be written so that each instance has a ``next update time'' that is always returned from getUpdateTime. You could then create several instances with different times and use them to test your queue.)

Files and links



Berna Massingill
2010-03-30