Lecture notes for the Introduction to Computer Science for non-majors by James Tam Return to the course web page

CPSC 217: Assignment 7 (Worth 8%)

New concepts to be applied for the assignment

  1. Complex program design1
  2. Problem solving a non-trivial problem1
  3. 2D lists

 

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 list:

 
 

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 grid will contain spaces.

In the course directory there is a partial source code program that provides the starting positions for all the characters in the list. While you are not strictly required to use this program for your assignment, the starting points MUST be the same as the one in the program in the course directory.

The goal of the game is to bring Homer from Alaska (top portion of the grid) 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 (you will also be graded on other criteria such as coding style and providing program documentation as listed in the marking key):

 
  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. (The option for entering the debugging mode (point #8) should not be shown in the movement menu because it's supposed to be a hidden function).
 
  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 code that actually 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 'debug' flag. The exact content of these debugging messages (e.g., showing function 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. 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., 'displayFunctionCalls', 'displayVariableContents') each of which will each only display a particular category of debugging message. (For example if displayFunctionCalls was set to 'true' and displayVariableContents was set to 'false', the game would show a message each time that a function 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 it will actually help you in the development process. 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 grid - 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 grid 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).

 

Resources available

In the course directory under the path: /home/courses/217/assignments/assignment7 you will find an executable program called "simpsons". Similar to the executable for the previous assignment you can run (execute) it by typing "./simpsons" at the command line but it cannot be viewed or copied.

 

Submission requirements

In addition to having 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 so that your marker knows whose assignment that he or she is marking.  Also your README should also list which features of the assignment that you completed (in the case of this assignment which functions did you actually implement).

 
  1. The programming assignments require a two part submission: a) A paper submission of your README file and Python program into the assignment drop boxes (second floor Math Sciences) b) An electronic submission (again of your README file and your Python program) as an email attachment (don't cut and paste it into the email body!) to the following people (failing to include everyone listed below may result in your assignment not being marked for credit so before submitting your assignment double check!) Make sure that the subject line of the email contains the exact text (don't add or delete anything to it or you will lose marks): CPSC 217 Assignment X.

X = The appropriate assignment number (e.g., for Assignment 3 the subject would be titled "CPSC 217 Assignment 3")

 
  1. The course instructor at the following email address: tamj@cpsc.ucalgary.ca
 
  1. Your tutorial instructor, the email addresses for the TA's can be found on the main course web page.
 
  1. The TA coordinating the marking of assignments: amaobied@ucalgary.ca (if you are in Ahmed's tutorial you don't have to send your assignment to him twice, other students must send their assignment both to their TA and to Ahmed).
 
  1. Yourself. Sending the assignment to yourself provides one last "double check" that you submitted your assignment properly (e.g., you sent it to all the right people, you attached all the important files to the submission etc.) When you receive the submitted assignment you can check one last time to make sure that you fulfilled all the requirements. If you forgot something then you can resend your assignment with a note to mark only the latest submission (but try not to resubmit your assignment too many times please).
 
  1. 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.
 
  1. For this assignment you must include a structure chart that outlines the functions that will be implemented in your program as well as the hierarchy of function calls (which function calls which). You can work on the structure charts on your own time and during the second tutorials (either Wednesday or Thursday of the week of April 7 - 11) you will get some feedback about the direction of the design of your program. If students hand in their structure charts after this tutorial (e.g., you hand it in with your paper print outs when you submit your assignment) then you can still get a grade for this component although you obviously won't receive timely feedback to help you with your work. If you are unsure of what a structure chart looks like you can refer to the slides and your in-class notes on problem decomposition / modular design.
To help make sure that you haven't missed anything here is a checklist of items to be used in marking.

1 From the view of a student who is new to programming the design and problem solving issues faced in this assignment are non-trivial. It's worth noting that compared to an actual commercial system that this software is still quite small.