Я борюсь с моим проектом для университета. Я делаю текстовую приключенческую игру, которая скорее линейна, но я не могу пройти через этот блок.
Я пытался вызвать список, чтобы показать "Вы выбрали ...", ноЯ не могу заставить его сделать это, я пытался следовать тому, что делал ранее с другим списком, но я думаю, что я потерян.
import random
import time
list_intro = ["The drawbridge.", "The sewers."] # naming the 2 indexes to paths ingame.
hall_rooms = ["Left door", "Right door"]
def intro():
print("You heard at the local tavern of a abandoned castle holding many treasures.")
print("You journey for 7 days until you find yourself at the bottom of the path leading to the castle.")
print("Standing at the foot of the castles runway you see two options to enter.")
for index, path in enumerate(list_intro):
# this is the loop that prints both options as well as the index value +1 (index starts @ 0).
print(str(index + 1) + ".", path)
# print("1. To enter through the drawbridge.")
# print("2. To swim under the moat and enter the sewers.")
story = {}
def chosenpath():
path = ""
while path != "1" and path != "2": # we are including input validation, meaning only predefined values will work.
path = input(
"What path will you choose? (1 or 2): ") # the inclusion of the boolean operator "and" is also here
return int(path)
def checkpath(path): # here we are simply making a function to return a string based on the option the user chooses.
print("You have chosen", list_intro[path - 1])
return entering_path(path)
def entering_path(path):
print(f"So you've entered {list_intro[path - 1]}") # here we are simply using the user input to call a item from
# our list using index values.
if path == 1:
return """You cross the drawbridge and see a gargoyle looking straight at you,
before you have time to react you feel a slight brush across your neck, you then fall to the ground
but see your body standing, it seems your head is no longer attached to your body.
Better luck next time!"""
if path == 2: # Adding a new string here for the other path.
return """You climb over the small ledge leading into the castles underbelly,unfortunately the swim wasn't great,
& you now wreak of old sewage and damp water. After walking up some stairs you find yourself in a grand dining hall,
At the back of the hall there are two doors, one on the left and one on the right. What one do you choose?"""
print(hall_rooms)
def Dining_Hall_Rooms():
print("So you've chosen", hall_rooms[-1])
intro()
path = chosenpath()
print(checkpath(path))
Я не получаю сообщений об ошибках, но когда я запускаю код по пути "канализации", я получаю это -
You heard at the local tavern of a abandoned castle holding many treasures.
You journey for 7 days until you find yourself at the bottom of the path leading to the castle.
Standing at the foot of the castles runway you see two options to enter.
1. The drawbridge.
2. The sewers.
What path will you choose? (1 or 2): 2
You have chosen The sewers.
So you've entered The sewers.
You climb over the small ledge leading into the castles underbelly,unfortunately the swim wasn't great,
& you now wreak of old sewage and damp water. After walking up some stairs you find yourself in a grand dining hall,
At the back of the hall there are two doors, one on the left and one on the right. What one do you choose?
Process finished with exit code 0
Извините, если мне не хватаетчто-то действительно довольно очевидное, кодирование, конечно, не моя сильная сторона, но я действительно хочу улучшить. Также извиняюсь за грамматические ошибки.