首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何应对不同的随机反应(在我的文字冒险游戏中)

如何应对不同的随机反应(在我的文字冒险游戏中)
EN

Stack Overflow用户
提问于 2019-04-14 19:29:11
回答 1查看 139关注 0票数 0

我正在用python做一个文字冒险游戏,我随机地给我的每个第一选择( A,B,C)做了一个反应,现在让我说他在选择A时什么都找不到。

“如果没有发现,(* 在这里插入另一个选项列表, *)”

在我的密码里?我似乎找不到答案,所以我希望这里有人知道,谢谢!到目前为止,这是我的代码:

代码语言:javascript
复制
import time
import random

print ('You suddenly jolt up from the sleeping bag, awoken by the howling of nearby wolves.\nYou are cold, shivering and starving, and the few things that are still visible,\nare lit up only by the moon, and notice you are in the middle of a forest.\n')
ch1 = str(input(' Do you: \nA: Use your hands to search around\nB: Sleep again until morning\nC: Get up, and attempt to run away from the wolves in the dark:\n'))

responsesA = [
    'You found a torch!',
    'You did not find anything.'
    ]

responsesB = [
    'You fell asleep again cold and hungry.',
    'You are unable to sleep.'
    ]

responsesC = [
    'You start running as fast as you can and successfuly escape!',
    'You trip and injure knee.'
    ]


if ch1 in ['A']:
    print (random.choice(responsesA))

if ch1 in ['B']:
    print (random.choice(responsesB))

if ch1 in ['C']:
    print (random.choice(responsesC))

有什么我该换的吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-14 19:34:30

这个怎么样?

代码语言:javascript
复制
if ch1 in ['A']:
    random_value = random.choice(responsesA)
    print(random_value)
    if random_value == 'You did not find anything.':
       # insert another list of choices here

与其打印出随机值,不如将其保存在变量中,然后检查随机值是否为“无值”,并相应地处理它。

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

https://stackoverflow.com/questions/55679225

复制
相关文章

相似问题

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