Skip to content
← Back to Community
How do you make a text adventure game in python
Profile icon
rperm

I’ve been trying to learn how to make a text adventure game in Python but none works.

Voters
Profile icon
RonanBIZZELL
Profile icon
ChrysalHyno
Profile icon
MZdabeast
Profile icon
SandwichBlamwich
Profile icon
AbrilRosinski
Profile icon
rperm
Comments
hotnewtop
Profile icon
InvisibleOne

It's pretty simple, just create a story, and at each important point in the story, give the player a two options. If they pick the wrong option, they die, or something like that. Here's a simple one:

#get the player's name name = input("Name: ") print("Hello " + name) print("You are on an adventure, what do you want to do?") print("[1] Hunt a dragon [2] Jump in a hole filled with spikes") #then get the player's choice choice = input() #check to see what the player chose to do if choice == '1': print("You attack a dragon and killed it") #Now give them another choice to keep the story going print("[1] Jump in a hole filled with spikes [1] Hunt another dragon") choice2 = input() if choice2 == '1': print("You died...") elif choice2 == '2': print("You hunted a dragon and won!") #Then you continue on elif choice == '2': #This is the result of them choosing to jump into the hole the first time print("You died...")

You can make the story as complicated or uncomplicated as you like, but have fun with it.

Profile icon
SandwichBlamwich

@InvisibleOne
I can only do two choices, choice3 does not work?
I am new to python :p

Profile icon
InvisibleOne

It should just be another elif

print("[1] Do something") print("[2] Say Hi") print("[3] Leave") choice = input("=> ") if choice == '1': print("doing something...") elif choice == '2': print("Hi!") elif choice == '3': exit()

@SandwichBlamwich

Profile icon
SandwichBlamwich

@InvisibleOne no i mean in "if choice3 == '2':"
does not work (without the "")

Profile icon
InvisibleOne

Hmm... Could I see the code in context? @SandwichBlamwich

Profile icon
SandwichBlamwich

@InvisibleOne this is a snippet, i have the choice3 = input(), just i did not copy it.
'''
if choice3 == '1':
print("it was a trap! as you pick up the bottle, placing coins on the table, the shopkeeper pounces and takes you away!")
print("the end...")
elif choice3 == '2':
print("you pass through and continue on. ")
print("it starts to get dark...")
print("[1] set up camp [2] continue")
choice = input("")
if choice == '1':
print("test")
elif choice == '2':
print("test")
'''

Profile icon
SandwichBlamwich

@InvisibleOne
elif choice3 == '2':
does not work. the if choice3 == '1':
works...

Profile icon
SandwichBlamwich

elif choice3 == '2': is the code that is not working...
if choice3 == '1': works!?

Profile icon
InvisibleOne

I'm not sure what the problem is, unless it is an indentation issue. Here's an example code yours should be something like this: https://replit.com/@InvisibleOne/example#main.py @SandwichBlamwich

Profile icon
Coder100
Profile icon
Bookie0

hi there!

first of all to make a text adventure game, you should choose your plot story. It could be anything, like a mountain trailing hike, or a post apocalyptic society, etc. Then, make some questions.

The 1st question could be like do you want to run away or fight a monster. Then, include a variable to keep track of how brave you are; for brave actions + 1 for coward actions - 1. Here is a list of some questions:

fight/run away
turn light on/dont
save person/leave them to die
share food/dont
share water/dont
go to plains/go to mountain
cross bridge/swim
go inside town/stay in fields
go inside motel/go to barn

and here is a text adventure game i made a while ago:
https://repl.it/talk/share/OBLIVION/37512

also here some resources to help you: http://coding-grace-guide.readthedocs.io/en/latest/guide/lessonplans/beginners-python-text-based-adventure.html

https://letstalkdata.com/2014/08/how-to-write-a-text-adventure-in-python/

https://trinket.io/python/e5a03e7cbc

https://www.derekshidler.com/how-to-create-a-text-based-adventure-and-quiz-game-in-python/

Profile icon
PattanAhmed

@rperm Hi,
Follow up with this video...
It will be really helpful.
Click here
Thanks!

Hope this helps