【发布时间】:2017-07-23 17:49:54
【问题描述】:
我是一名初级程序员。我想创建一个用户输入会影响游戏进程的游戏。一开始我有点卡住了。
def displayIntro():
print("You wake up in your bed and realize today is the day your are going to your friends house.")
print("You realize you can go back to sleep still and make it ontime.")
def wakeUp():
sleepLimit = 0
choice = input("Do you 1: Go back to sleep or 2: Get up ")
for i in range(3):
if choice == '1':
sleepLimit += 1
print("sleep")
print(sleepLimit)
if sleepLimit == 3:
print("Now you are gonna be late, get up!")
print("After your shower you take the direct route to your friends house.")
elif choice == '2':
print("Woke")
whichWay()
else:
print("Invalid")
def whichWay():
print("After your shower, you decide to plan your route.")
print("Do you take 1: The scenic route or 2: The quick route")
choice = input()
if choice == 1:
print("scenic route")
if choice == 2:
print("quick route")
displayIntro()
wakeUp()
我有一些错误,我试图自己解决它们,但我很挣扎。
1) 我只希望玩家能够再次入睡 3 次,第三次我希望出现一条消息并运行另一个功能(还没有实现)。
2) 如果玩家决定醒来,我希望 whichWay() 运行,但它不会退出 for 循环,而是直接返回该循环并询问玩家是否想再次醒来,我不知道如何解决这个问题。
3) 有没有更好的方法来制作这样的游戏?
感谢您的宝贵时间并希望您的回答。
【问题讨论】:
标签: python-3.x function loops break adventure