Skip to main content

Colossal Cave adventure game at the Python prompt

Project description

This is a faithful port of the “Adventure” game to Python 3 from the original 1977 FORTRAN code by Crowther and Woods (it is driven by the same advent.dat file!) that lets you explore Colossal Cave, where others have found fortunes in treasure and gold, though it is rumored that some who enter are never seen again. To encourage the use of Python 3, the game is designed to be played right at the Python prompt. Single-word commands can be typed by themselves, but two-word commands should be written as a function call (since a two-word command would not be valid Python):

>>> import adventure
>>> adventure.play()
WELCOME TO ADVENTURE!!  WOULD YOU LIKE INSTRUCTIONS?

>>> no
YOU ARE STANDING AT THE END OF A ROAD BEFORE A SMALL BRICK BUILDING.
AROUND YOU IS A FOREST.  A SMALL STREAM FLOWS OUT OF THE BUILDING AND
DOWN A GULLY.

>>> east
YOU ARE INSIDE A BUILDING, A WELL HOUSE FOR A LARGE SPRING.
THERE ARE SOME KEYS ON THE GROUND HERE.
THERE IS A SHINY BRASS LAMP NEARBY.
THERE IS FOOD HERE.
THERE IS A BOTTLE OF WATER HERE.

>>> get(lamp)
OK

>>> leave
YOU'RE AT END OF ROAD AGAIN.

>>> south
YOU ARE IN A VALLEY IN THE FOREST BESIDE A STREAM TUMBLING ALONG A
ROCKY BED.

The original Adventure payed attention to only the first five letters of each command, so a long command like inventory could simply be typed as inven. This package defines a symbol for both versions of every long word, so you can type the long or short version as you please.

You can save your game at any time by calling the save() command with a filename, and then can resume it later at any time:

>>> save('advent.save')
GAME SAVED

>>> adventure.resume('advent.save')
GAME RESTORED
>>> look
SORRY, BUT I AM NOT ALLOWED TO GIVE MORE DETAIL.  I WILL REPEAT THE
LONG DESCRIPTION OF YOUR LOCATION.
YOU ARE IN A VALLEY IN THE FOREST BESIDE A STREAM TUMBLING ALONG A
ROCKY BED.

You can find two complete, working walkthroughs of the game in its tests directory, which you can run using the discover module that comes built-in with Python 3.2:

$ python3.2 -m unittest discover adventure

I wrote most of this package over Christmas vacation 2010, to learn more about the workings of the game that so enthralled me as a child; the project also gave me practice writing Python 3. I still forget the parentheses when writing print() if I am not paying attention.

Notes

  • Several Adventure commands conflict with standard Python built-in functions. The function “exit” is so important that I refused to overwrite it, so you will have to use one of the synonyms “out,” “outside,” or “leave” instead. Similarly, use “unlock” instead of “open.”

  • I use the Python functions “quit” and “help” less often, so I allow the game to replace them with Colossal Cave commands.

  • The word “break” is a Python keyword, so there was no possibility of using it in the game. Instead, use one of the two synonyms defined by the PDP version of Adventure: “shatter” or “smash.”

Changelog

1.0 — 2011 February 15 — 100% test coverage, feature-complete
0.3 — 2011 January 31 — first public release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

adventure-1.0.tar.gz (77.6 kB view details)

Uploaded Source

File details

Details for the file adventure-1.0.tar.gz.

File metadata

  • Download URL: adventure-1.0.tar.gz
  • Upload date:
  • Size: 77.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for adventure-1.0.tar.gz
Algorithm Hash digest
SHA256 f29ef6f5ff8eb1e68b989e83de2fd22217e1206c7579dc044e58ec8b02b4b161
MD5 87efff18b6912f6cc373a561b9a63d7e
BLAKE2b-256 a4e4010e5a17a12eda6d98da3e230f0e954b12c58a9a4eb80c61970e2974c67d

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page