added controller to model view controller
This commit is contained in:
13
src/controller/controller.py
Normal file
13
src/controller/controller.py
Normal file
@ -0,0 +1,13 @@
|
||||
from logic.board import Board
|
||||
from view.view import View
|
||||
|
||||
|
||||
class Controller:
|
||||
def __init__(self, board: Board, view: View) -> None:
|
||||
self._board = board
|
||||
self._view = view
|
||||
|
||||
self._view.set_controller(self)
|
||||
|
||||
def on_tile_selected(self, x: int, y: int) -> None:
|
||||
raise NotImplementedError(f"Cannot handle tile selected event, {type(self).__name__} did not implement it")
|
20
src/controller/gui_controller.py
Normal file
20
src/controller/gui_controller.py
Normal file
@ -0,0 +1,20 @@
|
||||
from logic.board import Board
|
||||
from view.view import View
|
||||
from .controller import Controller
|
||||
|
||||
|
||||
class GuiController(Controller):
|
||||
def __init__(self, board: Board, view: View) -> None:
|
||||
super().__init__(board, view)
|
||||
self._view.update_board(self._board, None, [])
|
||||
|
||||
def on_tile_selected(self, x: int, y: int) -> None:
|
||||
piece = self._board.piece_at(x, y)
|
||||
print(f"Clicked on {x, y}, {piece = }")
|
||||
|
||||
if piece:
|
||||
self._view.update_board(self._board, piece, piece.legal_moves(self._board))
|
||||
else:
|
||||
self._view.update_board(self._board, None, [])
|
||||
|
||||
|
Reference in New Issue
Block a user