gpt4 book ai didi

python - 随机技能在 Python 文本角色扮演游戏中无法按预期发挥作用

转载 作者:行者123 更新时间:2023-11-30 23:36:56 26 4
gpt4 key购买 nike

我在处理基本技能提升时遇到了一些麻烦。现在代码看起来像

huntluck = 11
huntskill = 1

def hunt(self):
global result, huntluck, huntskill

hunting = random.randint(0, huntluck)

if hunting == 0:
result = "You couldn't find anything."
elif hunting >=10:
huntluck += 1
huntskill += 1
result = ("You succeeded in hunting. Your hunting skill increases. " +
"(%s)" %huntskill)

运气和技能是分开的,因为我希望一级狩猎成功的几率是十分之一,但我也想正确地发挥技能。这是一种相当笨拙的方法,但这只是问题的一部分。

一切都打印正确,但是当用户成功时,技能水平有大约 50/50 的机会不会提升。

You succeeded in hunting. Your hunting skill increases. (2)

You succeeded in hunting. Your hunting skill increases. (2)

You succeeded in hunting. Your hunting skill increases. (3)

You succeeded in hunting. Your hunting skill increases. (3)

You succeeded in hunting. Your hunting skill increases. (3)

You succeeded in hunting. Your hunting skill increases. (4)

我打算让玩家每次成功狩猎时技能水平都会提高。显然这并没有发生...

你能看出我做错了什么吗?我该如何修复它?我怎样才能把事情做得更好?

谢谢!

最佳答案

如果 hunting 等于 0大于 9,则只能为 result 设置新值。如果 hunting code> 等于 1-9,则 result 保留旧值,然后重新打印该值。

更改您的狩猎测试:

if hunting < 10:
result = "You couldn't find anything."
else:
huntluck += 1
huntskill += 1
result = ("You succeeded in hunting. Your hunting skill increases. " +
"(%s)" %huntskill)

关于python - 随机技能在 Python 文本角色扮演游戏中无法按预期发挥作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15998414/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com