Trigger game stop
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user