UNPKG

nodito

Version:

Una librería para aprender juegos por turnos en node.

36 lines 1.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class RoomManager { constructor(dictMaker, classMaker) { this.dictMaker = dictMaker; this.classMaker = classMaker; this.rooms = []; } makeRoom(type, game, players) { const makePlayer = this.classMaker[type]; if (!this.dictMaker[type]) { throw new Error("Undefined constructor for RoomGame of type: " + type); } return new this.dictMaker[type](game, players, makePlayer); } findByPlayer(p) { return this.rooms.find((x) => x.find(p) !== undefined); } add(room) { this.rooms.push(room); } remove(room) { this.rooms = this.rooms.filter((x) => x !== room); } count() { return this.rooms.length; } find(roomId) { return this.rooms.find((x) => x.getId() === roomId); } toClient() { return this.rooms.map((x) => x.toClient()); } } exports.RoomManager = RoomManager; //# sourceMappingURL=RoomManager.js.map