我必须写一个类在类可以addShapes将一个类放在列表中。蟒蛇
继承人的I类必须做
class Drawing(Circle, Square):
list = []
def addShape(self, theShape, colour, x, y, side):
self.list += [self.theShape(colour, x, y, side)]
def display(self):
return self.list
def move(self):
def changeColour(self, newColour):
def totalArea(self):
return
形状类:
class Shape(Point):
def __init__(self, colour, x, y):
Point.__init__(self, x, y)
self.colour = colour
self.centrePoint = (x,y)
def centre(self):
return self.centrePoint
def movePoint(self, newX, newY):
Point.move(self, newX, newY)
self.centrePoint = (self.x, self.y)
class Circle(Shape):
def __init__(self, colour, x, y, radius):
Shape.__init__(self, colour, x, y)
self.radius = radius
def getArea(self):
return math.pi * (self.radius * self.radius)
加上一个正方形类。
如何将颜色等加上形状的类名到列表中,然后才能使用。 或最好的做法是什么。
感谢
'addShapes'是什么意思?你只是想要一个'Shape'实例列表吗?你需要知道实例是什么形状,或者只需调用'draw()',让实例知道该怎么做? – unholysampler 2011-05-04 16:03:17
请处理您的问题的清晰度。这将有助于获得良好的答案。 – NPE 2011-05-04 16:15:38
ive添加了我必须做的类 – Tom 2011-05-04 16:58:34