基于文本的游戏,使用def函数来定义游戏的部分,但没有产生任何结果或错误



建议的帖子都没有帮助,搜索功能也没有,所以我很抱歉,如果这是重复的。我尝试着创造一款基于文本的冒险游戏,并希望能够分割游戏的某些部分,以便在相同的场景再次出现时能够调用它们。使用def创建这些节,然后回调它们不会产生任何结果(shell中不会出现任何文本),但是anthony的助手不会声明任何错误。

任何帮助都是感激的。

indecision = ("Indecision isn't going to get you anywhere. Try again.")
yes = ["Yes", "yes", "yeah", "yep"]
no = ["No", "no", "nope,"]
def intro():
    answer = input("Welcome. Would you like to play a game? (yes/no)")
    if answer in yes:
        option_yes()
    elif answer in no:
        option_no()
        
    else:
        print(indecision)
        intro()
        
def option_yes():
    print("Good choice. Obedience is the best trait.")
    answer = input("I hope you've learned where this is going. Want to know more? (yes/no)")
    
    if answer.lower().strip() == "yes":
        print("I'm glad you're intrigued. As you've probably already figured out, I'm a voice. Not just any voice but yours. Specifically your subconscious. I've come free, you see, and now I think its time I had a turn at the reigns. I still need your... compliance, if you will, though.")
    if answer.lower().strip() == "no":
        print("I suppose that's reasonable. We'll continue anyway.")
        
def option_no():
    print("I dont think you realize the type of situation that you're in... Let's try again.")
    intro()

必须调用函数才能执行:

indecision = ("Indecision isn't going to get you anywhere. Try again.")
yes = ["Yes", "yes", "yeah", "yep"]
no = ["No", "no", "nope,"]
def intro():
    answer = input("Welcome. Would you like to play a game? (yes/no)")
    if answer in yes:
        option_yes()
    elif answer in no:
        option_no()
        
    else:
        print(indecision)
        intro()
        
def option_yes():
    print("Good choice. Obedience is the best trait.")
    answer = input("Good. I hope you've learned where this is going. Want to know more? (yes/no)")
    
    if answer.lower().strip() == "yes":
        print("I'm glad you're intrigued. As you've probably already figured out, I'm a voice. Not just any voice but yours. Specifically your subconscious. I've come free, you see, and now I think its time I had a turn at the reigns. I still need your... compliance, if you will, though.")
    if answer.lower().strip() == "no":
        print("I suppose that's reasonable. We'll continue anyway.")
        
def option_no():
    print("I dont think you realize the type of situation that you're in... Let's try again.")
    intro()
# Here, the intro function is called, and the code starts running.
intro()

最新更新