Introduction to Computer Science I by James Tam Return to the course web page

CPSC 231: Assignment 7 (Worth 8%)

 

New concepts to be applied for the assignment

  1. Two-dimensional arrays
  2. Solving a moderately challenging problem

 

Writing a simple adventure game:

For this assignment you are to write a text-based adventure game based on 'The Simpsons Movie' © Fox. The game world will be modeled as a two-dimensional character array:

 
 

Character

Value represented

 

H

Homer Simpson (controlled by the player)

 

#

A building (cannot be entered)

 

E

Agents of the EPA (controlled by the computer)

 

~

Water

 

S

The town of Springfield

  The empty parts of the array will contain spaces.

In the course directory there is a partial source code program that provides that starting positions for all the characters in the array. You MUST use this partial program as the starting point for your assignment. The goal of the game is to bring Homer from Alaska (top left portion of the array) back to the town of Springfield (near the bottom right). However if Homer takes too long to travel out of Alaska he freezes and the player loses the game. Also if Homer moves into the water he drowns and the game is lost. Finally the tireless agents of the EPA will try to capture Homer and if they do once again the game is lost. The game will be run on a turn-by-turn basis. A turn elapses when Homer moves (direction 2, 4, 6, 8) stays on the same square (direction 5) or toggles the debugging mode on or off (negative value for the direction). A turn won't pass if the player enters an erroneous value for the movement direction (10 or larger). After Homer moves the EPA agents will move in the fashion described in Point #14 below. The game continues until: 1) The player has lost the game (Homer drowns, freezes or is captured) [Multimedia visualization of the losing the game] 2) The player has won the game [Multimedia visualization of wining the game] 3) The player has quit the game. [Multimedia visualization of Homer quitting]

Features to be implemented
 
  1. Display an introduction each time that the game is run which provides instructions for playing the game.
 
  1. Display a conclusion each time that the game ends. The conclusion must show the player's game status (won, quit, or if lost how the player lost the game).
 
  1. Displays a menu that shows the allowable directions that Homer can be moved which are mapped to the keypad on the keyboard. The menu should show the 4 cardinal compass points (N = 8, W = 4, E = 6, S = 2). It should be indicated in the menu that selecting 0 will allow the player to quit the game.
 
  1. Homer can be moved in the four cardinal compass directions (to get credit for Point #3 your program merely has to display the menu whereas to get credit for this point your program has implemented the part of the menu that makes Homer move).
 
  1. If the player tries to move Homer in one of the inter-cardinal compass directions (NW, NE, SW, SE) an appropriate error message will be displayed and Homer will not move.
 
  1. If the player tries to enter a value larger than 9 for the movement direction another error message will be provided. (Reminder: Time in the game will not elapse in this case - a turn will not pass and the EPA agents will not move - if Feature #14 was implemented).
 
  1. Entering zero for the direction of movement will allow the player to quit the game.
 
  1. Entering a negative number for the direction of movement will toggle debugging messages on and off by using the 'debugOn' flag. The exact content of these debugging messages (e.g., showing module calls, showing the contents of variables at different points in your program) are left to your discretion but as the name implies they should be used to help you debug your program. (Note: the use of this debugging flag as a global variable is probably the sole exception to avoiding the use of global variables for your assignments for this semester). If you find that seeing all debugging messages appearing all at once through a single debugging flag is too overwhelming you can implement multiple debugging flags (e.g., 'displayModuleCalls', 'displayVariableContents') each of which will each only display a particular category of debugging message. (For example if displayModuleCalls was set to 'true' and displayVariableContents was set to 'false', the game would show a message each time that a function or procedure was called but it would not display the contents of variables). If your game has multiple types of debugging messages then entering a negative number will shown a debugging menu which then allows the player to select the specific debugging message to turn on and off. (JT's hint: you should implement this feature early on so you can actually use it to help you debug your program because this is a complex assignment! You shouldn't implement it at the end merely to fulfill the assignment requirements when it's too late to help you fix the errors in your game because that defeats the whole purpose of writing a debugging tool).
 
  1. The game prevents Homer from entering an occupied square (contains a building or an EPA agent).
 
  1. If Homer enters the water, he drowns and the game ends (with an appropriate consolation message for the player).
 
  1. The game adds to an unfocused, easily distracted side to Homer's personality (which is pretty much an actual personality trait of the character Homer Simpson in the movie). Each turn that the player tries to move Homer (direction 2, 4, 6, 8) there is a 25% chance that Homer finds something more interesting at his current location. To get credit for this feature your program should indicate to the player that Homer has become distracted this turn and refuses to move (e.g., "Homer becomes distracted and refuses to move) but it doesn't have to be as elaborate as the sample executable (a random message is displayed). [Multi-media visualization of this event]
 
  1. The game tracks the amount of time that Homer spends in Alaska (top six rows of the array - start counting at the row that consists entirely of water). Homer can only remain in this area for 10 turns before he freezes.  To get credit for this feature, each time that the game shows the array it also displays how long he has been in Alaska and how much time he has left. There is a simple and an enhanced version of this feature (you can only get credit for one version). With either version when his time runs out Homer freezes and the game ends (with a suitable consolation message being displayed).
   
  1. Simple version: If Homer spends a total of 10 turns in Alaska he freezes. Those turns don't have to be successive ones. If Homer leaves and re-enters Alaska the count down for his 'time remaining before he freezes' will continue where it left off.
   
  1. Enhanced version: Homer has to spend a total of 10 successive turns in Alaska before he freezes. If he leaves and re-enters Alaska then the count down will start again at the beginning (he has 10 turns before he freezes).
 
  1. When Homer makes it back to Springfield the game is won and a suitable congratulatory message should be displayed.
 
  1. The agents of the EPA can move (in a purely random fashion). Agents will only move to an empty (contains a space) and adjacent square with a one in nine probability of a particular square being picked (there's eight agent squares plus there's a chance that the agent won't move). (JT's hint: to implement this feature properly you need some way to track the (row/column coordinates of each agent in a fashion somewhat similar to how you tracked Homer's location- except that you now must track 6 pairs of row/column coordinates instead of just one pair. This feature is more challenging than the others so you should leave it to near the end).
 
  1. The game can detect when an EPA agent is in a square that is adjacent to Homer and end the game (with a suitable consolation message being displayed).

 

Submission requirements

In addition to having to fulfill the generic assignment requirements, the requirements specific to this assignment include:

  1. Include a README file in your submission:  For this assignment you need to include a file called 'README' which includes your contact information: your name, university identification number and UNIX login name as well as all the features of the program that you implemented so that your marker knows whose assignment that he or she is marking and what features to look for.

  2. Assignments (source code/'dot-p' file and the README file) must be electronically submitted.  In addition a paper print out of the source code and README must be handed into the assignment drop box (located on the second floor of the Math Sciences building) for the tutorial that you are registered in.  Electronically submitting the assignment allows your marker to compile and run the code in order to quickly determine what features were implemented.  Providing a paper printout makes it easier for your marker to read and flip through your source code to check for things like program style.

  3. As a reminder, you are not allowed to work in groups for this class.   Copying the work of another student will be regarded as academic misconduct (cheating).  For additional details about what is and is not okay for this class please refer to the following link.

To help make sure that you haven't missed anything here is a [checklist] of items to be used in marking. A sample executable 'simpsons' can be found in UNIX under the directory: /home/231/assignments/assignment7. The source code program that you must use can also be found in that directory and is called 'simpsons.p'.