remove(player) { let index = this.players[player.teamColor].indexOf(player); this.players[player.teamColor][index].status = 'disconnect'; this.getAllPlayerExceptThis(player).forEach((p) => { p.getMessage(`player ${player.name} disconnected.`); }); if (this.verifyOver(player.teamColor)) { this.gameOver(player.teamColor) } }
die(player) { let index = this.players[player.teamColor].indexOf(player); this.players[player.teamColor][index].status = 'die'; this.getAllPlayerExceptThis(player).forEach((p) => { p.getMessage(`player ${player.name} dead.`); }); if (this.verifyOver(player.teamColor)) { this.gameOver(player.teamColor) } }
getAllPlayerExceptThis(player) { let ret = []; for (let t ofObject.keys(this.players)) { for (let p ofthis.players[t]) { if (player !== p) { ret.push(p); } } } return ret; }
verifyOver(teamColor) { for (let player ofthis.players[teamColor]) { if (player.status === 'live') { returnfalse; } } returntrue }
gameOver(teamColor) { for (let t ofObject.keys(this.players)) { for (let player ofthis.players[t]) { if (teamColor === player.teamColor) { player.lose(); } else { player.win(); } } } } }