我该怎么做呢? (不能想到一个准确的标题)(PYTHON)

时间:2017-09-19 19:39:11

标签: python

我正在尝试制作一个基于文本的选择你自己的冒险游戏。

在这个游戏中,每回合有三种选择:清除,休息和继续旅行。每次选择继续您的旅程' Area变量向上移动一个。如果你在同一地区清理两次,我希望它说'#34;你找不到任何东西。"。但如果我必须写'如果Area == one和Canteen == 1: 打印"你找不到任何东西。" (食堂是你在第一个区域清理的项目)如果我必须为每个选项写出来,我会非常沮丧。那么,如果他们在那个地区进行了清理,那么轻松测试的方法是什么,然后说“你无法找到任何东西。”#34;提前致谢!"

1 个答案:

答案 0 :(得分:0)

如果你正在寻找一些非常简单的东西,可以作为一个例子:

area = 0
inventory = []
area_scavenged = False

while True:
    print 'Area: %s\nInventory: %s' % (area, str(inventory))
    choice = raw_input("Choose an option: ")
    if choice == 'rest':
        pass
    elif choice == 'continue':
        area_scavenged = False
        area += 1
    elif choice == 'scavenge':
        if not area_scavenged:
            # Append to inventory the item that corresponds to the area you're in
            inventory.append('whatever')
            area_scavenged = True
        else:
            print("You couldn't find anything")
    elif choice == 'end':
        break