Trigger game stop

This commit is contained in:
2026-01-05 11:55:08 +01:00
parent e2679901f5
commit 6a47d83ada
2 changed files with 23 additions and 10 deletions

View File

@@ -1,4 +1,5 @@
import json
from typing import Callable
from hardware.buzzer.buzzer import Buzzer
from hardware.led.led import Led
@@ -16,6 +17,7 @@ class GameService:
_has_started : bool
_led : Led
_buzzer : Buzzer
_on_terminated : Callable[[str], None]
def __init__(self):
self._detection_service = DetectionService()
@@ -23,7 +25,6 @@ class GameService:
self._has_started = False
self._led = Led(7)
self._buzzer = Buzzer(8)
self.game = None
def start(self, white_name, back_name, time_control : int, increment : int ) -> None:
if self._has_started :
@@ -42,7 +43,7 @@ class GameService:
self._clock_service.stop()
self._detection_service.stop()
self._led.off()
self._buzzer.beep()
self._notify()
self._has_started = False
def make_move(self) -> tuple[bytes, str] | None:
@@ -57,5 +58,11 @@ class GameService:
print(e)
raise ServiceException(e)
def export_game(self):
return json.dumps(self._game)
def set_on_terminated(self, callback: Callable[[str], None]):
self._on_terminated = callback
def _notify(self):
game_data = json.dumps(self._game)
self._on_terminated(game_data)