如何解决该参数错误?

时间:2018-07-18 16:49:40

标签: python python-3.x

我目前正在开发这款战斗游戏,突然间我遇到了这个意外的参数错误。我可能做错了什么,但看不到任何东西。因此,如果有人可以帮助我了解问题所在,我将不胜感激。

game.py

import random

class bcolors:
    HEADER = '\033[95m'
    OKBLUE = '\033[94m'
    OKGREEN = '\033[92n'
    WARNING = '\033[93n'
    FAIL = '\033[91n'
    ENDC = '\033[0m'
    BOLD = '\033[1m'
    UNDERLINE = '\033[4n'

class Person:
    def _init_(self, hp, mp, atk, df, magic):
        self.maxhp = hp
        self.hp = hp
        self.maxmp = mp
        self.mp = mp
        self.atkl = atk - 10
        self.atkh = atk + 10
        self.df = df
        self.magic = magic
        self.actions = ["Attack", "Magic"]

    def generate_damage(self):
        return random.randrange(self.atkl, self.atkh)

main.py

from classes.game import Person, bcolors

magic = [{"name": "Fire", "cost": 10, "dmg": 60},
         {"name": "Thunder", "cost": 10, "dmg": 60},
         {"name": "Blizzard", "cost": 10, "dmg": 60}]


player = Person(460, 65, 60, 34, magic)

print(player.generate_damage())
print(player.generate_damage())
print(player.generate_damage())

带有警告消息的代码行在main.py中,并且该行说玩家= Person(460,65,60,34,魔术) 谢谢。

1 个答案:

答案 0 :(得分:1)

您必须在__语句周围加上两个下划线init。您的Person类应如下所示:

class Person:
    def __init__(self, hp, mp, atk, df, magic):
        self.maxhp = hp
        self.hp = hp
        self.maxmp = mp
        self.mp = mp
        self.atkl = atk - 10
        self.atkh = atk + 10
        self.df = df
        self.magic = magic
        self.actions = ["Attack", "Magic"]

    def generate_damage(self):
        return random.randrange(self.atkl, self.atkh)