Introduction: Making a Text Adventure in Python

I made a Python Text Adventure. Here's how you can too.

Supplies

  1. Visual Studio Code or a text editor
  2. Linux
  3. Python
  4. Google Account

Step 1: Creating the Map

  1. Start off by going to drawings.google.com.
  2. Now, use the Shape tool to create a building or wherever you want it to be. Add the rooms and label them.
  3. Save your drawing and keep it available

Step 2: Creating the Python File

  1. Open your text editor. In this case, mine is Visual Studio Code.
  2. Click "New File" and press "Select a language".
  3. Scroll down until you get to "Python". Click on that.
  4. Now, you'll want to press Ctrl+S (Cmd+S on Mac) and name the file whatever you want. In this case, I used TextAdventure.py

Step 3: Beginning the Code

Start by adding something like:

def start()

Now, you want to add a description of where they are:

print("Outside mansion\nYou are in front of a huge mansion with 10-foot-tall double doors to your north. To your East, a pathway leads into the forest, holding many secrets.")

Perfect. Now that we have shown them where they are, add the user input.

answer=input("You: ")

Now that we've done that, we can add what happens if they say north or east.

if answer == "n" or answer=="north":
inside()
elif answer == "east" or answer=="e":
forest()
else:
fail()
start()

We are now left with:

def start():
print("Outside mansion\nYou are in front of a huge mansion with 10-foot-tall double doors to your north. To your East, a pathway leads into the forest, holding many secrets.")
answer=input("You: ")
if answer == "n" or answer=="north":
inside()
elif answer == "east" or answer=="e":
forest()
else:
fail()
start()

Step 4: Adding More Code

Right now, the code won't work since we haven't defined inside() or forest() or (fail). Define those, and complete the game. It should have an ending.

Step 5: Finishing Off the Code

To end it, outside all def()'s, add:

start()

or whatever your starting def() is. When the game is started, it will run itself if coded correctly.

Hit "Ctrl+S" or "Cmd+S" and run the Python file.

Congrats! You've just made a Python Text Adventure!

Check out my Text Adventure down below.