AttributeError:'list'对象没有属性'x'

时间:2017-04-19 02:31:36

标签: python python-3.x pygame

我正在尝试为游戏小行星制作一些岩石,我收到此错误消息。我该如何解决这个问题?

这是我的代码:

ramesh

我只是不明白在哪里调用'列表'?

这是我的引用:

class Rock(movable.Movable):
# outline = [(10, 0), (12, 8), (0, 7), (-10, 10), (-5, 0), (-10, -10), 
(0, -8)]
outline = []
points = random.randint(5, 15)
for degrees in range(0, 360, int(360/points)):
    r = random.randint(5, 15)
    angle = math.radians(degrees)
    x = int(r * math.cos(angle))
    y = int(r * math.sin(angle))
    point = (x, y)
    outline.append(point)

x = random.randint(0, SCREENW)
y = random.randint(0, SCREENH)
d = random.randint(0, 359)
movable.Movable.__init__(outline, x, y, dir)
self.setColor(255, 0, 0)

dx = random.randint(1, 4) * random.randint(-1, 1)
dy = random.randint(1, 4) * random.randint(-1, 1)
self.setDX(7)
self.setDY(3)

ddir = random.randint(-20, 20)
self.rotate(ddir)

def paint(self, surface):
    pygame.draw.polygon(surface, (255, 0, 0), outline)

这是我的Locatable:

Traceback (most recent call last):
File "pygame_starter.py", line 4, in <module>
import game
File "/Volumes/KINGSTON/CS1410/Asteroids/game.py", line 1, in <module>
import pygame, rocket
File "/Volumes/KINGSTON/CS1410/Asteroids/rocket.py", line 75, in 
<module>
class Rock(movable.Movable):
File "/Volumes/KINGSTON/CS1410/Asteroids/rocket.py", line 90, in Rock
movable.Movable.__init__(outline, x, y, dir)
File "/Volumes/KINGSTON/CS1410/Asteroids/movable.py", line 7, in 
__init__
locatable.Locatable.__init__(self, x, y)
File "/Volumes/KINGSTON/CS1410/Asteroids/locatable.py", line 6, in 
__init__
self.x = int(SCREENW//2)
AttributeError: 'list' object has no attribute 'x'

1 个答案:

答案 0 :(得分:2)

你的代码很奇怪......但问题几乎肯定在这里:

movable.Movable.__init__(outline, x, y, dir)

__init__方法需要movable.Movable的实例作为第一个参数。您传递的是outline,这是一个列表。