Karasick

Untitled

May 11th, 2020
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. class BlockModel:
  2.     def __init__(self, x1, y1, x2, y2, color):
  3.         self._x1 = x1
  4.         self._y1 = y1
  5.         self._x2 = x2
  6.         self._y2 = y2
  7.         self._color = color
  8.  
  9.  
  10.     def move(self, dx, dy):
  11.         self._x1 += dx
  12.         self._x2 += dx
  13.         self._y1 += dy
  14.         self._y2 += dy
  15.  
  16.  
  17.  
  18. class View:
  19.     _canvas = ...
  20.     _cell_size = 70
  21.     def __init__(self):
  22.         pass
  23.  
  24.  
  25.  
  26. class BlockView(View):
  27.     def __init__(self, block:BlockModel):
  28.         self._block = block
  29.         self._canvas_id = None
  30.  
  31.  
  32.     def show(self):
  33.         x1 = self._block._x1 * self._cell_size
  34.         x2 = self._block._x2 * self._cell_size
  35.         y1 = self._block._y1 * self._cell_size
  36.         y2 = self._block._y2 * self._cell_size
  37.         color = self._block._color
  38.  
  39.         self._canvas_id = _canvas.create_rectangle(
  40.             x1, x2, y1, y2, fill=color,
  41.             activefill="white", outline='#CD853F', width='2')
  42.  
  43.  
  44.     def hide(self):
  45.         self._canvas.delete(self._canvas_id)
  46.         self._canvas_id = None
  47.  
  48.  
  49.  
  50. class BlockPresenter:
  51.     def __init__(self, model:BlockModel, view:BlockView):
  52.         self.model = model
  53.         self.view = view
  54.         self.view.show()
  55.  
  56.  
  57.     def move(self, dx, dy):
  58.         self.view.hide()
  59.         self.model.move(dx, dy)
  60.         self.view.show()
Add Comment
Please, Sign In to add comment