Živý režim po vzoru Kahootu (OpenSpec změna `zivy-rezim-trida`, nová capability `live-room`). - Schválená učitelka založí nad publikovanou sadou místnost (režim Psaní / Výběr A–D, délka, časový limit); tabule ukáže 6místný kód a QR. - Připojení kódem a přezdívkou; přihlášeným se kola zapisují do DB a žebříčků, ostatní mají body jen v místnosti. - Synchronní průběh řízený učitelkou: otázka končí limitem nebo odpovědí všech, pak vyhodnocení a průběžné pořadí, na konci stupně vítězů. - Bodování shodné s běžnou hrou včetně bonusu za sérii. - Moderace (vyhození hráče, zamčení místnosti), rate limit neúspěšných pokusů o kód podle session i IP, aktualizace pollingem. - Specifikace synchronizovány do `openspec/specs/live-room/`, změna archivována. Closes #23 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_013nPfHY7UqPQTQpoHNjSQ4K Reviewed-on: #27 Co-authored-by: David Spáčil <spacildavi@gmail.com>
637 lines
32 KiB
HTML
637 lines
32 KiB
HTML
<!doctype html>
|
||
<html lang="cs">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
||
<title>Prototyp – hra pro třídu</title>
|
||
<style>
|
||
/* Prototyp živé hry (úkol 2.2 změny zivy-rezim-trida). Tokeny Arény
|
||
převzaté z poznavacky/static/css/app.css. Do aplikace se nenasazuje. */
|
||
:root {
|
||
--f: "Baloo 2", system-ui, sans-serif;
|
||
--bg: #1a1e3a; --surface: #262c55; --fg: #fff; --muted: #b8bde6;
|
||
--line: #3a4178; --accent: #ffd23f; --accent-fg: #1a1e3a;
|
||
--shadow: rgba(0,0,0,.35);
|
||
--ok: #18804b; --part: #f5a524; --bad: #c4303a;
|
||
--opt-a: #d13a40; --opt-b: #3e63dd; --opt-c: #f5a524; --opt-d: #0b7f72;
|
||
--on-opt-c: #1a1e3a;
|
||
--r: 18px; --rs: 12px;
|
||
}
|
||
* { box-sizing: border-box; }
|
||
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
|
||
font-family: var(--f); }
|
||
button { font: inherit; cursor: pointer; border: 0; }
|
||
.devbar { position: fixed; z-index: 50; top: 0; left: 0; right: 0;
|
||
display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
|
||
padding: 4px 8px; background: #0d1026; font-size: 13px; }
|
||
.devbar a { color: var(--muted); text-decoration: none; padding: 2px 8px;
|
||
border-radius: 8px; }
|
||
.devbar a.on { background: var(--accent); color: var(--accent-fg); }
|
||
.devbar .sep { flex: 1; }
|
||
.devbar button { background: var(--surface); color: var(--fg);
|
||
padding: 2px 8px; border-radius: 8px; font-size: 13px; }
|
||
.view { position: fixed; inset: 28px 0 0 0; overflow: hidden; }
|
||
[hidden] { display: none !important; }
|
||
|
||
/* ---------- společné kousky ---------- */
|
||
.shape { display: inline-grid; place-items: center; flex: none;
|
||
width: 1.6em; height: 1.6em; border-radius: .35em;
|
||
background: rgba(255,255,255,.25); }
|
||
.shape svg { width: 55%; height: 55%; fill: currentColor; }
|
||
.o0 { background: var(--opt-a); } .o1 { background: var(--opt-b); }
|
||
.o2 { background: var(--opt-c); color: var(--on-opt-c); }
|
||
.o3 { background: var(--opt-d); }
|
||
.btn { background: var(--accent); color: var(--accent-fg); font-weight: 800;
|
||
border-radius: var(--rs); padding: .5em 1.2em;
|
||
box-shadow: 0 5px 0 #b38f13; }
|
||
.btn:active { box-shadow: 0 2px 0 #b38f13; transform: translateY(3px); }
|
||
.btn-ghost { background: var(--surface); color: var(--fg);
|
||
box-shadow: 0 5px 0 var(--shadow); }
|
||
|
||
/* ---------- tabule (16:9, čte se z lavic) ---------- */
|
||
.board { font-size: clamp(14px, 1.6vw, 34px); display: grid;
|
||
grid-template-rows: auto 1fr auto; height: 100%; padding: 1.2vw 1.6vw;
|
||
gap: 1vw; }
|
||
.b-top { display: flex; align-items: center; gap: 1em; font-weight: 700; }
|
||
.b-top .set { color: var(--muted); }
|
||
.b-top .k { margin-left: auto; background: var(--surface);
|
||
padding: .1em .7em; border-radius: 99px; }
|
||
.b-top .code-chip { background: var(--surface); padding: .1em .7em;
|
||
border-radius: 99px; letter-spacing: .1em; }
|
||
.b-foot { display: flex; gap: .6em; align-items: center; }
|
||
.b-foot .spacer { flex: 1; }
|
||
.b-foot .btn { font-size: .8em; }
|
||
.b-main { min-height: 0; position: relative; }
|
||
|
||
/* lobby */
|
||
.lobby { display: grid; grid-template-columns: auto 1fr; gap: 2.5vw;
|
||
height: 100%; align-items: start; }
|
||
.join-card { background: #fff; color: var(--bg); border-radius: var(--r);
|
||
padding: 1.2em; text-align: center; width: 19em; }
|
||
.join-card .lbl { font-size: .8em; font-weight: 700; }
|
||
.join-card .url { font-size: 1.1em; font-weight: 800; }
|
||
.join-card .code { font-size: 3.4em; font-weight: 800; letter-spacing: .08em;
|
||
line-height: 1.1; }
|
||
.join-card .qr { width: 11em; height: 11em; margin: .5em auto 0;
|
||
background:
|
||
repeating-conic-gradient(var(--bg) 0 25%, #fff 0 50%) 0 0 / 1.1em 1.1em;
|
||
border: .6em solid #fff; outline: .25em solid var(--bg); }
|
||
.players h2 { margin: 0 0 .4em; font-size: 1.4em; }
|
||
.players .count { color: var(--accent); }
|
||
.chips { display: flex; flex-wrap: wrap; gap: .5em; }
|
||
.chip { display: inline-flex; align-items: center; gap: .4em;
|
||
background: var(--surface); border-radius: 99px; padding: .25em .4em .25em .9em;
|
||
font-weight: 700; animation: pop .25s ease-out; }
|
||
.chip button { background: rgba(255,255,255,.12); color: var(--fg);
|
||
width: 1.5em; height: 1.5em; border-radius: 99px; font-size: .8em; }
|
||
.chip button:hover { background: var(--bad); }
|
||
.locked-note { color: var(--accent); font-weight: 700; margin-top: .6em; }
|
||
@keyframes pop { from { transform: scale(.7); opacity: 0; } }
|
||
@media (prefers-reduced-motion: reduce) { * { animation: none !important;
|
||
transition: none !important; } }
|
||
|
||
/* otázka – varianty A a B */
|
||
.q-layout { display: grid; grid-template-columns: 1fr 11em; gap: 1.2vw;
|
||
height: 100%; }
|
||
.q-photo { position: relative; border-radius: var(--r); overflow: hidden;
|
||
background: #000; min-height: 0; }
|
||
.q-photo img { width: 100%; height: 100%; object-fit: contain; display: block; }
|
||
.q-side { display: flex; flex-direction: column; gap: 1em; align-items: stretch; }
|
||
.timer { position: relative; aspect-ratio: 1; }
|
||
.timer svg { width: 100%; height: 100%; transform: rotate(-90deg); }
|
||
.timer circle { fill: none; stroke-width: 7; }
|
||
.timer .bg { stroke: var(--line); }
|
||
.timer .fg { stroke: var(--accent); stroke-linecap: round;
|
||
transition: stroke-dashoffset .25s linear; }
|
||
.timer .num { position: absolute; inset: 0; display: grid; place-items: center;
|
||
font-size: 3em; font-weight: 800; }
|
||
.stat-box { background: var(--surface); border-radius: var(--rs); padding: .5em;
|
||
text-align: center; }
|
||
.stat-box b { display: block; font-size: 2.2em; line-height: 1; }
|
||
.stat-box span { color: var(--muted); font-size: .8em; }
|
||
.opts-row { display: grid; grid-template-columns: 1fr 1fr; gap: .6em;
|
||
margin-top: .8em; }
|
||
.b-opt { display: flex; align-items: center; gap: .6em; padding: .45em .7em;
|
||
border-radius: var(--rs); font-weight: 800; font-size: 1.15em;
|
||
box-shadow: 0 4px 0 var(--shadow); }
|
||
.b-opt.dim { opacity: .35; }
|
||
.b-opt.ok { outline: .2em solid #fff; outline-offset: -.2em; }
|
||
.b-opt .cnt { margin-left: auto; font-size: 1.2em; }
|
||
.prep-banner { position: absolute; left: 50%; bottom: 1em;
|
||
transform: translateX(-50%); background: rgba(13,16,38,.85);
|
||
padding: .3em 1em; border-radius: 99px; font-weight: 800; font-size: 1.3em; }
|
||
|
||
/* vyhodnocení */
|
||
.reveal { display: grid; grid-template-columns: 16em 1fr 15em; gap: 1.4vw;
|
||
height: 100%; align-items: start; }
|
||
.reveal.no-top { grid-template-columns: 18em 1fr; }
|
||
.rv-photo { border-radius: var(--r); overflow: hidden; background: #000; }
|
||
.rv-photo img { width: 100%; aspect-ratio: 4/3; object-fit: cover;
|
||
display: block; }
|
||
.rv-name { font-size: 1.9em; font-weight: 800; line-height: 1.1;
|
||
margin: .4em 0 0; }
|
||
.rv-latin { color: var(--muted); font-style: italic; }
|
||
.dist { display: flex; flex-direction: column; gap: .6em; }
|
||
.bars { display: grid; grid-template-columns: repeat(4, 1fr); gap: .8em;
|
||
align-items: end; height: 12em; }
|
||
.bars.v3 { grid-template-columns: repeat(3, 1fr); }
|
||
.bar { display: flex; flex-direction: column; justify-content: flex-end;
|
||
align-items: center; height: 100%; gap: .3em; }
|
||
.bar .fill { width: 100%; border-radius: .4em .4em 0 0; min-height: .3em;
|
||
box-shadow: 0 4px 0 var(--shadow); transition: height .5s ease-out; }
|
||
.bar .n { font-size: 1.6em; font-weight: 800; }
|
||
.bar.dim .fill { opacity: .35; }
|
||
.bar.ok .n::after { content: " ✓"; }
|
||
.bar .lbl { display: flex; align-items: center; gap: .3em; font-weight: 700;
|
||
font-size: .85em; text-align: center; }
|
||
.top h3 { margin: 0 0 .3em; color: var(--muted); font-size: 1em; }
|
||
.top ol { list-style: none; margin: 0; padding: 0; display: grid; gap: .35em; }
|
||
.top li { display: flex; gap: .5em; align-items: center;
|
||
background: var(--surface); border-radius: var(--rs); padding: .3em .6em;
|
||
font-weight: 700; }
|
||
.top li .pos { width: 1.4em; color: var(--accent); font-weight: 800; }
|
||
.top li .pts { margin-left: auto; }
|
||
.top li .up { color: #5ad596; font-size: .8em; }
|
||
|
||
/* varianta B – samostatné pořadí */
|
||
.ranking { max-width: 34em; margin: 0 auto; font-size: 1.3em; }
|
||
.ranking h2 { text-align: center; margin: 0 0 .6em; }
|
||
|
||
/* varianta C – fotka přes celou plochu */
|
||
.full { position: absolute; inset: 0; border-radius: var(--r);
|
||
overflow: hidden; background: #000; }
|
||
.full img { width: 100%; height: 100%; object-fit: cover; display: block; }
|
||
.full .overlay-top { position: absolute; top: .8em; right: .8em; display: flex;
|
||
gap: .6em; align-items: center; }
|
||
.full .overlay-top .timer { width: 6em; background: rgba(13,16,38,.75);
|
||
border-radius: 99px; }
|
||
.full .overlay-top .timer .num { font-size: 2em; }
|
||
.full .overlay-top .stat-box { background: rgba(13,16,38,.75); }
|
||
.full .strip { position: absolute; left: .8em; right: .8em; bottom: .8em;
|
||
display: grid; grid-template-columns: repeat(4, 1fr); gap: .6em; }
|
||
.full .strip.v3 { grid-template-columns: repeat(3, 1fr); }
|
||
.full .side-top { position: absolute; top: .8em; left: .8em; width: 15em;
|
||
background: rgba(13,16,38,.82); border-radius: var(--r); padding: .7em; }
|
||
.full .name-card { position: absolute; left: 50%; top: 40%;
|
||
transform: translate(-50%, -50%); background: rgba(13,16,38,.88);
|
||
border-radius: var(--r); padding: .6em 1.4em; text-align: center; }
|
||
.full .name-card .rv-name { margin: 0; }
|
||
|
||
/* konec */
|
||
.podium { display: flex; justify-content: center; align-items: flex-end;
|
||
gap: 1.5vw; height: 100%; padding-top: 1em; }
|
||
.step { display: flex; flex-direction: column; align-items: center;
|
||
width: 12em; }
|
||
.step .who { font-size: 1.5em; font-weight: 800; text-align: center; }
|
||
.step .pts { color: var(--muted); margin-bottom: .4em; }
|
||
.step .block { width: 100%; border-radius: var(--r) var(--r) 0 0;
|
||
display: grid; place-items: start center; padding-top: .4em;
|
||
font-size: 3em; font-weight: 800; color: var(--accent-fg); }
|
||
.p1 .block { height: 10em; background: var(--accent); font-size: 3.6em; }
|
||
.p2 .block { height: 7em; background: #c9cde8; }
|
||
.p3 .block { height: 5em; background: #e0a060; }
|
||
|
||
/* ---------- telefon ---------- */
|
||
.phone-wrap { display: grid; place-items: center; height: 100%;
|
||
background: #0d1026; }
|
||
.phone { width: min(100vw, 390px); height: min(100%, 780px);
|
||
background: var(--bg); position: relative; overflow: hidden;
|
||
display: flex; flex-direction: column; font-size: 17px; }
|
||
@media (min-width: 500px) { .phone { border-radius: 28px;
|
||
border: 6px solid #2b3160; } }
|
||
.ph-top { display: flex; align-items: center; gap: .5em; padding: .7em 1em;
|
||
font-weight: 700; }
|
||
.ph-top .me { flex: 1; }
|
||
.ph-top .score { background: var(--surface); padding: .1em .7em;
|
||
border-radius: 99px; }
|
||
.ph-body { flex: 1; display: flex; flex-direction: column; padding: 0 1em 1em;
|
||
min-height: 0; }
|
||
.center { flex: 1; display: flex; flex-direction: column; align-items: center;
|
||
justify-content: center; text-align: center; gap: .6em; }
|
||
.big { font-size: 2.4em; font-weight: 800; line-height: 1.1; }
|
||
.muted { color: var(--muted); }
|
||
.field { width: 100%; font: inherit; font-size: 1.3em; padding: .55em .8em;
|
||
border-radius: var(--rs); border: 2px solid var(--line);
|
||
background: var(--surface); color: var(--fg); }
|
||
.field:focus { outline: 3px solid var(--accent); border-color: transparent; }
|
||
.code-field { letter-spacing: .3em; text-align: center; font-weight: 800; }
|
||
.form { display: flex; flex-direction: column; gap: .7em; width: 100%; }
|
||
.form .btn { font-size: 1.2em; padding: .7em; }
|
||
.count-ring { width: 7em; height: 7em; border-radius: 50%;
|
||
border: .5em solid var(--accent); display: grid; place-items: center;
|
||
font-size: 1.6em; font-weight: 800; }
|
||
.ph-opts { flex: 1; display: grid; grid-template-columns: 1fr 1fr; gap: .7em; }
|
||
.ph-opts.n3 .ph-opt:last-child { grid-column: span 2; }
|
||
.ph-opt { border-radius: var(--r); display: grid; place-items: center;
|
||
box-shadow: 0 6px 0 var(--shadow); color: #fff; min-height: 6em; }
|
||
.ph-opt svg { width: 38%; max-width: 6em; fill: currentColor; }
|
||
.ph-opt:active { transform: translateY(3px); box-shadow: 0 3px 0 var(--shadow); }
|
||
.ph-opt .sr { position: absolute; width: 1px; height: 1px; overflow: hidden;
|
||
clip: rect(0 0 0 0); }
|
||
.ph-write { margin-top: auto; display: flex; gap: .5em; }
|
||
.ph-write .btn { font-size: 1.4em; padding: 0 .8em; }
|
||
.ph-prompt { flex: 1; display: grid; place-items: center; text-align: center; }
|
||
.verdict { width: 100%; border-radius: var(--r); padding: 1.2em 1em;
|
||
text-align: center; }
|
||
.verdict.spravne { background: var(--ok); }
|
||
.verdict.castecne { background: var(--part); color: var(--accent-fg); }
|
||
.verdict.spatne { background: var(--bad); }
|
||
.verdict .v { font-size: 2em; font-weight: 800; }
|
||
.verdict .pts { font-size: 1.4em; font-weight: 800; }
|
||
.rows { width: 100%; display: grid; gap: .4em; margin-top: .8em; }
|
||
.rows div { display: flex; justify-content: space-between;
|
||
background: var(--surface); border-radius: var(--rs); padding: .45em .8em; }
|
||
.rows b { font-weight: 800; }
|
||
.ph-sim { position: absolute; top: .75em; left: 50%;
|
||
transform: translateX(-50%); }
|
||
.ph-sim button { background: rgba(255,255,255,.1); color: var(--muted);
|
||
border-radius: 8px; padding: .2em .6em; font-size: .75em; }
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<nav class="devbar" aria-label="Přepínání prototypu">
|
||
<strong>Prototyp hry pro třídu</strong>
|
||
<a href="#tabule-a" data-v="tabule-a">Tabule A · jedna obrazovka</a>
|
||
<a href="#tabule-b" data-v="tabule-b">Tabule B · dvě obrazovky</a>
|
||
<a href="#tabule-c" data-v="tabule-c">Tabule C · fotka přes plochu</a>
|
||
<a href="#telefon-abcd" data-v="telefon-abcd">Telefon A–D</a>
|
||
<a href="#telefon-psani" data-v="telefon-psani">Telefon Psaní</a>
|
||
<span class="sep"></span>
|
||
<span id="sim-tools">
|
||
<button type="button" id="sim-join">+ hráč</button>
|
||
<button type="button" id="sim-answer">všichni odpoví</button>
|
||
<button type="button" id="sim-reset">od začátku</button>
|
||
</span>
|
||
</nav>
|
||
<main id="board-view" class="view" hidden></main>
|
||
<main id="phone-view" class="view" hidden></main>
|
||
|
||
<script type="module">
|
||
// Syntetická data: fotky z img/ (licence v README.md), vymyšlené přezdívky.
|
||
const QUESTIONS = [
|
||
{ img: "img/parus-major.webp", name: "Sýkora koňadra", latin: "Parus major",
|
||
opts: ["Sýkora koňadra", "Sýkora modřinka", "Brhlík lesní", "Pěnkava obecná"], ok: 0 },
|
||
{ img: "img/erinaceus-europaeus.webp", name: "Ježek západní",
|
||
latin: "Erinaceus europaeus",
|
||
opts: ["Krtek obecný", "Ježek západní", "Rejsek obecný", "Plch velký"], ok: 1 },
|
||
{ img: "img/ciconia-ciconia.webp", name: "Čáp bílý", latin: "Ciconia ciconia",
|
||
opts: ["Volavka popelavá", "Čáp černý", "Čáp bílý"], ok: 2 },
|
||
{ img: "img/aglais-io.webp", name: "Babočka paví oko", latin: "Aglais io",
|
||
opts: ["Babočka admirál", "Otakárek fenyklový", "Žluťásek řešetlákový",
|
||
"Babočka paví oko"], ok: 3 },
|
||
{ img: "img/salamandra-salamandra.webp", name: "Mlok skvrnitý",
|
||
latin: "Salamandra salamandra",
|
||
opts: ["Mlok skvrnitý", "Čolek obecný", "Ještěrka obecná", "Slepýš křehký"], ok: 0 },
|
||
];
|
||
const NICKS = ["Rys", "Liška", "Sova", "Datel", "Mravenec", "Jezevec", "Kuna",
|
||
"Sýček", "Bobr", "Vydra", "Čáp", "Krtek", "Výr", "Ještěrka", "Srnka",
|
||
"Veverka", "Kos", "Žluna", "Lasička", "Tchoř"];
|
||
const SHAPES = [
|
||
'<polygon points="5,0.5 9.5,9.5 0.5,9.5"/>',
|
||
'<polygon points="5,0 10,5 5,10 0,5"/>',
|
||
'<circle cx="5" cy="5" r="4.6"/>',
|
||
'<rect x="0.8" y="0.8" width="8.4" height="8.4"/>',
|
||
];
|
||
const SHAPE_NAMES = ["trojúhelník", "kosočtverec", "kruh", "čtverec"];
|
||
const LIMIT = 20, PREP = 3, CODE = "482 917";
|
||
const shape = (i, cls = "shape") =>
|
||
`<span class="${cls}"><svg viewBox="0 0 10 10" aria-hidden="true">${SHAPES[i]}</svg></span>`;
|
||
const esc = (s) => String(s).replace(/[&<>"]/g, (c) =>
|
||
({ "&": "&", "<": "<", ">": ">", '"': """ })[c]);
|
||
const fmt = new Intl.NumberFormat("cs-CZ");
|
||
|
||
// ---------------- simulace místnosti (tabule) ----------------
|
||
let S;
|
||
function resetSim() {
|
||
S = { phase: "lobby", q: 0, players: [], locked: false, shownAt: 0,
|
||
answers: {}, rankStep: false, prevRank: {} };
|
||
for (let i = 0; i < 8; i++) addPlayer();
|
||
}
|
||
function addPlayer() {
|
||
if (S.locked || S.players.length >= NICKS.length) return;
|
||
const name = NICKS[S.players.length];
|
||
S.players.push({ id: name, name, score: 0, streak: 0,
|
||
skill: 0.45 + Math.random() * 0.5 });
|
||
}
|
||
const now = () => performance.now() / 1000;
|
||
function q() { return QUESTIONS[S.q]; }
|
||
function startQuestion(i) {
|
||
S.q = i; S.phase = "priprava"; S.shownAt = now(); S.answers = {};
|
||
S.rankStep = false;
|
||
S.prevRank = Object.fromEntries(ranking().map((p, k) => [p.id, k]));
|
||
for (const p of S.players) {
|
||
p.planAt = PREP + 1 + Math.random() * (LIMIT - 4) * (1.2 - p.skill);
|
||
}
|
||
}
|
||
function answer(p, idx, at) {
|
||
if (S.answers[p.id]) return;
|
||
const correct = idx === q().ok;
|
||
const t = at;
|
||
p.streak = correct ? p.streak + 1 : 0;
|
||
const ratio = t <= 3.5 ? 1 : Math.max(0.3, 1 - (t - 3.5) / 11.5 * 0.7);
|
||
const base = correct ? Math.round(500 * ratio) : 0;
|
||
const bonus = correct ? Math.floor(500 * Math.min(p.streak - 1, 5) * 10 / 100) : 0;
|
||
p.score += base + bonus;
|
||
S.answers[p.id] = { idx, pts: base + bonus };
|
||
}
|
||
function closeQuestion() { S.phase = "vyhodnoceni"; }
|
||
function tick() {
|
||
const t = now() - S.shownAt;
|
||
if (S.phase === "priprava" && t >= PREP) S.phase = "otazka";
|
||
if (S.phase === "otazka") {
|
||
for (const p of S.players) {
|
||
if (!S.answers[p.id] && t >= p.planAt) {
|
||
const idx = Math.random() < p.skill ? q().ok
|
||
: Math.floor(Math.random() * q().opts.length);
|
||
answer(p, idx, t);
|
||
}
|
||
}
|
||
if (t >= PREP + LIMIT || S.players.every((p) => S.answers[p.id])) closeQuestion();
|
||
}
|
||
}
|
||
const ranking = () => [...S.players].sort((a, b) => b.score - a.score);
|
||
|
||
// ---------------- vykreslení tabule ----------------
|
||
const boardView = document.getElementById("board-view");
|
||
let variant = "a";
|
||
|
||
function timerSvg(left, total) {
|
||
const L = 2 * Math.PI * 44;
|
||
const off = L * (1 - Math.max(0, left) / total);
|
||
return `<div class="timer"><svg viewBox="0 0 100 100"><circle class="bg" cx="50" cy="50" r="44"/>
|
||
<circle class="fg" cx="50" cy="50" r="44" stroke-dasharray="${L}" stroke-dashoffset="${off}"/></svg>
|
||
<span class="num">${Math.ceil(Math.max(0, left))}</span></div>`;
|
||
}
|
||
function topList(n = 5) {
|
||
const r = ranking().slice(0, n);
|
||
return `<div class="top"><h3>Průběžné pořadí</h3><ol>${r.map((p, k) => {
|
||
const prev = S.prevRank[p.id];
|
||
const up = prev !== undefined && prev > k ? `<span class="up">▲${prev - k}</span>` : "";
|
||
return `<li><span class="pos">${k + 1}.</span>${esc(p.name)} ${up}<span class="pts">${fmt.format(p.score)}</span></li>`;
|
||
}).join("")}</ol></div>`;
|
||
}
|
||
function counts() {
|
||
const c = q().opts.map(() => 0);
|
||
for (const a of Object.values(S.answers)) c[a.idx]++;
|
||
return c;
|
||
}
|
||
function boardOpts({ reveal = false, cls = "opts-row" } = {}) {
|
||
const c = counts();
|
||
return `<div class="${cls}${q().opts.length === 3 ? " v3" : ""}">${q().opts.map((o, i) => {
|
||
const st = reveal ? (i === q().ok ? " ok" : " dim") : "";
|
||
return `<div class="b-opt o${i}${st}">${shape(i)}<span>${esc(o)}</span>${reveal ? `<span class="cnt">${c[i]}</span>` : ""}</div>`;
|
||
}).join("")}</div>`;
|
||
}
|
||
function answeredBox() {
|
||
return `<div class="stat-box"><b>${Object.keys(S.answers).length}/${S.players.length}</b><span>odpovědělo</span></div>`;
|
||
}
|
||
function bars() {
|
||
const c = counts(); const max = Math.max(1, ...c);
|
||
return `<div class="bars${c.length === 3 ? " v3" : ""}">${c.map((n, i) => `
|
||
<div class="bar ${i === q().ok ? "ok" : "dim"}"><span class="n">${n}</span>
|
||
<span class="fill o${i}" style="height:${(n / max) * 80}%"></span>
|
||
<span class="lbl">${shape(i)}${esc(q().opts[i])}</span></div>`).join("")}</div>`;
|
||
}
|
||
|
||
function renderBoard() {
|
||
const t = now() - S.shownAt;
|
||
const top = `<header class="b-top"><span>Hra pro třídu</span>
|
||
<span class="set">Ptáci a další · Výběr A–D</span>
|
||
${S.phase !== "lobby" ? `<span class="code-chip">kód ${CODE}</span>` : ""}
|
||
${["priprava", "otazka", "vyhodnoceni"].includes(S.phase)
|
||
? `<span class="k">${S.q + 1} / ${QUESTIONS.length}</span>` : ""}</header>`;
|
||
let main = "", foot = "";
|
||
const end = `<button class="btn btn-ghost" data-act="end">Ukončit hru</button>`;
|
||
if (S.phase === "lobby") {
|
||
main = `<div class="lobby"><div class="join-card">
|
||
<div class="lbl">Na telefonu otevři</div><div class="url">poznavacky.skola.cz/zive</div>
|
||
<div class="lbl">a zadej kód</div><div class="code">${CODE}</div>
|
||
<div class="qr" role="img" aria-label="QR kód (v aplikaci skutečný)"></div></div>
|
||
<div class="players"><h2><span class="count">${S.players.length}</span> hráčů</h2>
|
||
<div class="chips">${S.players.map((p) => `<span class="chip">${esc(p.name)}
|
||
<button data-kick="${esc(p.id)}" aria-label="Vyhodit ${esc(p.name)}">✕</button></span>`).join("")}</div>
|
||
${S.locked ? `<p class="locked-note">🔒 Místnost je zamčená, noví hráči se nepřipojí.</p>` : ""}
|
||
</div></div>`;
|
||
foot = `<button class="btn btn-ghost" data-act="lock">${S.locked ? "Odemknout" : "Zamknout"}</button>
|
||
<span class="spacer"></span><button class="btn" data-act="start" ${S.players.length ? "" : "disabled"}>Start</button>`;
|
||
} else if (S.phase === "priprava" || S.phase === "otazka") {
|
||
const prep = S.phase === "priprava";
|
||
const left = prep ? PREP - t : PREP + LIMIT - t;
|
||
if (variant === "c") {
|
||
main = `<div class="full"><img src="${q().img}" alt="">
|
||
<div class="overlay-top">${prep ? "" : answeredBox()}${timerSvg(left, prep ? PREP : LIMIT)}</div>
|
||
${prep ? `<div class="prep-banner">Prohlédni si fotku… ${Math.ceil(left)}</div>`
|
||
: boardOpts({ cls: "strip" })}</div>`;
|
||
} else {
|
||
main = `<div class="q-layout"><div class="q-photo"><img src="${q().img}" alt="">
|
||
${prep ? `<div class="prep-banner">Prohlédni si fotku… ${Math.ceil(left)}</div>` : ""}</div>
|
||
<div class="q-side">${timerSvg(left, prep ? PREP : LIMIT)}${prep ? "" : answeredBox()}</div></div>`;
|
||
if (!prep) main = `<div style="display:grid;grid-template-rows:1fr auto;height:100%">${main}${boardOpts()}</div>`;
|
||
}
|
||
foot = `${end}<span class="spacer"></span>${prep ? "" : `<button class="btn btn-ghost" data-act="close">Ukončit otázku</button>`}`;
|
||
} else if (S.phase === "vyhodnoceni") {
|
||
const nameBlock = `<p class="rv-name">${esc(q().name)}</p><p class="rv-latin">${esc(q().latin)}</p>`;
|
||
if (variant === "b" && S.rankStep) {
|
||
main = `<div class="ranking"><h2>Pořadí po ${S.q + 1}. otázce</h2>${topList(5)}</div>`;
|
||
} else if (variant === "c") {
|
||
main = `<div class="full"><img src="${q().img}" alt="">
|
||
<div class="side-top">${topList(5)}</div>
|
||
<div class="name-card">${nameBlock}</div>
|
||
${boardOpts({ reveal: true, cls: "strip" })}</div>`;
|
||
} else {
|
||
main = `<div class="reveal${variant === "b" ? " no-top" : ""}">
|
||
<div><div class="rv-photo"><img src="${q().img}" alt=""></div>${nameBlock}</div>
|
||
<div class="dist">${bars()}</div>${variant === "a" ? topList(5) : ""}</div>`;
|
||
}
|
||
const last = S.q + 1 >= QUESTIONS.length;
|
||
const label = variant === "b" && !S.rankStep ? "Pořadí" : last ? "Výsledky" : "Další otázka";
|
||
foot = `${end}<span class="spacer"></span><button class="btn" data-act="next">${label}</button>`;
|
||
} else {
|
||
const r = ranking();
|
||
const step = (p, cls, n) => p ? `<div class="step ${cls}"><span class="who">${esc(p.name)}</span>
|
||
<span class="pts">${fmt.format(p.score)} b.</span><div class="block">${n}</div></div>` : "";
|
||
main = `<div class="podium">${step(r[1], "p2", 2)}${step(r[0], "p1", 1)}${step(r[2], "p3", 3)}</div>`;
|
||
foot = `<span class="spacer"></span><button class="btn btn-ghost" data-act="reset">Zpět na detail sady</button>`;
|
||
}
|
||
boardView.innerHTML = `<div class="board">${top}<section class="b-main">${main}</section>
|
||
<footer class="b-foot">${foot}</footer></div>`;
|
||
}
|
||
boardView.addEventListener("click", (e) => {
|
||
const kick = e.target.closest("[data-kick]");
|
||
if (kick) { S.players = S.players.filter((p) => p.id !== kick.dataset.kick); return renderBoard(); }
|
||
const act = e.target.closest("[data-act]")?.dataset.act;
|
||
if (!act) return;
|
||
if (act === "start") startQuestion(0);
|
||
if (act === "lock") S.locked = !S.locked;
|
||
if (act === "close") closeQuestion();
|
||
if (act === "end") S.phase = "konec";
|
||
if (act === "reset") resetSim();
|
||
if (act === "next") {
|
||
if (variant === "b" && !S.rankStep) S.rankStep = true;
|
||
else if (S.q + 1 < QUESTIONS.length) startQuestion(S.q + 1);
|
||
else S.phase = "konec";
|
||
}
|
||
renderBoard();
|
||
});
|
||
|
||
// ---------------- telefon ----------------
|
||
const phoneView = document.getElementById("phone-view");
|
||
let P;
|
||
let phoneMode = "abcd";
|
||
function resetPhone() {
|
||
P = { screen: "join", name: "", score: 0, streak: 0, q: 0, t0: 0,
|
||
last: null, rank: 5, players: 14 };
|
||
}
|
||
const WRITE_OK = (txt) => {
|
||
const n = txt.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase().trim();
|
||
const target = q2().name.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase();
|
||
if (n === target) return "spravne";
|
||
if (n && target.split(" ")[0] === n.split(" ")[0]) return "castecne";
|
||
return "spatne";
|
||
};
|
||
const q2 = () => QUESTIONS[P.q];
|
||
function phoneAnswer(verdict, answered = true) {
|
||
const t = now() - P.t0;
|
||
const base = phoneMode === "abcd" ? 500 : verdict === "castecne" ? 500 : 1000;
|
||
P.streak = verdict === "spravne" ? P.streak + 1 : 0;
|
||
const ratio = t <= 3.5 ? 1 : Math.max(0.3, 1 - (t - 3.5) / 11.5 * 0.7);
|
||
const pts = verdict === "spatne" ? 0 : Math.round(base * ratio);
|
||
const full = phoneMode === "abcd" ? 500 : 1000;
|
||
const bonus = verdict === "spravne" ? Math.floor(full * Math.min(P.streak - 1, 5) / 10) : 0;
|
||
P.score += pts + bonus;
|
||
P.last = { verdict, pts, bonus, answered };
|
||
P.rank = Math.max(1, Math.min(P.players, P.rank + (verdict === "spravne" ? -1 : 2)));
|
||
P.screen = "sent";
|
||
setTimeout(() => { if (P.screen === "sent") { P.screen = "result"; renderPhone(); } }, 1800);
|
||
}
|
||
function renderPhone() {
|
||
const t = now() - P.t0;
|
||
const head = P.screen === "join" ? "" : `<header class="ph-top"><span class="me">${esc(P.name)}</span>
|
||
<span class="score">${fmt.format(P.score)} b.</span></header>`;
|
||
let body = "";
|
||
const sim = (label, act) => `<div class="ph-sim"><button data-p="${act}">simulace: ${label}</button></div>`;
|
||
switch (P.screen) {
|
||
case "join":
|
||
body = `<div class="center"><p class="big">Hra pro třídu</p>
|
||
<form class="form" id="ph-join"><label class="muted" for="c">Kód z tabule</label>
|
||
<input id="c" class="field code-field" inputmode="numeric" value="482917" maxlength="6">
|
||
<label class="muted" for="n">Přezdívka</label>
|
||
<input id="n" class="field" maxlength="20" placeholder="např. Rys" required>
|
||
<button class="btn">Připojit se</button></form>
|
||
<p class="muted">Přihlášený hráč přezdívku nezadává, hraje pod svým jménem.</p></div>`;
|
||
break;
|
||
case "lobby":
|
||
body = `<div class="center"><p class="big">Jsi ve hře!</p>
|
||
<p>Tvoje jméno vidíš na tabuli.</p><p class="muted">Čekáme, až paní učitelka spustí hru…</p></div>
|
||
${sim("start hry", "start")}`;
|
||
break;
|
||
case "prep": {
|
||
const left = Math.ceil(PREP - t);
|
||
body = `<div class="center"><p class="muted">${P.q + 1}. otázka z ${QUESTIONS.length}</p>
|
||
<div class="count-ring">${Math.max(0, left)}</div><p class="big">Dívej se na tabuli</p></div>`;
|
||
break;
|
||
}
|
||
case "question":
|
||
if (phoneMode === "abcd") {
|
||
const n = q2().opts.length;
|
||
body = `<p class="muted" style="text-align:center;margin:.2em 0 .6em">Vyber tvar podle tabule</p>
|
||
<div class="ph-opts n${n}">${q2().opts.map((_, i) => `<button class="ph-opt o${i}" data-opt="${i}">
|
||
<svg viewBox="0 0 10 10" aria-hidden="true">${SHAPES[i]}</svg><span class="sr">${SHAPE_NAMES[i]}</span></button>`).join("")}</div>`;
|
||
} else {
|
||
body = `<div class="ph-prompt"><div><p class="big">Co je na fotce?</p>
|
||
<p class="muted">Česky nebo latinsky</p></div></div>
|
||
<form class="ph-write" id="ph-write"><input class="field" id="w" autocomplete="off"
|
||
autocapitalize="off" spellcheck="false" enterkeyhint="send" placeholder="Název"><button class="btn" aria-label="Odeslat">›</button></form>`;
|
||
}
|
||
body += sim("nestihnu", "timeout");
|
||
break;
|
||
case "sent":
|
||
body = `<div class="center"><p class="big">Odesláno ✓</p><p class="muted">Počkej na vyhodnocení…</p></div>`;
|
||
break;
|
||
case "result": {
|
||
const l = P.last;
|
||
const label = { spravne: "Správně!", castecne: "Skoro!", spatne: l.answered ? "Špatně" : "Nestihl(a) jsi" }[l.verdict];
|
||
body = `<div class="center" style="justify-content:flex-start;padding-top:1em">
|
||
<div class="verdict ${l.verdict}"><div class="v">${label}</div>
|
||
<div class="pts">+${fmt.format(l.pts + l.bonus)} b.</div></div>
|
||
<div class="rows">
|
||
<div><span>Body za otázku</span><b>${fmt.format(l.pts)}</b></div>
|
||
<div><span>Bonus za sérii</span><b>${l.bonus ? "+" + fmt.format(l.bonus) : "–"}</b></div>
|
||
<div><span>Série</span><b>${P.streak ? "🔥 " + P.streak : "0"}</b></div>
|
||
<div><span>Celkem</span><b>${fmt.format(P.score)}</b></div>
|
||
<div><span>Pořadí</span><b>${P.rank}. z ${P.players}</b></div></div>
|
||
<p class="muted">Správně: ${esc(q2().name)}</p></div>${sim("další otázka", "next")}`;
|
||
break;
|
||
}
|
||
case "end":
|
||
body = `<div class="center"><p class="muted">Konec hry</p><p class="big">${P.rank}. místo</p>
|
||
<p style="font-size:1.4em;font-weight:800">${fmt.format(P.score)} bodů</p>
|
||
<p class="muted">Tip: příště se před hrou přihlas, výsledky se ti
|
||
uloží do profilu a žebříčku. Tahle hra se už neuloží.</p>
|
||
<a class="btn btn-ghost" href="#telefon-${phoneMode}">Založit účet</a></div>`;
|
||
break;
|
||
}
|
||
phoneView.innerHTML = `<div class="phone-wrap"><div class="phone">${head}<div class="ph-body">${body}</div></div></div>`;
|
||
}
|
||
phoneView.addEventListener("submit", (e) => {
|
||
e.preventDefault();
|
||
if (e.target.id === "ph-join") {
|
||
P.name = document.getElementById("n").value.trim().slice(0, 20) || "Rys";
|
||
P.screen = "lobby";
|
||
} else if (e.target.id === "ph-write") {
|
||
phoneAnswer(WRITE_OK(document.getElementById("w").value));
|
||
}
|
||
renderPhone();
|
||
});
|
||
phoneView.addEventListener("click", (e) => {
|
||
const opt = e.target.closest("[data-opt]");
|
||
if (opt) { phoneAnswer(Number(opt.dataset.opt) === q2().ok ? "spravne" : "spatne"); return renderPhone(); }
|
||
const act = e.target.closest("[data-p]")?.dataset.p;
|
||
if (!act) return;
|
||
if (act === "start") { P.q = 0; P.t0 = now(); P.screen = "prep"; }
|
||
if (act === "timeout") phoneAnswer("spatne", false);
|
||
if (act === "next") {
|
||
if (P.q + 1 < QUESTIONS.length) { P.q++; P.t0 = now(); P.screen = "prep"; }
|
||
else P.screen = "end";
|
||
}
|
||
renderPhone();
|
||
});
|
||
|
||
// ---------------- přepínání a smyčka ----------------
|
||
const simTools = document.getElementById("sim-tools");
|
||
document.getElementById("sim-join").onclick = () => { addPlayer(); renderBoard(); };
|
||
document.getElementById("sim-answer").onclick = () => {
|
||
if (S.phase !== "otazka") return;
|
||
for (const p of S.players) if (!S.answers[p.id]) answer(p, Math.random() < p.skill ? q().ok : 1, now() - S.shownAt);
|
||
tick(); renderBoard();
|
||
};
|
||
document.getElementById("sim-reset").onclick = () => { resetSim(); resetPhone(); route(); };
|
||
|
||
function route() {
|
||
const v = location.hash.slice(1) || "tabule-a";
|
||
document.querySelectorAll(".devbar a").forEach((a) => a.classList.toggle("on", a.dataset.v === v));
|
||
const isBoard = v.startsWith("tabule");
|
||
boardView.hidden = !isBoard; phoneView.hidden = isBoard; simTools.hidden = !isBoard;
|
||
if (isBoard) { variant = v.slice(-1); renderBoard(); }
|
||
else {
|
||
const m = v.endsWith("psani") ? "psani" : "abcd";
|
||
if (m !== phoneMode) resetPhone();
|
||
phoneMode = m; renderPhone();
|
||
}
|
||
}
|
||
window.addEventListener("hashchange", route);
|
||
resetSim(); resetPhone(); route();
|
||
setInterval(() => {
|
||
if (!boardView.hidden && S.phase !== "lobby" && S.phase !== "konec") {
|
||
const before = S.phase; tick();
|
||
if (S.phase !== before || S.phase === "priprava" || S.phase === "otazka") renderBoard();
|
||
}
|
||
if (!phoneView.hidden && P.screen === "prep") {
|
||
if (now() - P.t0 >= PREP) P.screen = "question";
|
||
if (document.activeElement?.id !== "w") renderPhone();
|
||
}
|
||
}, 250);
|
||
</script>
|
||
</body>
|
||
</html>
|