【发布时间】:2016-11-26 21:34:30
【问题描述】:
我一直在尝试在我的文字游戏中实现战斗系统。我想我可以在我的每个场景中创建具有不同int 值的实例,以尽量减少我认为书中的练习试图教给我的硬编码。当我通过 dict 访问 TestRoom 类时,它在 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)
这是在 Python 2.7 中
旁注:在 Python 3 退出后学习 Pyhton 2.7 是不是一件坏事?不需要回答,只是想知道。
【问题讨论】:
标签: python python-2.7 syntax typeerror