文字冒险游戏,循环故障排除

时间:2019-10-12 18:42:08

标签: loops for-loop while-loop nested-loops

作为练习,我正在创建一个文字冒险游戏。 我从事这个冒险游戏已经有一段时间了... 我主要在90%的代码中使用了if,elif和else语句...(未显示完整的代码,下面的代码只是一部分) 我的代码有很多层,我试图找出不需要在相同缩进级别上循环的方法,我想知道是否有人可以帮助我? 我是否需要重新考虑代码的格式?还是可以使用填充有else,if和elif函数的现有代码?

我无法弄清楚在我的一生中如何使用while和for循环。

#setup
name = ('Ashe')
robot_name = ('bob')
status = []
#status is the "players life.  1=alive; 0=dead"
#game_start (not really) many more layers of code supposed to be before these... the decision the user leads to here...
answer = input('input either 1 or 2')
if (answer == "1"):
    #there are many layers and "decisions here"
    print(f"""{robot_name}:[let me get through this wall of bright blue vines] """)
    print(f"""{robot_name}:[There is a LOT of these vines, maybe this IS the wa---] """)
    print(f"""{robot_name}:[We wandered into a tar pit... there does not seem to be anything to help us...] """)
    print(f"""{robot_name}:[I am sinking FAST... {name} I don't think I will make it... I will keep this brief] """)
    print(f"""{robot_name}:[Thank you for everything thus far, please do not blame youself for this... and... goodbye...] """)
    print(f"""User [{name}] - Disconnected from unit {robot_name}."you died" """)
    #how to make this point loop back to "#game_start" 
if (answer == '2'): 
    #many layers added here
    answer = input(f"""you are still alive and finished the game. would you like to play again?' (yes/no)""")
    if answer == ('yes'):
        print('alright, we will start the game again')
        #many more layers, how to loop back to start?
    elif answer == ('no'):
        print('guess not')
        #loop back to start

else:
    print('not working?')
    #loop back to start

无论任何决定,我都试图使代码循环回到代码的开头或中间。尽管压痕程度不同。

0 个答案:

没有答案