fertig-classic-games/src/games/azul/AzulEndScreen.js

128 lines
8.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// AzulEndScreen.js — the final tally, shown after the end-game bonuses have
// been counted on the boards. A plaster card in a walnut frame with:
// • one row per player: rank, name, total, points by source (wall, floor,
// rows, columns, colours), their finished wall in miniature, a few stats
// • a points-by-round chart
// • Play Again · View Table (hide the card to look at the boards) · Leave
import { GAME_WIDTH, GAME_HEIGHT } from '../../config.js';
import { Button } from '../../ui/Button.js';
import { TILE_HEX, WALL_SIZE } from './AzulData.js';
import { finalRanking, cellColor } from './AzulLogic.js';
import { SERIF, DISPLAY, COBALT, INK } from './AzulArt.js';
import { frame, blocker } from './AzulDialogs.js';
export const SEAT_INK = [0x1d4f8f, 0xa7311d, 0xb07a12, 0x3c7a3a];
const hexStr = (n) => `#${n.toString(16).padStart(6, '0')}`;
export function showAzulEndScreen(scene, { depth, onPlayAgain, onLeave, onHidePortraits, onShowPortraits }) {
const gs = scene.gs;
const ranking = finalRanking(gs);
const objs = [];
const add = (o) => { objs.push(o); return o; };
const n = ranking.length;
const w = 1280, rowH = 92, chartH = 210;
const h = 150 + n * rowH + chartH + 96;
const x = GAME_WIDTH / 2 - w / 2, y = Math.max(16, GAME_HEIGHT / 2 - h / 2);
add(blocker(scene, depth - 1, 0.55));
add(frame(scene, x, y, w, h, depth));
const top = ranking[0];
const won = top.seat === 0;
const tied = ranking.length > 1 && ranking[1].score === top.score && ranking[1].rows === top.rows;
add(scene.add.text(x + w / 2, y + 52, tied ? 'A shared victory!' : won ? 'Your wall is the finest!' : `${top.name} wins the commission`, {
fontFamily: DISPLAY, fontSize: '34px', color: won ? '#b07a12' : COBALT,
}).setOrigin(0.5).setDepth(depth + 1));
// Column heads.
const cols = [
['Wall', 520], ['Floor', 590], ['Rows', 660], ['Columns', 740], ['Colours', 826], ['Total', 912],
];
const headY = y + 104;
cols.forEach(([t, cx]) => add(scene.add.text(x + cx, headY, t, { fontFamily: SERIF, fontSize: '14px', fontStyle: 'italic', color: '#6b5226' }).setOrigin(0.5).setDepth(depth + 1)));
add(scene.add.text(x + 1010, headY, 'Wall', { fontFamily: SERIF, fontSize: '14px', fontStyle: 'italic', color: '#6b5226' }).setOrigin(0.5).setDepth(depth + 1));
add(scene.add.text(x + 1150, headY, 'Stats', { fontFamily: SERIF, fontSize: '14px', fontStyle: 'italic', color: '#6b5226' }).setOrigin(0.5).setDepth(depth + 1));
ranking.forEach((r, i) => {
const p = gs.players[r.seat];
const st = p.stats;
const ry = y + 150 + i * rowH;
const g = add(scene.add.graphics().setDepth(depth + 1));
g.fillStyle(i === 0 ? 0xffe7a8 : r.seat === 0 ? 0xe6ecf4 : 0xffffff, i === 0 ? 0.85 : 0.5).fillRoundedRect(x + 36, ry - 38, w - 72, rowH - 12, 8);
g.fillStyle(SEAT_INK[r.seat % SEAT_INK.length], 1).fillRect(x + 36, ry - 38, 6, rowH - 12);
add(scene.add.text(x + 70, ry, `${i + 1}`, { fontFamily: 'Righteous', fontSize: '30px', color: i === 0 ? '#b07a12' : '#6b5226' }).setOrigin(0.5).setDepth(depth + 2));
add(scene.add.text(x + 100, ry - 12, r.seat === 0 ? `${p.name} (you)` : p.name, { fontFamily: SERIF, fontSize: '22px', color: INK }).setOrigin(0, 0.5).setDepth(depth + 2));
add(scene.add.text(x + 100, ry + 16, `${r.rows} row${r.rows === 1 ? '' : 's'} complete`, { fontFamily: SERIF, fontSize: '13px', fontStyle: 'italic', color: '#6b5226' }).setOrigin(0, 0.5).setDepth(depth + 2));
const b = gs.roundSummary?.[r.seat]?.endBonuses ?? { rowPts: 0, colPts: 0, colorPts: 0 };
const vals = [`+${st.placementPts}`, st.floorLost ? `−${st.floorLost}` : '0', `+${b.rowPts}`, `+${b.colPts}`, `+${b.colorPts}`];
vals.forEach((v, k) => add(scene.add.text(x + cols[k][1], ry, v, {
fontFamily: 'Righteous', fontSize: '20px', color: v.startsWith('−') ? '#a7311d' : INK,
}).setOrigin(0.5).setDepth(depth + 2)));
add(scene.add.text(x + cols[5][1], ry, `${p.score}`, { fontFamily: 'Righteous', fontSize: '30px', color: COBALT }).setOrigin(0.5).setDepth(depth + 2));
// Miniature wall.
const cs = 13, wx = x + 1010 - (WALL_SIZE * cs) / 2, wy = ry - (WALL_SIZE * cs) / 2;
const wg = add(scene.add.graphics().setDepth(depth + 2));
wg.fillStyle(0xc6b48c, 1).fillRect(wx - 2, wy - 2, WALL_SIZE * cs + 3, WALL_SIZE * cs + 3);
for (let rr = 0; rr < WALL_SIZE; rr++) for (let cc = 0; cc < WALL_SIZE; cc++) {
const col = cellColor(p, rr, cc);
wg.fillStyle(col ? TILE_HEX[col] : 0xeee4cc, 1).fillRect(wx + cc * cs, wy + rr * cs, cs - 1, cs - 1);
}
add(scene.add.text(x + 1080, ry, `set ${st.tilesPlaced} · floored ${st.tilesFloored}\nfirst ×${st.firstTaken} · best +${st.bestPlacement}`, {
fontFamily: SERIF, fontSize: '13px', color: INK, lineSpacing: 4,
}).setOrigin(0, 0.5).setDepth(depth + 2));
});
// ── points by round ──────────────────────────────────────────────────────────
const cx0 = x + 110, cy0 = y + 150 + n * rowH + 10, cw = w - 260, ch = chartH - 40;
const series = gs.players.map((p) => [0, ...p.stats.roundScores]);
const maxV = Math.max(10, ...series.flat());
const steps = Math.max(...series.map((s) => s.length)) - 1;
const cg = add(scene.add.graphics().setDepth(depth + 1));
cg.fillStyle(0xffffff, 0.45).fillRoundedRect(cx0 - 60, cy0 - 10, cw + 120, ch + 50, 8);
cg.lineStyle(1, 0x6b5226, 0.35);
const gridStep = maxV > 60 ? 20 : 10;
for (let v = 0; v <= maxV; v += gridStep) {
const yy = cy0 + ch - (v / maxV) * ch;
cg.lineBetween(cx0, yy, cx0 + cw, yy);
add(scene.add.text(cx0 - 10, yy, `${v}`, { fontFamily: SERIF, fontSize: '11px', color: '#6b5226' }).setOrigin(1, 0.5).setDepth(depth + 2));
}
const xAt = (k) => cx0 + (steps ? (k / steps) * cw : 0);
const lastRound = gs.round;
for (let k = 0; k <= steps; k++) {
const label = k === 0 ? 'start' : k <= lastRound ? `R${k}` : 'bonus';
add(scene.add.text(xAt(k), cy0 + ch + 14, label, { fontFamily: SERIF, fontSize: '12px', fontStyle: 'italic', color: '#6b5226' }).setOrigin(0.5).setDepth(depth + 2));
}
series.forEach((s, seat) => {
const col = SEAT_INK[seat % SEAT_INK.length];
cg.lineStyle(seat === 0 ? 4 : 2.5, col, 0.95);
cg.beginPath();
s.forEach((v, k) => { const px = xAt(k), py = cy0 + ch - (v / maxV) * ch; if (k) cg.lineTo(px, py); else cg.moveTo(px, py); });
cg.strokePath();
s.forEach((v, k) => cg.fillStyle(col, 1).fillCircle(xAt(k), cy0 + ch - (v / maxV) * ch, seat === 0 ? 4.5 : 3.5));
add(scene.add.text(xAt(steps) + 12, cy0 + ch - (s[s.length - 1] / maxV) * ch, gs.players[seat].name, {
fontFamily: SERIF, fontSize: '12px', color: hexStr(col),
}).setOrigin(0, 0.5).setDepth(depth + 2));
});
// ── buttons ──────────────────────────────────────────────────────────────────
const by = y + h - 50;
let hidden = false;
const panelObjs = objs.slice();
const viewBtn = new Button(scene, x + w / 2, by, 'View Table', () => {
hidden = !hidden;
panelObjs.forEach((o) => o.setVisible?.(!hidden));
if (panelObjs[0].input) panelObjs[0].input.enabled = !hidden; // the click blocker
viewBtn.setLabel(hidden ? 'Show Results' : 'View Table');
viewBtn.setPosition(hidden ? GAME_WIDTH / 2 : x + w / 2, hidden ? 652 : by);
if (hidden) onShowPortraits?.(); else onHidePortraits?.();
}, { width: 220, height: 48, fontSize: 18, bg: 0x5a3820 }).setDepth(depth + 3);
add(viewBtn);
add(new Button(scene, x + w / 2 - 260, by, 'Play Again', () => onPlayAgain(), { width: 220, height: 48, fontSize: 19, bg: 0x1d4f8f }).setDepth(depth + 3));
add(new Button(scene, x + w / 2 + 260, by, 'Leave', () => onLeave(), { width: 220, height: 48, fontSize: 19, bg: 0x7a2a1a }).setDepth(depth + 3));
onHidePortraits?.();
// Fade in.
panelObjs.forEach((o) => { if (o.setAlpha) { const a = o.alpha; o.setAlpha(0); scene.tweens.add({ targets: o, alpha: a, duration: 350 }); } });
return { close() { objs.forEach((o) => o.destroy?.()); } };
}