나는 파이썬에서 새롭지도 경험이 없으며 Google과 Bing에서 여러 시간 후에도 답을 찾을 수있는 뚱뚱한 문제에 직면하고 있습니다. 내 문제는 다음 코드로 시작합니다.파이 게임 (Pygame) 상속 문제
class Rectangulo(object):
def __init__ (self, x, y, color, largo, alto, cambio_x, cambio_y):
self.alto = alto
self.largo = largo
self.color = color
self.cambio_x = cambio_x
self.cambio_y = cambio_y
self.x = x
self.y = y
def dibujar(self):
pygame.draw.rect(pantalla, self.color, (self.x, self.y, self.alto, self.largo))
def mover(self):
self.x += self.cambio_x
self.y += self.cambio_y
class Elipse(Rectangulo):
def __init__(self):
Rectangulo.__init__(self)
def dibujar (self):
pygame.draw.ellipse(pantalla, Rectangulo.color,(Rectangulo.x, Rectangulo.y, Rectangulo.alto, Rectangulo.largo))
이것은 현재 가장 중요한 코드입니다. Elipse에서 문제가 발견되어 상속이 작동하도록 여러 가지 방법을 시도했지만 콘솔에서이 메시지를 계속 표시합니다.
Traceback (most recent call last):
File "/home/josh/Escritorio/Codigo python/Jueguito.py", line 63, in <module>
miEl = Elipse(x,y,VERDE,alto,largo,cam_x,cam_y)
TypeError: __init__() takes 1 positional argument but 8 were given
매번 나는이 코드를 클래스 기능 dibujar()를 호출하려고 : 루프 자신을 위해 사용
for item in range(10):
x = random.randrange(685)
y = random.randrange(485)
alto = random.randrange(20, 71)
largo = random.randrange(20, 71)
cam_x = random.randrange(1, 2)
cam_y = random.randrange(-3, 3)
miObjeto = Rectangulo(x,y,VERDE,alto,largo,cam_x,cam_y)
miLista.append(miObjeto)
miEl = Elipse(x,y,VERDE,alto,largo,cam_x,cam_y)
미엘 변수하지만 난 나를 위해 덜 혼란 스러울 것입니다 이런 식으로 생각 . 나는 아직도 무슨 일이 일어나고 있는지 알 수 없다. 나는 도움이 필요해. 이 클래스는 7 개 매개 변수 (X, Y, 색상, ... 등) 소요 것을 기본 클래스 Rectangulo
의 초기화를 호출 할 때하기 때문에
이것은 대부분의 프로그래머가 변수 이름에 영어를 사용하는 이유입니다 ... – danijar
튜토리얼이 스페인어로되어있어서 페이스를 따라 갔기 때문에 스페인어로했습니다. 하지만 정말 귀찮은 일이라면 잘 살 수 있어요. – Jocoso
'Elipse'에 대한 생성자는'def __init __ (self)'이지만, 7 개의 매개 변수를 전달하고 있습니다. 그들을 지정해야합니다. –