feat: select game duration
All checks were successful
Linux arm64 / Build (push) Successful in 28s

This commit is contained in:
2025-02-01 12:27:50 +01:00
parent e98199e1ec
commit 02089c649b
9 changed files with 52 additions and 27 deletions

View File

@@ -69,13 +69,13 @@ public class Server {
return game;
}
public void startGame(MultiDoku doku) {
public void startGame(MultiDoku doku, long gameDuration) {
Instant now = Instant.now();
this.game.startGame(doku, now);
this.game.startGame(doku, now, gameDuration);
for (ServerConnexion connexion : this.connexions) {
connexion.setSudoku(doku.clone());
}
broadcastPacket(new StartGamePacket(SudokuSerializer.serializeSudoku(doku).toString(), now));
broadcastPacket(new StartGamePacket(SudokuSerializer.serializeSudoku(doku).toString(), now, gameDuration));
}
}

View File

@@ -76,7 +76,7 @@ public class ServerConnexion extends Connexion {
setSudoku(game.getDoku().clone());
sendPacket(
new StartGamePacket(SudokuSerializer.serializeSudoku(game.getDoku()).toString(),
game.getStartTime()));
game.getStartTime(), game.getGameDuration()));
}
}
@@ -148,6 +148,15 @@ public class ServerConnexion extends Connexion {
this.server.getGame().setPlayerScore(player, player.getScore() - 1);
this.server.broadcastPacket(new UpdatePlayerScorePacket(player.getId(), player.getScore()));
}
checkWin();
}
private void checkWin() {
if (this.player.getScore() == 0) {
// we don't need to specify the winner since it has to be the first
this.server.broadcastPacket(new EndGamePacket());
this.server.getGame().stopGame();
}
}
public void setSudoku(MultiDoku doku) {