所以我有一个问题,我不太明白为什么会这样。当它应该在我的武器类上时,我得到一个(名称错误全局变量“值”未定义)。
from items import *
class weapons(Item):
def __init__(self, name, attack_damage, lifesteal = 0):
super(weapons,self).__init__(name, value, quantity=1)
self.attack_damage = attack_damage
self.lifesteal = lifesteal
这是武器从已经定义了值的类中获取它的类。
class Item(object):
def __init__(self, name, value, quantity=1):
self.name = name
self.raw = name.replace(" ","").lower()
self.quantity = quantity
self.value = value
self.netValue = quantity * value
def recalc(self):
self.netValue = self.quantity * self.value
我已经有一段与此类似的代码正在运行,但由于某种原因,这个值错误正在发生。我只是要包括它。
from character import*
class player(character):
def __init__(self,name,hp,maxhp,attack_damage,ability_power):
super(player,self).__init__(name, hp, maxhp)
self.attack_damage = attack_damage
self.ability_power = ability_power
以及玩家从中获取内容的类
class character(object):
def __init__(self,name,hp,maxhp):
self.name = name
self.hp = hp
self.maxhp = maxhp
def attack(self,other):
pass
正如你所看到的,我在这里做了,当我打电话给玩家时,这段代码可以工作。