可能不是正确的标题,但我不知道如何制定它
我正在尝试根据灵活的价值计算统计数据,特别是HP& MP并返回值,以便可以在屏幕上打印。我已经尝试为统计数据创建一个单独的类并调用它,在统计数据中以及在调用它时将其更改为self.HP但似乎没有任何工作,我无法弄清楚如何修复它。
我知道这是很多代码,但有人可以看一下吗,好吗?
E1:在这里复制了正确的代码(我是一个白痴-_-')并将惠普改回自己.HP程序完全是香蕉......它实际上已经自杀了。
import formulae
from formulae import *
characters = {"1":battle_maiden("Hibikime")}
enemies = {"a":enemy("Enemy")}
while characters["1"].alive and enemies["a"].alive:
print
for charactersKey, in sorted(characters.keys()):
print(characters[charactersKey])
在formulae.py中的代码:
class character(object):
def __init__(self, name):
self.name = name
self.alive = True
self.Hit = 10
self.Dodge = 0
self.Lv = 1
def __str__(self):
if self.alive:
return "%s (%i HP, %i MP)" % (self.name, self.HP, self.MP)
else:
return "%s (DEAD)" % self.name
def attack(self, enemy):
print(self.name, "attacks", enemy.name)
enemy.hit()
def hit(self):
self.HP -= self.Atk
print(self.name, "is hit! (",self.Atk,")")
if self.HP <= 0:
self.die()
def die(self):
self.alive = False
print(self.name, "died.")
class enemy(object):
def __init__(self, name):
self.name = name
self.alive = True
self.HP = 100
self.MP = 20
self.M_Atk = 10
self.Atk = 30
self.Def = 5
self.M_Def = 5
self.Hit = 10
self.Dodge = 0
def __str__(self):
if self.alive:
return "%s (%i HP, %i MP)" % (self.name, self.HP, self.MP)
else:
return "%s (DEAD)" % self.name
def attack(self, enemy):
print(self.name, "attacks", enemy.name)
enemy.hit()
def hit(self):
self.HP -= self.Atk
print(self.name, "is hit! (",self.Atk,")")
if self.HP <= 0:
self.die()
def die(self):
self.alive = False
print(self.name, "died.")
##SUBCLASSES FOR CHARACTERS##
class battle_maiden(character):
def __init__(self, name):
super(battle_maiden, self).__init__(self)
classHP = 80
classMP = 5
Vitality = 10
Wisdom = 3
Intelligence = 2
Strength = 15
Defense = 5
Dexterity = 15
Agility = 2
self.HP = (classHP + (self.Lv*5) + (Vitality *(self.Lv *0.3)))
self.MP = (classMP + (self.Lv*2) + (Wisdom *(self.Lv *0.2)))
Atk = (Strength * (self.Lv*0.2))
M_Atk = (Intelligence * (self.Lv*0.2))
Def = (Defense + (self.Lv*1.5) + (Defense*0.1))
M_Def = (Intelligence + (self.Lv*1.5) + (Intelligence*0.1))
我得到的错误:
返回“%s(%i HP,%i MP)”%(self.name,self.HP,self.MP)
RuntimeError:超出最大递归深度
答案 0 :(得分:1)
首先,双重导入是顽皮的,所以不要这样做;)
修复这个很简单,你只需要替换
super(battle_maiden, self).__init__(self)
与
character.__init__(self, name)
至于为什么,试着自己找出答案。如果你不能在30分钟内发表评论,我会破坏它;)