Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class BlockModel:
- def __init__(self, x1, y1, x2, y2, color):
- self._x1 = x1
- self._y1 = y1
- self._x2 = x2
- self._y2 = y2
- self._color = color
- def move(self, dx, dy):
- self._x1 += dx
- self._x2 += dx
- self._y1 += dy
- self._y2 += dy
- class View:
- _canvas = ...
- _cell_size = 70
- def __init__(self):
- pass
- class BlockView(View):
- def __init__(self, block:BlockModel):
- self._block = block
- self._canvas_id = None
- def show(self):
- x1 = self._block._x1 * self._cell_size
- x2 = self._block._x2 * self._cell_size
- y1 = self._block._y1 * self._cell_size
- y2 = self._block._y2 * self._cell_size
- color = self._block._color
- self._canvas_id = _canvas.create_rectangle(
- x1, x2, y1, y2, fill=color,
- activefill="white", outline='#CD853F', width='2')
- def hide(self):
- self._canvas.delete(self._canvas_id)
- self._canvas_id = None
- class BlockPresenter:
- def __init__(self, model:BlockModel, view:BlockView):
- self.model = model
- self.view = view
- self.view.show()
- def move(self, dx, dy):
- self.view.hide()
- self.model.move(dx, dy)
- self.view.show()
Add Comment
Please, Sign In to add comment