我制作了这个游戏,我希望用户必须得到一个马鞍,然后他们能够离开马上,这总是打印(“输”),即使我有马鞍,并输入是为raw_input。
##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.")发布于 2014-03-14 15:04:22
你有个打字错误。
saddle == True我猜你是说:
saddle = True所以马鞍永远不会变成真的
希望有帮助:)干杯,亚历克斯
https://stackoverflow.com/questions/22408436
复制相似问题