【发布时间】:2020-02-04 11:51:39
【问题描述】:
我正在用 Python 制作一款 RPG 游戏。 我做了不同的课程,但我遇到了我的一种敌人类型的问题。它是一只蜘蛛,为了增加趣味,我试着让蜘蛛做点(随着时间的推移造成伤害)。它不能保证中毒伤害,但是当它确实使你中毒时,它会叠加。 这是我的父类(敌人):
class Enemy():
def __init__(self, number_of, name):
self.number_of = int(number_of)
self.name = name
self.hp = 20 * self.number_of
self.dmg = 2 * self.number_of
def attack(self):
print(f"you now have {round(class1.hp)} health" + "\n")
def appearing(self):
if self.number_of > 1:
print (f"{self.number_of} {self.name}s have appeared")
else:
print(f"A {self.name} has appeared")
print (f"They have {self.hp} health")
注意:class1 是播放器
这是我的蜘蛛类:
class Spider(Enemy):
posion_dmg = 0
def __init__(self, number_of, name):
Enemy.__init__(self, number_of, name)
self.posion_dmg = 0
def attack(self,player):
if self.posion_dmg > 0:
dot = 2 ** (self.poison_dmg + 1)
player.hp -= dot
print ("you are posioned" + "\n")
print (f"it deals {round(dot)} damage")
dmg = random.uniform(1.2 * self.dmg, 1.8* self.dmg)
player.hp -= dmg
print ("The spider(s) bite(s) you. ")
print(f"It deals {round(dmg)} damage")
if randint(1,4) == 1:
self.poison_dmg += 1
if self.number_of == 1:
print ("The spider poisons you")
else:
print ("The spiders poison you")
return Enemy.attack(self)
def appearing(self):
print ("*Spiders have a chance to hit you with poison that deals damage over time - this stack exponentially*")
return Enemy.appearing(self)
当我和蜘蛛战斗时,randint为1,它说“蜘蛛”没有属性“poison_dmg”,但我把它变成了一个属性,对吧?
【问题讨论】:
-
"posion_dmg" 是你的属性