<p>我试图用Python编写一个基于文本的冒险游戏,但是我无法让战斗系统工作</p>
<p>到目前为止,我的情况是:</p>
<pre><code>import time
import random
battle_chance = 3
enemies = ['A hoard of Goblins', 'A skeleton army', 'A large troll']
random_index = randrange(len(enemies))
def init_battle():
while True:
x = randint(0,5)
time.sleep(2)
if x == battle_chance:
print(enemies[random_index], "Has approached you.\nWhat do you do?")
</code></pre>
<p>我总是遇到一个错误,我想不出怎么解决它</p>