Füge Countdown-Logik für den Spielstart hinzu und verbessere die Benutzerverwaltung in Lobbys

This commit is contained in:
2025-03-24 19:46:49 +01:00
parent 101b29193c
commit d299a90067
10 changed files with 178 additions and 5 deletions

View File

@@ -1,3 +1,5 @@
import StartGameHandler from "./StartGameHandler.js";
class LobbyHandler {
/**@param {import("../../../../../backend/node_modules/socket.io-client".Socket} socket Autocompletions VSC*/
constructor(socket) {
@@ -22,6 +24,9 @@ class LobbyHandler {
// Für das Aktualisieren
this.socket.on("lobbyUserUpdate", (data) => { this.lobbyUserUpdate(data) });
// Für alles Was mit dem Starten zu tuhen hat
this.startGameHandler = new StartGameHandler(this.socket);
}
handleCreateClick() {

View File

@@ -0,0 +1,26 @@
class StartGameHandler {
/**@param {import("../../../../../backend/node_modules/socket.io-client".Socket} socket Autocompletions VSC*/
constructor(socket) {
this.socket = socket;
this.countDownText = document.getElementById("countdown");
this.socket.on("startGame", (data) => { this.startGame(data) });
this.socket.on("interruptStart", () => { this.interruptStart() });
}
startGame(data) {
document.getElementById("gameStartCountdown").style.display = "block";
this.countDownText.innerText = data.currentSecond;
if(data.needRedirect){
window.location.pathname = `/game`;
}
}
interruptStart() {
document.getElementById("gameStartCountdown").style.display = "none";
}
}
export default StartGameHandler;