Adventures in the Imaginary Land of Gack

MCS-178: Introduction to Computer Science II

Due November 23, 2009

Objective

In this lab you will use object-oriented programming to extend an adventure game, the Land of Gack. This game is explained in section 14.5 of Concrete Abstractions and we will spend a couple class days discussing the Python version you'll be working with.

Differences in the Python version

I am providing a document that summarizes the classes. In brief, the changes from the book's versions are

In lab

To download and run the game:

  1. Download gack.zip.

  2. Unzip that file, so as to produce a directory called gack.

  3. To run the program, open Game.py in Idle and choose "Run Module" from the Run menu (or press F5).

If at some point you close the game window, you can use the interactive Python prompt to probe more deeply the state of the various objects. (I'll demonstrate this in class.) If you then want to restart the GUI, you can tell Python to play().

The code for the game has been divided into a collection of individual files, most of which which are named for the class they contain. For example, Person.py contains the Person class. There are only four exceptions to this general rule:

Once you have a copy of the game, you are to do exercises 14.33, 14.34, and 14.35. In coming up with ideas for the open-ended exercise 14.35, you may also want to look at exercise 14.42. All four of these exercises are reproduced below with minor editing to suit the current Python context. Be sure in the open-ended exercise to make changes which require all three of the following: some change or addition to the class hierarchy, some additional method, and some additional attribute (instance variable). This is a grading criterion for your project report.

Exercise 14.33: First you'll need to familiarize yourself with the game. Run it as described above. Try to get from the dormitory to the computer lab without getting turned into a frog along the way. To make it more challenging, try to get to the lab possessing the scroll of enlightenment. If you want, you can make the other characters move several times after each move of yours (rather than just once) by using the "Pace" control. Be sure to get familiar with the game's other features too.

Exercise 14.34: Modify the Land of Gack so that there is a new scroll, called "late lab report", in the dormitory. Now you can play the game with a new goal: Pick up the late lab report, go catch up with Max, wherever he may have wandered to, and try to give Max the report even though it's late. You'll need to add some additional mechanisms to the Person class and to the give procedure within Game.py. Verify that at the end the lab report thinks Max is its owner, Max thinks the lab report is one of his possessions, and Gack.player no longer thinks the lab report is one of its possessions.

Exercise 14.35: Of course, you can make the game much more interesting by adding additional twists. Implement some that interest you. We give a list of suggestions below but feel free to come up with some of your own. Be sure to describe in English whatever new ideas you introduce.

Exercise 14.42: When a person says something in the Land of Gack, it is "heard" only by the player, in that whatever is said gets displayed. It would be more interesting if other objects within the Land of Gack itself could also hear--and potentially respond to--what was said. That way you could have characters who behaved differently if you said "please," magic portals that opened when you said "open sesame," etc. Note that this is just a suggestion; you don't need to do this.

  1. Add a method in the Person class called hear that takes two arguments: the person speaking and what was said. The implementation in the Person class should do nothing because ordinary persons ignore what they hear.

  2. Change the Person class's say method so that it invokes the hear method of each other person in the place where the person is speaking.

  3. Now have fun introducing special classes of person that respond to what they hear.

  4. In order for magic portals and the other magical objects to respond to spoken commands, they will need to hear as well. In Concrete Abstraction's version of the Land of Gack, this would be achieved by putting the hear method in a general named-object class, from which the person, place, and thing classes all inherit. However, in the Python version, this superclass was eliminated. Therefore, you have a choice of either independently adding hear to other classes, such as Thing, or reintroducing a NamedObject class after all.

Postlab

Focus your report on the open ended exercise 14.35. The warm-up exercises need not be mentioned in the body of your report. You'll be electronically submitting the code, so you'll only need to include excerpts to illustrate particular points in the project report.

Your audience for this report is a fellow programmer (or team of programmers) who will be extending your game. You can assume the audience knows Python but is not familiar with The Land of Gack. All aspects of your report, including the introduction, should be addressed to this audience. (If there are comments that you wish to make to the grader, you can put those in an appendix.) As always, your report should focus on what the final product is, and not on the assigment. Sentences starting, "We were asked to..." and "The first thing we did in lab is..." should not appear in your project report.

You'll want to briefly describe your game to the audience (with emphasis placed on those parts that differ from the original version.) One thing I'll be looking for is a clear description of your final class hierarchy early in the report. (A diagram helps!) As always, emphasize the final product rather than each incremental change you made. Make sure that your English text provides context for the Python code rather than echoing it; after all, the reader can read Python code.

Suggest one or two specific further improvement(s) to the audience. Clearly explain how components of the program will need to be adapted to incorporate these improvements. I'd rather you explain one suggested improvement in detail than explain several vague ideas. For instance, the programmer may need to

  1. expand the class hierarchy,
  2. adapt the interface,
  3. add new attributes (instance variables), or
  4. change or write new methods.

One way to sketch your idea is to list the attributes any new class would have (along with the type of value each would refer to, if that isn't obvious) and the methods that would be defined. You should specify the arguments and return values for new methods.

Although you need not provide explicit testing information in this report, you are expected to adequately test the code you wrote. If your program has bugs, provide a bug report.

The gradesheet for the project is available in PDF format. (If you print a copy out, you can staple it to the front of your project report to save paper.)

Submitting your code

To submit your code when it's ready, send an email message to max@gustavus.edu with all of the .py files from your project directory as attachments.

Please print out your project report and submit it in class. Your project report should not include all your code.