CODING ACADEMY
Code your own Python text adventure
Nate Drake guides you through creating your own interactive text adventure with the power of Python, starting with the basics…
Text adventure
ACADEMY
MUCredit: https://codewith.mu
Part One!
Don’t miss next issue, subscribe on page 16!
OUR EXPERT
Nate Drake wants to dedicate this series to his dad, who once told him that no one was ever going to pay him to sit around and play video games.
To download all the code samples for part one of this series, open a terminal and install Git via sudo apt-get install git . Next run git clone https:// github.com/ azuregate/ lxfpython textadventure. git . The files download to the ‘lxfpython adventure’ folder in your home directory.
T hose of us old enough to remember the ’70s and early ’80s know that games were graphically very uninspiring then. Not to mention the fact that personal computers were still prohibitively expensive.
In 1975, MIT student William Crowther took some time out of his busy schedule developing ARPANET to create a text adventure game he could play with his kids. Although it wasn’t the first of its kind (that honour belongs to 1973’s Hunt the Wumpus), Colossal Cave Adventure quickly spread over the early internet after heavy modifications. The basic premise was the same as any text adventure, in that you entered commands, such as the cardinal points of the compass (N, S, E and W), to move between areas, and interact with items, traps and monsters in a bid to win through to the end with maximum points.
Younger readers may find it difficult to believe that people actually still do this for fun. In fact, IF (interactive fiction) has never been more popular. The annual XYZZY Awards even offer prizes to those who code the very best text adventure games.
In this four-part series, we plan to take you through the basic steps of creating your own text adventure game using the Python 3 programming language. The good news is that since it’s text-based, you won’t need a degree in Photoshop wizardry. It’s also a great programming project for getting started with Python, as well as developing clean coding practices.
If you’re a Linux user, there’s more good news, because support for Python 3 is almost certainly already built into your distro. You can just type python3 via the terminal to get started.
Still, this isn’t the easiest way to code and run Python scripts, so we’ve used the Mu Pytho interpreter instead. It’s available in the Ubuntu software centre and it offers a quick and easy way to run scripts. Mu’s also available for the Raspberry Pi.