简体   繁体   English

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

[英]RNG for my text-based game in python3

I am new to programming and to test myself, I tried making a text-based game. 我是编程新手,为了测试自己,我尝试制作一款基于文本的游戏。 The problem is, in the selection of dialogue, I included a speech check where it will be based on RNG but I just can't get it right. 问题是,在选择对话时,我进行了语音检查,该检查将基于RNG,但我做得不好。 I am sorry if this is a dumb question but I am really lost. 很抱歉,这是一个愚蠢的问题,但我真的迷失了。

Here is the part of the code: 这是代码的一部分:

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")

It seems that you have used the same variable twice. 似乎您已经两次使用相同的变量。

Your loop: 您的循环:

for rng in range(1): 对于范围(1)中的rng:

uses the same variable as the randomizer variable. 使用与随机变量相同的变量。

rng = random.randint(1, 101) rng = random.randint(1,101)

Switch a variable name and it should work fine! 切换一个变量名,它应该可以正常工作!

Also, use a shorter range to minimize errors, 1-2 rather than 1-101 另外,请使用较短的范围以最小化错误,而不是1-101,而是1-2

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM