Making a Text Adventure in Python

by thestupidpythonguy in Circuits > Computers

21 Views, 2 Favorites, 0 Comments

Making a Text Adventure in Python

Screenshot 2025-06-22 15.18.34.png

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

Creating the Map

Screenshot 2025-06-21 13.29.59.png
  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

Creating the Python File

Screenshot 2025-06-22 15.07.14.png
  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

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()

Adding More Code

Screenshot 2025-06-22 15.18.34.png

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.

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.

Downloads