在用Python编程时,我遇到了一个错误,需要两个参数,而只有一个。
TypeError: __init__() takes exactly 2 arguments (1 given)
我试过添加额外的参数和其他方法,但我没有找到它的工作参数是类自变量我的代码如下所示。
import sys, pygame
pygame.init()
size = width, height = 750, 500
backgroundColour = 23, 195, 74
screen = pygame.display.set_mode((size), 0, 32)
class NPC():
npcList = []
def GetNPCList(self):
listNPC = []
for i in range(0, self.npcList):
test = self.npcList[i].id
listNPC.append(test)
print(listNPC)
def GetNPC():
return NPC()
class NPCHandler(object):
def __init__(self, npcId):
self.id = id
def newNPC(self, npcId):
return NPCHandler(npcId)
def addNPC(self, n = NPC):
return n.npcList.append(n)
def GetNPCHandler():
return NPCHandler()
def main():
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
for i in range(0, 5):
GetNPCHandler().addNPC(GetNPCHandler().newNPC(1))
GetNPC().GetNPCList()
screen.fill(backgroundColour)
#pygame.draw.circle(screen, (0, 0, 0), (100, 100), 10, 0)
pygame.display.update()
if __name__ == "__main__":
main()
目前没有回答
相关问题 更多 >
编程相关推荐