// Lobby class
class Lobby {
constructor(name) {
this.name = name;
this.players = []; // List of players in the lobby
}
addPlayer(player) {
this.players.push(player);
console.log(`${player} joined the lobby: ${this.name}`);
}
removePlayer(player) {
this.players = this.players.filter(p => p !== player);
console.log(`${player} left the lobby: ${this.name}`);
}
listPlayers() {
console.log(`Players in ${this.name}:`, this.players);
}
}
// Game class
class Game {
constructor(lobby) {
this.lobby = lobby
this.isRunning = false;
}
start() {
if (this.lobby.players.length === 0) {
console.log("Cannot start the game. No players in the lobby.");
return;
}
this.isRunning = true;
console.log(`Game started with players: ${this.lobby.players.join(", ")}`);
this.playSoundtrack();
}
stop() {
this.isRunning = false;
console.log("Game stopped.");
}
playSoundtrack() {
const audio = new Audio("path/to/soundtrack.mp3"); // Replace with actual path
audio.loop = true;
audio.play().then(() => {
console.log("Soundtrack playing...");
}).catch(err => {
console.error("Error playing soundtrack:", err);
});
}
}
// Example
const lobby = new Lobby("Battle Arena");
lobby.addPlayer("Player1");
lobby.addPlayer("Player2");
lobby.listPlayers();
const game = new Game(lobby);
game.start();
setTimeout(() => {
game.stop();
}, 10000);