我在python3中基于文本的游戏的RNG

时间:2018-07-31 01:29:31

标签: python python-3.x

我是编程和测试自我的新手,我尝试制作一款基于文本的游戏。问题是,在选择对话时,我进行了语音检查,该检查将基于RNG,但我做得不好。很抱歉,这是一个愚蠢的问题,但我真的迷路了。

这是代码的一部分:

def scene1part2():
    option2 = ["1. Okay. Here you go you cheeky guard.", "2. What?! No.", "3. [Luck] Let me in for free?"]
    option2_1 = ["Okay. Here you go you cheeky guard.", "What?! No.", "3.Let me in for free?"]
    for o2 in option2:
    print(o2)
    answer2 = input("> ")
    if answer2 == "1":
        print(option2_1[0])
        print("Lost 500 Chromosomes")
        print("Guard: You can go ahead now.")
        chromosomes = (chromosomes) - 500
    elif answer2 == "2":
        print(option2_1[1])
        print("Guard: Get out of here then you piece of crap.")
        sys.exit()
    elif answer2 == "3":
        for rng in range(1):
            rng = random.randint(1, 101)
            print(rng)
            if rng <= 50:
                print("Guard: You wish. Get out of here then you piece of crap. ")
            elif rng >= 50:
                print("Guard: *sigh* Okay. Come inside already")

1 个答案:

答案 0 :(得分:0)

似乎您两次使用相同的变量。

您的循环:

对于范围(1)中的rng:

使用与随机变量相同的变量。

rng = random.randint(1,101)

切换一个变量名,它应该可以正常工作!

此外,请使用较短的范围以最大程度地减少错误,而不是1-101,而是1-2

希望这会有所帮助!