Python中文
首页
教程
问答
标签
搜索
登录
注册
Python在while循环中重复随机整数
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我试图为一个基于文本的RPG游戏编写玩家和怪物攻击代码,我为玩家和暴徒命中率和暴击几率设置了randomint,但我无法计算出如何在每次我重新启动循环时为它们获取一个新的整数,它使用的整数与它第一次进入循环时得到的相同。在</p> <pre><code>### GAME VALUES ### class roll_dice: def __init__(self): self.spawn = random.randint(1,100) self.escape = random.randint(1,100) self.playercrit = random.randint(1,100) self.playerhitchance = random.randint(1,100) self.mobcrit = random.randint(1,100) self.mobhitchance = random.randint(1,100) roll = roll_dice() ### ORC SPAWN ### if fight_walk.lower() == 'fight': orcMobSpawn() while True: fight_orc = input(">>> ") if fight_orc.lower() == 'a': ### PLAYER ATTACK ### while True: roll.playercrit roll.playerhitchance if roll.playercrit <= 10 and roll.playerhitchance >= 6: print("You crit orc for",str(userPlayer.atk * 2),"damage!") orcMob.hp = orcMob.hp - userPlayer.atk * 2 print("Orc HP:",orcMob.hp) break elif roll.playercrit >= 11 and roll.playerhitchance >= 6: print("You hit orc for",str(userPlayer.atk),"damage!") orcMob.hp = orcMob.hp - userPlayer.atk print("Orc HP:",orcMob.hp) break elif roll.playercrit >= 11 and roll.playerhitchance <= 5: print("You missed!") break elif roll.playercrit <= 10 and roll.playerhitchance <= 5: print("You missed!") break elif orcMob.hp <= 0 and userPlayer.hp >= 1: print("Your HP:",str(userPlayer.hp)) print("You win!") break elif userPlayer.hp <= 0: print("You died!") exit() ### ORC ATTACK ### while True: roll.mobcrit roll.mobhitchance if orcMob.hp <= 0 and userPlayer.hp >= 1: break if roll.mobcrit <= 5 and roll.mobhitchance >= 25: print("\nOrc crit for",str(orcMob.atk * 2),"damage!") userPlayer.hp = userPlayer.hp - orcMob.atk * 2 print("Your HP:",str(userPlayer.hp)) break elif roll.mobcrit >= 5 and roll.mobhitchance >= 25: print("\nOrc hit for",str(orcMob.atk),"damage!") userPlayer.hp = userPlayer.hp - orcMob.atk print("Your HP",str(userPlayer.hp)) break elif roll.mobcrit <= 5 and roll.mobhitchance <= 25: print("Orc missed!") print("Your HP:",str(userPlayer.hp)) break elif roll.mobcrit >= 5 and roll.mobhitchance <= 25: print("Orc missed!") print("Your HP:",str(userPlayer.hp)) break if orcMob.hp <= 0 and userPlayer.hp >= 1: break elif orcMob.hp >= 1: continue </code></pre>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>使用类似的函数</p> <pre><code>import random for x in range(10): print random.randint(1,101) </code></pre> <p>使用最多可容纳100人的数组,并生成随机数字来添加代码。在</p> <p>您也可以使用数组来创建随机数结构,然后在创建时使用要洗牌和添加的数字</p> ^{pr2}$
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
plt.savefig不会覆盖现有文件
8 回答
plt.savefig不保存图像
6 回答
plt.savefig在jupyter笔记本中不起作用
8 回答
plt.savefig在从另一个fi调用时停止工作
9 回答
plt.savefig在调用plt.show之前保存空数字
2 回答
plt.save不创建png文件
1 回答
plt.scatter overlay分类数据帧列
8 回答
Plt.Scatter:如何添加title、xlabel和ylab
2 回答
plt.scatter()绘图与Matplotlib中的plt.plot()绘图类似
3 回答
plt.scatter错误'NoneType'对象在成功运行后没有属性'sqrt'
7 回答
plt.set_title()中的标题字符串有误
1 回答
plt.show()
7 回答
plt.show()不在Jupyter笔记本上渲染任何内容
5 回答
plt.show()不打印plt.plot only plt.scatter
9 回答
plt.show()不显示三维散射图像
2 回答
plt.show()不显示任何内容
9 回答
plt.show()不显示数据,而是保留它供下一个图表使用(spyder)
8 回答
plt.show()使终端挂起
9 回答
plt.show()无法使用此代码
4 回答
plt.show()没有打开新的图形风
1 回答