首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python中基于文本的冒险

Python中基于文本的冒险
EN

Stack Overflow用户
提问于 2014-03-14 14:52:56
回答 1查看 147关注 0票数 0

我制作了这个游戏,我希望用户必须得到一个马鞍,然后他们能够离开马上,这总是打印(“输”),即使我有马鞍,并输入是为raw_input。

代码语言:javascript
复制
##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.")
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-14 15:04:22

你有个打字错误。

代码语言:javascript
复制
saddle == True

我猜你是说:

代码语言:javascript
复制
saddle = True

所以马鞍永远不会变成真的

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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22408436

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档