feat(geom11 ch2 final): Финал Раздела 2 (5 боссов + ачивка)

This commit is contained in:
Maxim Dolgolyov
2026-05-29 14:29:09 +03:00
parent 15de0d914f
commit 717ad3d0f5
+211 -2
View File
@@ -306,7 +306,8 @@ const ACH_LABELS = {
p3_done:"Пирамида освоено!",
p4_done:"Конус освоено!",
start:"Начало раздела 2!",
ch2_done:"Раздел 2 пройден!"
ch2_done:"Раздел 2 пройден!",
r2_done:"Мастер пирамиды и конуса"
};
function loadProgress(){
@@ -392,7 +393,7 @@ function buildParaSelector(){
}
const BUILT=new Set();
const BUILDERS = { p3:buildP3, p4:buildP4, final2:()=>buildStub('final2') };
const BUILDERS = { p3:buildP3, p4:buildP4, final2:buildFinal2 };
function ensureBuilt(id){ if(BUILT.has(id)) return; const fn=BUILDERS[id]; if(fn){ fn(); BUILT.add(id); } }
function goTo(id){
STATE.current=id; ensureBuilt(id);
@@ -1392,6 +1393,214 @@ function buildP4(){
wireReadBtn('p4');
}
/* ===== Финал Раздела 2 «Пирамида и конус» ===== */
function buildFinal2(){
const box = document.getElementById('final2-body');
if(!box) return;
let html = '';
/* Часть А — Шпаргалка раздела 2 (2 mini-карточки по числу § в разделе) */
html += '<div class="card">'
+ '<div class="card-header">'
+ '<div class="card-icon theory">' + ICONS.theory + '</div>'
+ '<div class="card-title">Шпаргалка раздела 2</div>'
+ '<div class="card-num">Итог</div>'
+ '</div>'
+ '<div class="card-body">'
+ '<p>Ключевые формулы обоих параграфов раздела в одном месте — пробеги глазами перед битвой с боссами.</p>'
+ '<div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(240px,1fr));gap:12px;margin-top:10px">'
+ '<div style="padding:12px 14px;background:var(--sec-acc-soft);border-radius:11px;border-left:3px solid var(--pri)">'
+ '<div style="display:flex;align-items:center;gap:8px;margin-bottom:6px">'
+ '<svg viewBox="0 0 24 24" fill="none" stroke="#059669" stroke-width="2" style="width:18px;height:18px"><polygon points="12,3 21,20 3,20"/><line x1="12" y1="3" x2="12" y2="20"/></svg>'
+ '<div style="font-family:\'Unbounded\',sans-serif;font-weight:700;color:var(--pri2);font-size:.92rem">§ 3 · Пирамида</div>'
+ '</div>'
+ '<div style="font-size:.94rem;line-height:1.55">$V=\\tfrac{1}{3}S_{осн}\\cdot h$ (любая). Правильная: $S_{бок}=\\tfrac{1}{2}P_{осн}\\cdot l$ ($l$ — апофема). Связи: $b^2=R^2+h^2$, $l^2=r^2+h^2$. Усечённая: $V=\\tfrac{1}{3}h(S_1+S_2+\\sqrt{S_1 S_2})$.</div>'
+ '</div>'
+ '<div style="padding:12px 14px;background:var(--sec-acc-soft);border-radius:11px;border-left:3px solid var(--pri)">'
+ '<div style="display:flex;align-items:center;gap:8px;margin-bottom:6px">'
+ '<svg viewBox="0 0 24 24" fill="none" stroke="#dc2626" stroke-width="2" style="width:18px;height:18px"><ellipse cx="12" cy="20" rx="8" ry="2.5"/><path d="M4 20L12 3L20 20"/></svg>'
+ '<div style="font-family:\'Unbounded\',sans-serif;font-weight:700;color:var(--pri2);font-size:.92rem">§ 4 · Конус</div>'
+ '</div>'
+ '<div style="font-size:.94rem;line-height:1.55">$V=\\tfrac{1}{3}\\pi R^2 h$, $S_{бок}=\\pi R l$, $S_{полн}=\\pi R(R+l)$. $l^2=R^2+h^2$. Развёртка — сектор радиуса $l$ с углом $\\varphi=\\tfrac{360°\\,R}{l}$. Усечённый: $V=\\tfrac{1}{3}\\pi h(R_1^2+R_2^2+R_1 R_2)$.</div>'
+ '</div>'
+ '</div>'
+ '</div>'
+ '</div>';
/* Часть Б — анонс 5 боссов */
html += '<div class="card">'
+ '<div class="card-header">'
+ '<div class="card-icon rule">' + ICONS.rule + '</div>'
+ '<div class="card-title">Боссы раздела 2</div>'
+ '<div class="card-num">5</div>'
+ '</div>'
+ '<div class="card-body">'
+ '<p>5 интегрированных задач — каждая комбинирует темы § 3 и § 4. За каждого побеждённого босса: <b>+10 XP, +18% к прогрессу</b>. Победишь всех — ачивка <b>«Мастер пирамиды и конуса»</b> и <b>+50 XP бонус</b>.</p>'
+ '<p style="font-size:.88rem;color:var(--muted);margin-top:6px">Для расчётов с $\\pi$ используй $\\pi\\approx 3{,}14$. Допуск ответа — $\\pm 0{,}05$ (для больших чисел — $\\pm 0{,}1$).</p>'
+ '</div>'
+ '</div>';
html += '<div id="r2-bosses-container"></div>';
/* Прогресс-итог + ачивка */
html += '<div style="margin-top:18px;padding:18px 20px;background:linear-gradient(135deg,var(--pri-soft),var(--sec-acc-soft));border-radius:14px;border:1.5px solid var(--pri);text-align:center" id="r2-final-summary">'
+ '<div style="font-family:\'Unbounded\',sans-serif;font-weight:800;color:var(--pri2);font-size:1.1rem;margin-bottom:6px">Прогресс по боссам</div>'
+ '<div id="r2-boss-overall" style="font-size:.95rem;color:var(--text);margin-bottom:10px">0 / 5 боссов побеждено</div>'
+ '<div style="height:12px;background:var(--card);border-radius:8px;overflow:hidden;border:1px solid var(--border)">'
+ '<div id="r2-boss-overall-fill" style="height:100%;width:0%;background:linear-gradient(90deg,#059669,#10b981)"></div>'
+ '</div>'
+ '<div id="r2-final-reward" style="margin-top:14px;display:none;padding:14px;background:var(--card);border-radius:11px;border:2px solid #f59e0b">'
+ '<div style="font-family:\'Unbounded\',sans-serif;font-weight:800;color:#92400e;font-size:1.05rem;margin-bottom:6px">Мастер пирамиды и конуса</div>'
+ '<div style="font-size:.92rem;margin-bottom:10px">Раздел 2 пройден! Все 5 боссов повержены. +50 XP бонус.</div>'
+ '<a class="btn primary" href="/textbook/geometry-11-ch3" style="text-decoration:none">Дальше: Раздел 3 <svg class="ic" viewBox="0 0 24 24"><polyline points="9 18 15 12 9 6"/></svg></a>'
+ '</div>'
+ '</div>';
html += secNav('p4', null);
box.innerHTML = html;
renderMath(box);
/* === Боссы === */
const BOSSES = [
{
n:1, color:'#059669',
title:'Циклоп Пирамиды',
tag:'§ 3',
q:'Правильная 4-угольная пирамида: сторона основания $a=6$, высота $h=4$. Найдите объём $V$.',
ans:48, tol:0.05,
hint:'$S_{осн}=a^2=36$, $V=\\tfrac{1}{3}\\cdot S_{осн}\\cdot h=\\tfrac{1}{3}\\cdot 36\\cdot 4=48$.'
},
{
n:2, color:'#dc2626',
title:'Минотавр Конуса',
tag:'§ 4',
q:'Конус с $R=5$, $h=12$. Найдите образующую $l$.',
ans:13, tol:0.05,
hint:'$l=\\sqrt{R^2+h^2}=\\sqrt{25+144}=\\sqrt{169}=13$.'
},
{
n:3, color:'#7c3aed',
title:'Гарпия Развёртки',
tag:'§ 4',
q:'Конус с $R=4$, $l=8$. Найдите угол развёртки боковой поверхности (в градусах).',
ans:180, tol:0.1,
hint:'$\\varphi=\\dfrac{360°\\cdot R}{l}=\\dfrac{360\\cdot 4}{8}=180°$.'
},
{
n:4, color:'#0891b2',
title:'Дракон Усечённой',
tag:'§ 3 + § 4',
q:'Усечённый конус: $R_1=5$, $R_2=2$, $h=4$. Найдите образующую $l$.',
ans:5, tol:0.05,
hint:'$l=\\sqrt{h^2+(R_1-R_2)^2}=\\sqrt{16+9}=\\sqrt{25}=5$.'
},
{
n:5, color:'#f59e0b',
title:'Мастер Тел Вращения',
tag:'синтез § 3 + § 4',
q:'В правильной 4-угольной пирамиде сторона основания $a=6$, высота $h=4$. Найдите длину апофемы $l$.',
ans:5, tol:0.05,
hint:'Радиус вписанной окружности квадрата: $r=a/2=3$. Апофема: $l=\\sqrt{r^2+h^2}=\\sqrt{9+16}=5$.'
}
];
const cont = document.getElementById('r2-bosses-container');
const STATE_KEY = 'geometry11_ch2_bosses';
const BOSS_STATE = (function(){
try{ const s = localStorage.getItem(STATE_KEY); if(s){ const p = JSON.parse(s); if(Array.isArray(p) && p.length === BOSSES.length) return p; } }catch(e){}
return BOSSES.map(()=>({defeated:false}));
})();
function saveBosses(){ try{ localStorage.setItem(STATE_KEY, JSON.stringify(BOSS_STATE)); }catch(e){} }
cont.innerHTML = BOSSES.map(b=>{
return '<div class="boss-card" id="boss2-'+b.n+'-card" style="padding:16px;background:var(--card);border-radius:12px;border:2px solid '+b.color+';margin-bottom:14px">'
+ '<div style="display:flex;align-items:center;gap:10px;margin-bottom:10px;flex-wrap:wrap">'
+ '<svg viewBox="0 0 24 24" fill="none" stroke="'+b.color+'" stroke-width="2.2" style="width:28px;height:28px;flex-shrink:0"><polygon points="12,2 22,20 2,20"/></svg>'
+ '<div style="font-family:\'Unbounded\',sans-serif;font-weight:800;color:'+b.color+';font-size:1.05rem">Босс '+b.n+': '+b.title+'</div>'
+ '<div style="margin-left:auto;font-size:.78rem;color:var(--muted);padding:3px 8px;background:var(--sec-acc-soft);border-radius:6px">'+b.tag+'</div>'
+ '</div>'
+ '<div class="boss-q" id="boss2-'+b.n+'-q" style="padding:12px 14px;background:var(--sec-acc-soft);border-radius:9px;font-size:1rem;line-height:1.5;margin-bottom:10px">'+b.q+'</div>'
+ '<div style="display:flex;gap:8px;align-items:center;flex-wrap:wrap">'
+ '<span style="font-family:\'JetBrains Mono\',monospace;font-size:.92rem">ответ =</span>'
+ '<input type="number" id="boss2-'+b.n+'-ans" class="tinp" style="width:140px;text-align:center" step="0.01" placeholder="число">'
+ '<button class="btn primary" id="boss2-'+b.n+'-go" style="background:'+b.color+';border-color:'+b.color+'">Атаковать</button>'
+ '<button class="btn" id="boss2-'+b.n+'-hint">Подсказка</button>'
+ '</div>'
+ '<div class="feedback" id="boss2-'+b.n+'-fb"></div>'
+ '</div>';
}).join('');
renderMath(cont);
function refreshOverall(){
const won = BOSS_STATE.filter(s => s.defeated).length;
const txt = document.getElementById('r2-boss-overall');
const fill = document.getElementById('r2-boss-overall-fill');
if(txt) txt.textContent = won + ' / ' + BOSSES.length + ' боссов побеждено';
if(fill) fill.style.width = (won * 100 / BOSSES.length) + '%';
if(won >= BOSSES.length){
const reward = document.getElementById('r2-final-reward');
if(reward && reward.style.display === 'none'){
reward.style.display = 'block';
if(!STATE.achievements.has('r2_done')){
achievement('r2_done','Мастер пирамиды и конуса');
addXp(50, 'r2-bonus');
bumpProgress('final2', 30);
if(window.confetti){ try{ confetti(); }catch(e){} }
}
}
}
}
BOSSES.forEach((b, idx)=>{
const card = document.getElementById('boss2-'+b.n+'-card');
const goBtn = document.getElementById('boss2-'+b.n+'-go');
const hintBtn= document.getElementById('boss2-'+b.n+'-hint');
const ansInp = document.getElementById('boss2-'+b.n+'-ans');
if(BOSS_STATE[idx].defeated){
card.style.background = 'linear-gradient(135deg,var(--sec-acc-soft),var(--pri-soft))';
card.classList.add('glow');
goBtn.disabled = true; goBtn.style.opacity = .55; goBtn.innerHTML = '&#10003; Повержен';
ansInp.disabled = true;
}
goBtn.addEventListener('click', ()=>{
if(BOSS_STATE[idx].defeated) return;
const fb = document.getElementById('boss2-'+b.n+'-fb');
const raw = (ansInp.value||'').replace(',', '.').trim();
const val = parseFloat(raw);
if(!isFinite(val)){ feedback(fb, false, '&#10007; Введи число.'); return; }
if(Math.abs(val - b.ans) <= b.tol){
BOSS_STATE[idx].defeated = true; saveBosses();
feedback(fb, true, '&#10003; Босс '+b.n+' повержен! +10 XP. '+b.hint);
addXp(10, 'boss-r2-'+b.n);
bumpProgress('final2', 18);
goBtn.disabled = true; goBtn.style.opacity = .55; goBtn.innerHTML = '&#10003; Повержен';
ansInp.disabled = true;
card.style.background = 'linear-gradient(135deg,var(--sec-acc-soft),var(--pri-soft))';
card.classList.add('glow','pulse');
setTimeout(()=>card.classList.remove('pulse'), 900);
refreshOverall();
} else {
feedback(fb, false, '&#10007; Промах. Попробуй ещё. Подсказка доступна.');
}
});
hintBtn.addEventListener('click', ()=>{
const fb = document.getElementById('boss2-'+b.n+'-fb');
fb.className = 'feedback ok';
fb.innerHTML = '<b>Подсказка:</b> '+b.hint;
fb.style.display = 'block';
fb.style.background = 'var(--warn-bg,#fef3c7)';
fb.style.color = '#92400e';
fb.style.borderLeftColor = 'var(--warn,#f59e0b)';
try{ renderMath(fb); }catch(e){}
});
ansInp.addEventListener('keydown', e=>{ if(e.key === 'Enter') goBtn.click(); });
});
refreshOverall();
}
/* ===== STUB BUILDER — единый для всех параграфов раздела (Phase 0) ===== */
function buildStub(id){