【发布时间】:2020-12-29 15:30:46
【问题描述】:
以下是错误
pygame 2.0.0(SDL 2.0.12,python 3.7.7)
Traceback (most recent call last): File "C:/Users/T######/PycharmProjects/pythonProject1/env.py", line 54, in < module > game_over, score = game.play_step() File "C:/Users/T######/PycharmProjects/pythonProject1/env.py", line 46, in play_step return game_over, self.score AttributeError: 'SpaceInvaders' object has no attribute 'score'**
在SpaceInvaders 类中,虽然它有 score 属性 -
class SpaceInvaders:
def __int__(self, w=640, h=480):
self.w = w
self.h = h
# init display
self.display = pygame.display.set_mode((self.w, self.h))
pygame.display.set_caption("SpaceInvaders")
self.clock = pygame.time.Clock()
# init game state
self.direction = Direction.RIGHT
self.head = Point[self.w/2, self.h/2]
self.score = 0
def play_step(self):
game_over = False
return game_over, self.score
这个问题有什么解决办法吗?
【问题讨论】:
-
这是一个错字。
__int__应该是__init__。这个问题对其他人没有用。请阅读What topics can I ask about here?
标签: python