Python中基于文本的冒险
我制作了这个游戏,我希望用户在能够马上带着马离开之前,必须得到一个马鞍。即使我有马鞍并且输入yes作为原始输入,这也会打印(“输”)Python中基于文本的冒险,python,Python,我制作了这个游戏,我希望用户在能够马上带着马离开之前,必须得到一个马鞍。即使我有马鞍并且输入yes作为原始输入,这也会打印(“输”) ##Text adventure## import time, datetime, sys, random keepGoing = True saddle = False def typer(what_you_want_to_type): for letter in what_you_want_to_type: sys.stdout.write(let
##Text adventure##
import time, datetime, sys, random
keepGoing = True
saddle = False
def typer(what_you_want_to_type):
for letter in what_you_want_to_type:
sys.stdout.write(letter)
sys.stdout.flush()
time.sleep(random.random() * 0.1)
typer("""You are at home eating a taco when suddenly there is a
great flash of light in the sky.""")
print("")
##Places and there descriptions go here##
home = ("Home", "You are at home.")
farm = ("Farm", "You are on the farm herding sheep while eating a taco")
field = ("Field", "You are in a corn field and you dropped your taco")
ranch = ("Ranch", "You are on the ranch")
##Dictionary of were you are and were you can go based on were you are##
transitions = {
home:(farm, field),
farm:(home, ranch),
field:(home, ranch),
ranch:(farm, field)
}
##Current location##
location = home
##Main game loop##
while keepGoing:
print("")
print location[1]
time.sleep(3)
print("\nYou can go to these places:")
##Adds a number to each place##
for (i, t) in enumerate(transitions[location]):
print i + 1,t[0]
##Obviously where you choose to go##
choice = int(raw_input("\nGo to "))
location = transitions[location][choice - 1]
if location == field:
take = raw_input("Take a horse?")
if take == "yes" and saddle == True:
print("win")
keepGoing == True
else:
print("Lose")
keepGoing = False
if location == ranch:
saddle == True
print("found a saddle.")
你打错了
saddle == True
我猜你的意思是:
saddle = True
所以马鞍实际上从未变为真
希望有帮助:)
干杯
Alex您在第4行设置了
saddle=False
,并且从不更改它。