class Player { constructor(id, name) { this.name = name; this.timeout = null; this.id = id; this.ready = false; this.isPlaying = false; } resetTimeout() { if (this.timeout !== null) { window.clearTimeout(this.timeout); } this.timeout = window.setTimeout(() => { if (players[this.id] !== undefined) { delete players[this.id]; } updateDom(); }, TIMEOUT); } /** * Claim a region of the map. * * @param data Data received via socket. */ claim(data) { console.log(data.region); let region = Region.getRegion(data.region); if (region.owner === null) { region.claim(this); } } /** * Start a player's turn. */ startTurn() { this.isPlaying = true; } /** * Perform some game action on your turn. * * @param data Data received via socket. */ perform(data) {} /** * End player's turn */ endTurn() { this.isPlaying = false; this.nextPlayer().startTurn(); } nextPlayer() { let sorted = Object.values(players).sort((a, b) => (a.id < b.id ? -1 : 1)); let ourIndex = sorted.findIndex((player) => player.id === ID); return sorted[(ourIndex + 1) % sorted.length]; } }