Untitled
unknown
plain_text
2 years ago
980 B
8
Indexable
Never
class point: def __init__(self,x,y): self.x = x self.y = y class Rectangle: """ A class to manufacture rectangle objects """ def __init__(self, posn, w, h): """ Initialize rectangle at posn, with width w, height h """ self.corner = posn self.width = w self.height = h def __str__(self): return "({0}, {1}, {2})" .format(self.corner, self.width, self.height) def grow(self, delta_width, delta_height): """ Grow (or shrink) this object by the deltas """ self.width += delta_width self.height += delta_height def move(self, dx, dy): """ Move this object by the deltas """ self.corner.x+= dx self.corner.y+= dy box = Rectangle(point(0, 0), 100, 200) bomb = Rectangle(point(100, 80), 5, 10) # In my video game print("box: ", box) print("bomb: ", bomb) print(bomb.corner) print(bomb.grow(10,30)) print(bomb.move(1,2))