added controller to model view controller
Some checks failed
pre-release / Pre Release (push) Waiting to run
tagged-release / Tagged Release (push) Has been cancelled

This commit is contained in:
Karma Riuk
2025-01-31 10:52:25 +01:00
parent ddfb95176b
commit ac85f3e6d3
5 changed files with 63 additions and 29 deletions

View 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")

View 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, [])