countdownSpectator method

void countdownSpectator(
  1. ChessBoardInterface game
)

countdown for player time, if game has timeLimit is being used in ChessBoardWidget to start countdownSpectator when widget is created

Implementation

void countdownSpectator(ChessBoardInterface game) {
  StreamSubscription<int>? whiteTimeSubscription;
  StreamSubscription<int>? blackTimeSubscription;

  if (game.timeLimit != null) {
    whiteTimeSubscription = game.whiteTimeStream.listen((countdown) {
      if (countdown <= 0) {
        game.switchTimer(stop: true);
        whiteTimeSubscription?.cancel();

        checkForGameEnd(game);
      }
    });

    blackTimeSubscription = game.blackTimeStream.listen((countdown) {
      if (countdown <= 0) {
        game.switchTimer(stop: true);
        blackTimeSubscription?.cancel();

        checkForGameEnd(game);
      }
    });
  }
}