I was making a text adventure game. I don’t know whats wrong with my code. Could someone help?
My code
player = input("Name: ")
Help = "NO CAPS l=look n=north s=south e=east w=west u=up d=down ew=eastwest take (item) l (item) use (item) r=restart"
inventory = ['lamp']
sect1 = ["l", "n", "s", "l door"]
sect2 = ["l", "e", "s", "l shelf"]
sect3 = ["l", "n", "s", "e", "w", "l shovel", "l flowers", "l gate", "take shovel"]
sect4 = ['l', 'w', 'n', 'e', 'sw', 'se']
sect5 = ['l', 's', 'nw', 'l shelf', 'l sofa', 'l TV', 'l TV stand', 'l table', 'l under table', 'l chairs', 'l cup', 'drink tea', 'take key', 'take remote']
sect7 = ['l', 'e']
sect8 = ['l', 'n']
sect9 = ['l', 'n']
sect10 = ['l', 'w', 'n']
dead = ['']
dis1 = "There is an door facing your north, behind you is an small garden"
dis2 = "Fortunately the door isn't locked, you opened it. You are in a doorway. Facing north is a shelf, go south if you want to exit this building, to your east is the hallway."
dis3 = "You are in a small garden, you can see some flowers and a sign beside saying NO PICKING FLOWERS. There is a shovel beside you. You can go north. Continue south out of the wooden gate to the sidewalk, east to proceed further into the garden. You can go west."
dis4 = "Your are in a hallway. There are two rooms in your se and sw, go east to the kitchen, west to the door way. Your north is the living room. "
dis5 = 'You are in the living room. there is a shelf and sofa behind you, on the opposite side of the sofa is the TV, there are some chair beside a table to your right. The bathroom is to your northwest.'
disdead = "Press enter to continue. "
Csect = sect1
def isect1():
Csect = sect1
print(dis1)
while Csect == sect1:
Ans = input("/")
if Ans == "help":
print(Help)
if Ans == "r":
Csect = dead
elif Ans == "inventory":
print(inventory)
elif Ans in sect1:
if Ans in ("l", "look"):
print(dis1)
elif Ans == "n":
Csect = sect2
continue
elif Ans == 'l door':
print("it's just a ordinary wooden door. There is nothing special about it.")
else:
Csect = sect3
continue
else:
print("Sorry, I don't recognize this command.")
def isect2():
Csect = sect2
print(dis2)
while Csect == sect2:
Ans = input("/")
if Ans == "help":
print(Help)
elif Ans == "inventory":
print(inventory)
if Ans == "r":
Csect = dead
elif Ans in sect2:
if Ans in ("l", "look"):
print(dis2)
elif Ans == "w":
Csect = sect4
continue
elif Ans == "l shelf":
print("You are facing the back of a wooden shelf. There is nothing special about it.")
else:
Csect = sect1
continue
else:
print("Sorry, I don't recognize this command.")
pass
def isect3():
Csect = sect3
print(dis3)
while Csect == sect3:
Ans = input("/")
if Ans == "help":
print(Help)
elif Ans == "inventory":
print(inventory)
elif Ans == "r":
Csect = dead
elif Ans in sect3:
if Ans in ("l", "look"):
print(dis3)
elif Ans == "n":
Csect = sect1
continue
elif Ans == "s":
Csect = "STREETS"
continue
elif Ans == "e":
Csect = sect10
continue
elif Ans == "l shovel":
print("Nothing special about it.")
elif Ans == "l flowers":
print("Nothing special about it.")
elif Ans == "l gate":
print("Nothing special about it.")
elif Ans == "take shovel" and "shovel" not in inventory:
inventory.append("shovel")
print("taken")
else:
Csect = dead
continue
else:
print("Sorry, I don't recognize this command.")
pass
def isect4():
Csect = sect4
print(dis4)
while Csect == sect4:
Ans = input("/")
if Ans == "help":
print(Help)
elif Ans == "inventory":
print(inventory)
if Ans == "r":
Csect = dead
elif Ans in sect4:
if Ans in ("l", "look"):
print(dis4)
elif Ans == "e":
Csect = sect2
continue
elif Ans == "n":
Csect = sect5
continue
elif Ans == "se":
Csect = sect9
continue
elif Ans == 'w':
Csect = sect7
continue
else:
Csect = sect8
continue
else:
print("Sorry, I don't recognize this command.")
pass
print("Hello "+player+"!")
print(" ")
print("Welcome to the land of Adventures!")
print(" ")
print("Type Help if you are stuck.")
print(" ")
print("-Front Porch-")
print('')
while Csect != dead:
if Csect == sect1:
isect1()
elif Csect == sect2:
isect2()
elif Csect == sect3:
isect3()
elif Csect == sect4:
isect4()
This is what happens when I run it:
Name: Python
Hello Python!
Welcome to the land of Adventures!
Type Help if you are stuck.
-Front Porch-
There is an door facing your north, behind you is an small garden
/n
There is an door facing your north, behind you is an small garden
/n
There is an door facing your north, behind you is an small garden
/s
There is an door facing your north, behind you is an small garden
/s
There is an door facing your north, behind you is an small garden
/
Thanks!