擅长:python、mysql、java
<p>您需要首先创建<code>player</code>的实例</p>
<pre><code>class Player: # Note how I have changed the class to have an upper case P
def __init__(self, hp, mp, atk, df, mag):
self.maxhp = hp
self.hp = hp
self.maxmp = mp
self.mp = mp
self.atkw = atk - 10
self.atks = atk + 10
self.df = df
self.mag = mag
self.actions = ["Attack", "Magic"]
def generate_damage(self):
return random.randrange(self.atkw, self.atks)
player = Player(100, 20, 5, 10,magic)
print(player.generate_damage())
</code></pre>