Hinzufügen der Game Logik: Hinzufügen von Spieler-Management, Socket.IO-Integration und UI-Updates
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user