Python中基于文本的冒险

时间:2014-03-14 14:52:57

标签: python

我做了这个游戏,我希望用户必须先得到一个马鞍,然后他们才能马上离开现在它总是打印(“丢失”),即使我有马鞍并为raw_input输入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(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.")

1 个答案:

答案 0 :(得分:2)

你有一个错字。

saddle == True

我猜你的意思是:

saddle = True

所以马鞍实际上从未改变为真

希望有帮助:) 干杯, 亚历