Introduction: Making a Text Adventure in Python
I made a Python Text Adventure. Here's how you can too.
Supplies
- Visual Studio Code or a text editor
- Linux
- Python
- Google Account
Step 1: Creating the Map
- Start off by going to drawings.google.com.
- Now, use the Shape tool to create a building or wherever you want it to be. Add the rooms and label them.
- Save your drawing and keep it available
Step 2: Creating the Python File
- Open your text editor. In this case, mine is Visual Studio Code.
- Click "New File" and press "Select a language".
- Scroll down until you get to "Python". Click on that.
- 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.


