Ask coding questions

← Back to all posts
How do you make a text adventure game in python
rperm (1)

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

Comments
hotnewtop
InvisibleOne (2677)

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.

Bookie0 (5956)

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/

PattanAhmed (1397)

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

Hope this helps