Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用类创建作战系统_Python_Python 2.7_Syntax_Typeerror - Fatal编程技术网

Python 使用类创建作战系统

Python 使用类创建作战系统,python,python-2.7,syntax,typeerror,Python,Python 2.7,Syntax,Typeerror,我一直在尝试在我的文字游戏中实现一个战斗系统。我想我可以在我的每个场景中创建具有不同int值的实例,以最小化硬编码,我认为这本书中的练习正试图教会我。当我通过dict访问测试室类时,它在Powershell中显示: TypeError: __init__() takes exactly 4 arguments (1 given) 请帮我弄清楚如何做到这一点,我对Python还不熟悉,但这本书并没有很好地解释类 class Hero(object): def __init__(self

我一直在尝试在我的文字游戏中实现一个战斗系统。我想我可以在我的每个场景中创建具有不同
int
值的实例,以最小化硬编码,我认为这本书中的练习正试图教会我。当我通过dict访问
测试室
类时,它在Powershell中显示:

TypeError: __init__() takes exactly 4 arguments (1 given)
请帮我弄清楚如何做到这一点,我对Python还不熟悉,但这本书并没有很好地解释类

class Hero(object):

    def __init__(self, health1, damage1, bullets1):
        self.health1 = health1
        self.damage1 = damage1
        self.bullets1 = bullets1

class Gothon(object):

    def __init__(self, health2, damage2):
        self.health2 = health2
        self.damage2 = damage2

class Combat(object):

    def battle():
        while self.health1 != 0 or self.health2 != 0 or self.bullets1 != 0:
            print "You have %r health left" % self.health1
            print "Gothon has %r health left" % self.health2
            fight = raw_input("Attack? Y/N?\n> ")
            if fight == "Y" or fight == "y":
                self.health2 - self.damage1
                self.health1 - self.damage2
            elif fight == "N" or fight == "n":
                self.health1 - self.damage2
            else:
                print "DOES NOT COMPUTE"
            if self.health1 == 0:
                return 'death'
            else:
                pass
class TestRoom(Combat, Hero, Gothon):

    def enter():
        hero = Hero(10, 2, 10)
        gothon = Gothon(5, 1)
这是在Python2.7中实现的


旁注:使用Python 3学习Python2.7是件坏事吗?答案并不是必须的,只是想知道。

我不知道为什么要让TestRoom继承其他三个类。这没有道理;继承意味着“是一种”关系,但尽管房间可能包含这些东西,但实际上它本身并不是这些东西中的任何一种


这就是问题的根源,因为TestRoom现在从定义它的第一个方法Hero继承了
\uuuuu init\uuuu
方法,因此它需要Hero所需要的参数。删除该继承。

我不知道为什么要让TestRoom继承其他三个类。这没有道理;继承意味着“是一种”关系,但尽管房间可能包含这些东西,但实际上它本身并不是这些东西中的任何一种

这就是问题的根源,因为TestRoom现在从定义它的第一个方法Hero继承了
\uuuuu init\uuuu
方法,因此它需要Hero所需要的参数。删除该继承