Füge Countdown-Logik für den Spielstart hinzu und verbessere die Benutzerverwaltung in Lobbys
This commit is contained in:
26
frontend/dashboard/lobby/scripts/Handler/StartGameHandler.js
Normal file
26
frontend/dashboard/lobby/scripts/Handler/StartGameHandler.js
Normal 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;
|
||||
Reference in New Issue
Block a user