【发布时间】:2018-08-28 15:28:06
【问题描述】:
我正在开发一款基于文本的冒险游戏。本质上,我想根据用户类型返回正确的事件。现在,无论用户键入什么,它都会给出相同的事件(每次都返回 EVENT_DRAGON)。在游戏的大部分时间里,用户可以在 1、2 或 3 之间进行选择。效果非常好,但我想切换它并要求用户输入单词。这一直无法正常工作.. 澄清为什么它可以使用编号输入而不是单词输入将不胜感激。谢谢。
def main():
import sys
def run_event(event):
text, choices = event
text_lines = text.split("\n")
for line in text_lines:
print('' + line)
print("")
choices = choices.strip("\n")
choices_lines = choices.split("\n")
for num, line in enumerate(choices_lines):
print('' + line)
print("")
print ("")
print ("You have found yourself stuck within a dark room, inside this room are 5 doors.. Your only way out..")
print ("")
print ("Do you want to enter door 1,2,3,4, or 5?")
print ("")
EVENT_DOOR3 = ("""
A dragon awaits you
""","""
'Welcome' remarks the dragon. 'Do you wish to escape?""")
EVENT_DRAGON = ("""
'Good choice' says the dragon. Where would you like to escape to?
""","""
1. Just get me out of here!
2. Where should I escape to?
""")
EVENT_DRAGON2 = ("""
Interesting..
""","""
Test..
""")
door = input("> ")
if door == "3":
run_event(EVENT_DOOR3)
dragon = input()
if dragon in ['yes','Yes']:
run_event(EVENT_DRAGON)
elif dragon in ['no','No']:
run_event(EVENT_DRAGON2)
main()
【问题讨论】:
-
if dragon == "yes" or "Yes":将始终为真,请参阅副本。 -
感谢您的回复。我按照推荐的方式进行了重组,但现在事件根本无法运行。也许我的事件函数有问题?
-
为我工作:ibb.co/jhMWq9
-
我让它工作了,我这边的 ELIF 语句前面有 2 个空格。谢谢您的帮助! @ErTR
标签: python events input tuples adventure