sistema de juego ajustado a evento CIAT

This commit is contained in:
2025-08-27 17:22:23 -06:00
parent acc700e50c
commit f4c6822857
5 changed files with 345 additions and 117 deletions

View File

@@ -519,6 +519,41 @@ export class GameRoom extends Room<GameState> {
broadcastDashboardUpdate();
}
private buildRoundSummary() {
const scores: any[] = [];
this.state.players.forEach((p, key) => {
const pavo = p.pavoTokens || 0;
const elote = p.eloteTokens || 0;
const points = (p.role === 'P2') ? (elote * 1 + pavo * 2) : (pavo * 1 + elote * 2);
scores.push({
sessionId: p.sessionId,
name: p.name,
role: p.role,
pavo,
elote,
points,
color: (p as any).color,
});
});
// Highest score first
scores.sort((a, b) => b.points - a.points);
return {
round: this.state.currentRound,
variant: this.state.currentVariant,
scores,
};
}
private resetTokensForNewRound() {
// Preserve shame tokens but reset pavo/elote according to role
const p1 = this.state.p1Id ? this.state.players.get(this.state.p1Id) : undefined;
const p2 = this.state.p2Id ? this.state.players.get(this.state.p2Id) : undefined;
if (p1) { p1.pavoTokens = 10; p1.eloteTokens = 0; }
if (p2) { p2.pavoTokens = 0; p2.eloteTokens = 10; }
// Notify dashboard of token reset
broadcastDashboardUpdate();
}
private resolveP2Action() {
const p1 = this.state.p1Id ? this.state.players.get(this.state.p1Id) : undefined;
const p2 = this.state.p2Id ? this.state.players.get(this.state.p2Id) : undefined;
@@ -914,7 +949,13 @@ export class GameRoom extends Room<GameState> {
}
private advanceRound() {
// Broadcast end-of-round summary BEFORE any resets so clients can render results
const summary = this.buildRoundSummary();
this.broadcast("roundEnded", summary);
if (this.state.currentRound < 3) {
// Prepare next round: reset tokens and round decisions
this.resetTokensForNewRound();
this.state.currentRound += 1;
this.state.resetRound();
// Update metadata with new round
@@ -928,6 +969,7 @@ export class GameRoom extends Room<GameState> {
// Notify dashboard of round advance
broadcastDashboardUpdate();
} else {
// Final round finished: finish the game
this.state.finishGame();
this.endGame();
}