Hinzufügen der Game Logik: Hinzufügen von Spieler-Management, Socket.IO-Integration und UI-Updates

This commit is contained in:
2025-04-01 16:16:26 +02:00
parent 5a2eaf74ca
commit 2c9a14db9a
10 changed files with 64 additions and 9 deletions

View File

@@ -1,3 +1,5 @@
const socketIO = require("socket.io");
const SocketUser = require("../../Classes/SocketUser");
const GameManager = require("../GameManager");
class Game{
@@ -6,6 +8,21 @@ class Game{
this.io = io;
this.gameManager = gameManager;
this.code = code;
/**@type {Array<SocketUser>} */
this.players = []
// TODO: 5 Seconds after initialization, check if game has 2 players. if not stop game
setInterval(() => {
this.io.to(`game-${this.code}`).emit("waitForStart", this.players.length);
this.io.to(`game-${this.code}`).emit("randomTest", Math.floor(Math.random() * 1000) + 1);
}, 1000);
}
addUser(user){
if(this.players.length >= 2) return 1;
this.players.push(user);
}
}