/** * intro.js * Introduction screen — two-step flow: * Step 1: select 1 or 2 players * Step 2: enter name(s), then start * Owns the #intro-screen element. */ const IntroScreen = (() => { function show() { document.querySelectorAll('.screen').forEach(s => s.classList.remove('active')); document.getElementById('intro-screen').classList.add('active'); renderStep1(); } /* ── Shared header (logo + rules) ─────────────────────────── */ function headerHTML() { return `

Help the Doctor collect kidneys from the supply belts and deliver them to the laboratory for analysis.

Bring special medication to the patient to earn bonus points!

Kidney delivered to lab+1 pt
Special med to patient+5 pts
Kidney dropped−1 pt
Special kidney dropped−3 pts

Carry up to 5 kidneys · 1 in 7 chance is special · 3 minutes on the clock

Move with ↑↓←→ or W A S D

Stand at column 0 (left) to collect · at column 3 (right) to deposit / pickup / deliver

`; } /* ── Step 1: player count selection ───────────────────────── */ function renderStep1() { const el = document.getElementById('intro-screen'); el.innerHTML = `
${headerHTML()}

SELECT NUMBER OF PLAYERS

`; el.querySelector('#btn-1p').addEventListener('click', () => renderStep2(1)); el.querySelector('#btn-2p').addEventListener('click', () => renderStep2(2)); } /* ── Step 2: name entry ────────────────────────────────────── */ function renderStep2(playerCount) { const el = document.getElementById('intro-screen'); const nameFields = playerCount === 2 ? `
` : `
`; el.innerHTML = `
${headerHTML()}
${playerCount === 2 ? '2 PLAYER MODE' : '1 PLAYER MODE'}
${nameFields}
`; const p1Input = el.querySelector('#name-p1'); p1Input.focus(); el.querySelector('#back-btn').addEventListener('click', renderStep1); el.querySelector('#start-btn').addEventListener('click', () => startGame(playerCount)); // Enter on last field starts game const lastInput = el.querySelector(playerCount === 2 ? '#name-p2' : '#name-p1'); lastInput.addEventListener('keydown', e => { if (e.key === 'Enter') startGame(playerCount); }); } /* ── Launch game ───────────────────────────────────────────── */ function startGame(playerCount) { const el = document.getElementById('intro-screen'); const name1 = (el.querySelector('#name-p1').value.trim() || 'DOCTOR').toUpperCase(); const name2 = playerCount === 2 ? ((el.querySelector('#name-p2').value.trim() || 'NURSE').toUpperCase()) : null; document.querySelectorAll('.screen').forEach(s => s.classList.remove('active')); document.getElementById('game-screen').classList.add('active'); Game.init(name1, name2); } return { show }; })();