跳到正文

剪贴板

剪贴板 j1ittydn

txy120607
原文
剪贴板信息

剪贴板信息

发布
收录
更新

tutorial.html

JavaScript
<!DOCTYPE html>
<html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no"><title>OI 比赛模拟器 · 教程</title><style>:root{--bg:#f5f5f5;--surface:#fff;--text:#222;--t2:#555;--ac:#444;--cor:#555;--inc:#888;--tf:#666;--td:#333;--sf:#999;--border:#ccc;--shadow:0 4px 20px rgba(0,0,0,.06);--skb:#aaa;--brbg:#444;--brh:#333;--cbbg:#555;--cbb:#3a3a3a;--cbh:#444;--rup:#4a7c59;--rdn:#b84c3b;--rsm:#888;--dcb:#e8e8e8;--dcr:#fafafa;--dl:#e8943a;--ds:#5a9a4b;--dn:#c0c0c0;--dte:#5b9bd5;--dtel:#d6e8f7;--drb:#9b59b6;--drbl:#ecdff2;--dfs:#e6a817;--dfsl:#fff8e1;--dmb:#e8943a;--dtb:#5b9bd5;--din:#d4a017;--dinl:#fef9e7;--t1b:#e8943a;--t1bg:#fffaf5;--t2b:#d94a3a;--t2bg:#fff5f5;--t3b:#8b1a1a;--t3bg:#fef5f5;--eab:#7b3fa3;--eabg:#f9f4fc;--fb:#4a9a3f;--fbg:#f4faf3}*{margin:0;padding:0;box-sizing:border-box}body{background:var(--bg);font-family:'Segoe UI','PingFang SC','Microsoft YaHei',sans-serif;display:flex;justify-content:center;align-items:flex-start;min-height:100vh;padding:10px;user-select:none;-webkit-user-select:none}.main-wrapper{display:flex;flex-direction:row;align-items:flex-start;justify-content:center;gap:20px;max-width:1400px;width:100%;flex-wrap:wrap}.game-container{background:var(--surface);border-radius:20px;padding:10px 18px 14px;box-shadow:var(--shadow);display:flex;flex-direction:column;align-items:center;gap:10px;flex:1;min-width:0;border:3px solid transparent;position:relative;transition:border-color .15s}.game-container.correct-flash{border-color:#4caf50!important;box-shadow:0 0 28px rgba(76,175,80,.55)!important;animation:correctBorderFlash .5s ease-out forwards}@keyframes correctBorderFlash{0%{border-color:#4caf50;box-shadow:0 0 28px rgba(76,175,80,.55)}100%{border-color:transparent;box-shadow:0 4px 20px rgba(0,0,0,.06)}}.game-container.blue-flash{border-color:#39f!important;box-shadow:0 0 28px rgba(51,153,255,.55)!important;animation:blueBorderFlash .5s ease-out forwards}@keyframes blueBorderFlash{0%{border-color:#39f;box-shadow:0 0 28px rgba(51,153,255,.55)}100%{border-color:transparent;box-shadow:0 4px 20px rgba(0,0,0,.06)}}.tutorial-side-panel{background:var(--surface);border-radius:16px;padding:12px;box-shadow:var(--shadow);border:1px solid var(--border);width:240px;font-size:.8rem;position:sticky;top:10px;display:flex;flex-direction:column;gap:6px;flex-shrink:0;max-height:90vh;overflow-y:auto}.tutorial-msg{width:100%;padding:10px 14px;border-radius:12px;font-size:.82rem;font-weight:600;text-align:center;min-height:20px;transition:.3s;color:#2b5f8a;background:#e8f2fa;border:2px solid #5b9bd5;line-height:1.5;white-space:pre-line}.tutorial-msg.highlight{color:#8a6d14;background:#fffcf0;border-color:#e6a817;animation:pulseTut 1.5s infinite}@keyframes pulseTut{0%,100%{box-shadow:0 0 8px rgba(230,168,23,.3)}50%{box-shadow:0 0 20px rgba(230,168,23,.6)}}.tutorial-msg.success{color:#3d6b30;background:#e8f5e9;border-color:#5a9a4b}.tutorial-msg.info{color:#2b5f8a;background:#e8f2fa;border-color:#5b9bd5}.tutorial-msg.warning{color:#8a6d14;background:#fffcf0;border-color:#e6a817}.global-message{width:100%;padding:8px 14px;border-radius:10px;font-size:.78rem;font-weight:600;text-align:center;min-height:20px;transition:.3s;color:#555;background:#fafafa;border:1px solid #e0e0e0;margin-top:2px}.global-message.warning{color:#8a6d14;background:#fffcf0;border-color:#e6a817}.global-message.success{color:#3d6b30;background:#e8f5e9;border-color:#5a9a4b}.global-message.info{color:#2b5f8a;background:#e8f2fa;border-color:#5b9bd5}.side-panel{background:var(--surface);border-radius:16px;padding:16px 14px;box-shadow:var(--shadow);border:1px solid var(--border);width:260px;font-size:.8rem;display:flex;flex-direction:column;gap:10px;position:sticky;top:10px;max-height:90vh;overflow-y:auto}.side-panel.collapsed{display:none}.side-panel-title{font-weight:700;font-size:.95rem;color:#333;text-align:center;border-bottom:1px solid #ddd;padding-bottom:6px}.side-attr-row{display:flex;align-items:center;justify-content:space-between;background:#fafafa;border-radius:12px;padding:8px 14px;gap:8px}.side-attr-label{font-weight:700;color:#444;font-size:.85rem}.side-attr-value{font-weight:700;font-size:1rem;color:#222;min-width:28px;text-align:center}.focus-btn-inline{background:#ddd;border:1px solid #bbb;border-radius:50%;width:32px;height:32px;font-size:1.1rem;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:.2s;position:relative;flex-shrink:0}.focus-btn-inline:hover{background:#ccc;border-color:#999}.focus-btn-inline.active{background:#f9a825;border-color:#f57f17;color:#fff}.focus-btn-inline.locked{background:#e8e8e8;border-color:#ccc;color:#bbb;cursor:not-allowed;opacity:.6}.focus-btn-inline.has-cost::after{content:attr(data-cost);position:absolute;top:-14px;left:50%;transform:translateX(-50%);font-size:.65rem;font-weight:800;color:#777;pointer-events:none;white-space:nowrap}.attr-focus-bonus{font-size:.65rem;font-weight:800;color:#f57f17;background:#fff3e0;padding:1px 6px;border-radius:8px;white-space:nowrap;transition:.2s;display:inline-block;margin-left:4px}.side-stock-row{display:flex;align-items:center;justify-content:space-between;background:#fafafa;border-radius:10px;padding:6px 10px;font-size:.73rem;gap:6px}.side-stock-icon{font-size:1rem}.side-stock-name{font-weight:600;color:#555;min-width:36px}.side-stock-count{font-weight:700;color:#333;min-width:20px;text-align:center}.side-stock-bar{flex:1;height:6px;background:#e8e8e8;border-radius:4px;overflow:hidden}.side-stock-fill{height:100%;border-radius:4px;transition:width .3s}.side-stock-fill.time-fill{background:#5b9bd5}.side-stock-fill.mind-fill{background:#e8943a}.side-stock-fill.boost-fill{background:#9b59b6}.side-stock-fill.inspire-fill{background:#d4a017}.level-banner{position:absolute;top:-2px;left:50%;transform:translateX(-50%);background:linear-gradient(135deg,#3a3a3a,#555);color:#fff;padding:6px 22px;border-radius:0 0 16px 16px;font-weight:800;font-size:.9rem;letter-spacing:.5px;box-shadow:0 3px 16px rgba(0,0,0,.25);z-index:10;white-space:nowrap;transition:.3s;display:flex;align-items:center;gap:8px}.level-banner.sim{background:linear-gradient(135deg,#5a5a5a,#777);box-shadow:0 3px 16px rgba(0,0,0,.2)}.level-banner.final{background:linear-gradient(135deg,#111,#333);box-shadow:0 3px 20px rgba(0,0,0,.4);animation:glowBanner 1.5s infinite alternate}@keyframes glowBanner{from{box-shadow:0 3px 20px rgba(0,0,0,.4)}to{box-shadow:0 6px 32px rgba(0,0,0,.55)}}.attrs-panel{width:100%;display:flex;gap:8px;flex-wrap:wrap;justify-content:center;padding:6px 10px;background:#fafafa;border-radius:14px;border:1px solid #e0e0e0;margin-top:6px;align-items:center;font-size:.78rem;color:#888;min-height:20px}.score-progress-panel{width:100%;display:flex;align-items:center;gap:10px;padding:5px 14px;background:#fafafa;border-radius:30px;border:1px solid #e0e0e0}.score-progress-label{font-size:.8rem;font-weight:700;color:#444;white-space:nowrap;min-width:40px}.score-bar-outer{flex:1;height:12px;background:#e8e8e8;border-radius:8px;overflow:hidden;position:relative}.score-bar-inner{position:absolute;top:0;left:0;height:100%;border-radius:8px;transition:width .5s,background-color .5s;background:#1a1a1a}.score-number{font-size:.85rem;font-weight:700;color:#333;min-width:50px;text-align:right;white-space:nowrap;transition:color .3s}.score-number.tick{animation:numTick .15s ease-out}@keyframes numTick{0%{transform:scale(1.25);color:#4caf50}100%{transform:scale(1);color:#333}}.time-panel{width:100%;display:flex;align-items:center;gap:10px;padding:6px 12px;background:#fafafa;border-radius:30px;border:1px solid #e0e0e0;flex-wrap:wrap}.time-icon{font-size:1.2rem}.time-label{font-size:.8rem;font-weight:700;color:#444;white-space:nowrap;min-width:50px}.time-bars-group{display:flex;flex-direction:column;gap:3px;flex:1;min-width:80px}.time-bar-outer{height:10px;background:#e8e8e8;border-radius:8px;overflow:hidden;position:relative;width:100%}.stamina-bar,.time-bar-inner{position:absolute;top:0;left:0;height:100%;border-radius:8px;transition:width .5s}.time-bar-inner{background:var(--tf)}.time-bar-inner.danger{background:var(--td)}.stamina-bar{background:var(--sf)}.time-number{font-size:1.3rem;font-weight:800;color:#222;min-width:40px;text-align:center;transition:color .3s,transform .15s}.time-number.tick{animation:numTick .15s ease-out}.time-number.danger{color:#111}.map-selector{display:flex;gap:6px;flex-wrap:wrap;justify-content:center;align-items:center}.map-btn{background:#f5f5f5;border:2px solid #d5d5d5;color:#666;border-radius:20px;padding:5px 12px;font-weight:600;font-size:.78rem;cursor:pointer;transition:.2s;display:flex;align-items:center;gap:4px}.map-btn.active{background:#444;border-color:#333;color:#fff;box-shadow:0 0 12px rgba(0,0,0,.2)}.map-btn.win{background:#e8e8e8;border-color:#999;color:#333}.map-btn.lose{background:#f5f5f5;border-color:#ccc;color:#888}.map-btn.correct-found{background:#e0e0e0;border-color:#555;color:#222}.btn-complete-map{background:var(--cbbg);color:#fff;border:2px solid var(--cbb);border-radius:20px;padding:6px 16px;font-weight:700;font-size:.8rem;cursor:pointer;transition:.2s;white-space:nowrap;letter-spacing:.5px}.btn-complete-map:hover:not(:disabled){background:var(--cbh);transform:translateY(-2px);box-shadow:0 4px 16px rgba(0,0,0,.2)}.btn-complete-map:disabled{background:#ccc;border-color:#b0b0b0;cursor:not-allowed;opacity:.6}.canvas-wrapper{background:#fcfcfc;border-radius:14px;border:2px solid #ddd;display:flex;justify-content:center;width:100%}.canvas-wrapper.inference{border-color:#f90;box-shadow:0 0 20px rgba(255,153,0,.5)}canvas{display:block;max-width:100%;height:auto}.info-bar{width:100%;display:flex;justify-content:space-between;align-items:center;flex-wrap:wrap;gap:8px;font-size:.8rem;color:#777}.legend{display:flex;gap:10px;flex-wrap:wrap}.legend-item{display:flex;align-items:center;gap:4px;font-size:.73rem}.legend-dot{width:12px;height:12px;border-radius:50%;border:1.5px solid #999;background:#d0d0d0}.legend-dot.important{background:#666;border-color:#444}.legend-dot.result{background:#888;border-radius:2px;border-color:#666}.legend-dot.skill-node{background:#ccc;border-radius:1px;border:2px solid #999;transform:rotate(45deg);width:10px;height:10px;display:inline-block}.legend-dot.check-ring{background:0 0;border-radius:50%;border:3px solid #444;width:10px;height:10px}.legend-dot.correct-box{background:#555;border-radius:2px;border:2px solid #bbb;width:10px;height:10px}.legend-dot.broken{background:#fff;border-radius:50%;border:1.5px dashed #999;width:10px;height:10px;position:relative}.legend-dot.upgrade-node{background:#fff;border-radius:3px;border:2px solid #f90;width:10px;height:10px;display:inline-block}.btn{padding:10px 22px;border-radius:25px;border:none;font-weight:700;font-size:.9rem;cursor:pointer;letter-spacing:.5px;transition:.2s}.btn-restart{background:var(--brbg);color:#fff}.btn-restart:hover{background:var(--brh);transform:translateY(-2px);box-shadow:0 6px 20px rgba(0,0,0,.2)}.overlay{position:fixed;top:0;left:0;width:100vw;height:100vh;background:rgba(0,0,0,.5);z-index:100;display:flex;justify-content:center;align-items:center}.overlay.hidden{display:none}.modal{background:#fff;border-radius:20px;padding:28px 30px;text-align:center;box-shadow:0 20px 60px rgba(0,0,0,.2);max-width:680px;width:90%;border:1px solid #ddd;max-height:85vh;overflow-y:auto}.modal h2{font-size:1.7rem;margin-bottom:10px}.btn-continue{background:#444;color:#fff;padding:10px 24px;border-radius:25px;border:none;font-weight:700;cursor:pointer;margin-top:8px}.btn-continue:hover{background:#333}.stock-section{margin:8px 0;padding:8px 12px;background:#fafbfd;border-radius:12px;border:1px solid #e0e0e0}.stock-section-title{font-weight:700;font-size:.8rem;color:#444;margin-bottom:6px;text-align:center}.stock-item{display:flex;align-items:center;justify-content:space-between;padding:5px 8px;background:#fff;border-radius:8px;margin:3px 0;border:1px solid #eee;gap:6px}.stock-item-name{font-weight:600;font-size:.75rem;color:#444;min-width:50px}.stock-item-count{font-weight:700;font-size:.78rem;color:#333;min-width:16px;text-align:center}.stock-item-cost{font-size:.7rem;color:#888;min-width:55px;text-align:right}.btn-stock-buy{background:#555;color:#fff;border:none;padding:3px 10px;border-radius:10px;font-weight:700;font-size:.7rem;cursor:pointer;transition:.2s}.btn-stock-buy:disabled{background:#ccc;cursor:not-allowed}.btn-stock-buy:hover:not(:disabled){background:#444}.shop-separator{border:none;border-top:2px dashed #ccc;margin:10px 0;width:100%}.shop-section-title{font-size:.75rem;font-weight:700;color:#888;text-align:center;margin:6px 0 2px;letter-spacing:.5px}.shop-item{display:flex;align-items:center;justify-content:space-between;background:#fafafa;padding:8px 12px;border-radius:10px;margin:6px 0;border:1px solid #ddd}.shop-btn{background:#555;color:#fff;border:none;padding:4px 12px;border-radius:12px;font-weight:700;cursor:pointer;font-size:.73rem}.shop-btn:disabled{background:#ccc}.correct-found-hint{display:inline-block;background:#e0e0e0;color:#222;padding:4px 10px;border-radius:12px;font-weight:600;font-size:.75rem}.active-skills-bar{width:100%;display:flex;gap:6px;flex-wrap:wrap;justify-content:center;padding:4px 8px;font-size:.7rem;color:#777;min-height:20px}.active-skill-tag{background:#e8e8e8;color:#444;padding:2px 8px;border-radius:10px;font-weight:600;font-size:.68rem;white-space:nowrap}.hidden{display:none!important}.overlay-tut-msg{width:100%;padding:8px 12px;border-radius:10px;font-size:.78rem;font-weight:600;text-align:center;margin-bottom:8px;line-height:1.4;color:#2b5f8a;background:#e8f2fa;border:2px solid #5b9bd5;transition:.3s;white-space:pre-line}.overlay-tut-msg.highlight{color:#8a6d14;background:#fffcf0;border-color:#e6a817;animation:pulseTut 1.5s infinite}.overlay-tut-msg.success{color:#3d6b30;background:#e8f5e9;border-color:#5a9a4b}.overlay-tut-msg.info{color:#2b5f8a;background:#e8f2fa;border-color:#5b9bd5}.overlay-tut-msg.warning{color:#8a6d14;background:#fffcf0;border-color:#e6a817}.php-overlay-bg{background:rgba(0,0,0,.65);z-index:200}.php-modal{max-width:650px;width:95%;background:#fff;border-radius:20px;padding:20px;position:relative;text-align:center;box-shadow:0 20px 60px rgba(0,0,0,.3)}.php-post{background:#f9f9f9;border:2px solid #ddd;border-radius:16px;padding:12px;margin-bottom:10px;text-align:left}.php-post-author{font-weight:700;font-size:.9rem;color:#333;display:block;margin-bottom:4px}.php-post-content{font-size:1rem;color:#222;word-break:break-word}.php-replies{display:flex;flex-direction:column;gap:6px;margin-top:10px;text-align:left}.php-reply{background:#f4f4f4;border-radius:12px;padding:8px 12px;position:relative;animation:replyFadeIn .3s ease-out}@keyframes replyFadeIn{from{opacity:0;transform:translateY(-5px)}to{opacity:1;transform:translateY(0)}}.php-reply-name{font-weight:700;font-size:.75rem;display:block;margin-bottom:2px}.php-reply-content{font-size:.9rem;color:#333}.php-result{position:absolute;right:-10px;top:50%;transform:translateY(-50%);background:#fff;border:2px solid #bbb;border-radius:50%;width:50px;height:50px;display:flex;align-items:center;justify-content:center;font-size:1.2rem;font-weight:700;color:#333;box-shadow:0 2px 8px rgba(0,0,0,.15)}.php-close-hint{margin-top:14px;font-size:.7rem;color:#888}.php-tip{font-size:.7rem;color:#888;margin-top:8px;text-align:center}.name-blue{color:#0E90D2}.name-green{color:#5EB95E}.name-orange{color:#E67E22}.name-red{color:#E74C3C}.name-purple{color:#9D3DCF}.btn-php{background:#b84c3b;color:#fff;border:none;padding:6px 16px;border-radius:16px;font-weight:700;cursor:pointer;font-size:.85rem;letter-spacing:.5px;transition:.2s}.btn-php:disabled{background:#ccc;cursor:not-allowed}.btn-php:hover:not(:disabled){background:#9a3a2b}.shop-progress-panel{background:#fff8e1;border:2px solid #e6a817;border-radius:12px;padding:10px 14px;font-size:.75rem;color:#5a4a1a;text-align:left;width:260px;flex-shrink:0;max-height:90vh;overflow-y:auto}.shop-progress-item{display:flex;align-items:center;justify-content:space-between;padding:4px 6px;background:#fff;border-radius:8px;margin-bottom:4px;border:1px solid #f0e0a0;gap:4px}.shop-progress-item.next-match{background:#fff3cd;border-color:#ffc107;font-weight:700}.shop-progress-item.passed .shop-progress-status{color:#4caf50}.shop-progress-item.failed .shop-progress-status{color:#e74c3c}.shop-progress-status{min-width:28px;text-align:center}.shop-progress-name{flex:1;font-weight:600}.shop-progress-score{min-width:40px;text-align:right;font-weight:700}.shop-preview-panel{background:#f0f8ff;border:2px solid #b0d4f1;border-radius:12px;padding:10px 14px;font-size:.75rem;color:#2b5f8a;text-align:left;width:260px;flex-shrink:0;max-height:90vh;overflow-y:auto}.leaderboard-section{margin-top:12px;border-top:2px dashed #ccc;padding-top:8px}.leaderboard-item{display:flex;align-items:center;justify-content:space-between;padding:3px 6px;font-size:.7rem;background:#fafafa;border-radius:6px;margin:2px 0;gap:4px;flex-wrap:wrap}.leaderboard-rank{width:22px;text-align:center;font-weight:700}.leaderboard-change{width:24px;text-align:center;font-weight:700;font-size:.65rem}.leaderboard-name{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0;font-weight:bold}.leaderboard-score{min-width:40px;text-align:right;font-weight:700}.leaderboard-mini-scores{width:100%;text-align:right;font-size:.6rem;color:#999;margin-top:2px}.leaderboard-mini-scores .mini-score{margin-left:4px;padding:0 2px;border-radius:3px;background:#f0f0f0}.leaderboard-mini-scores .mini-score.pass{color:#4a7c59}.leaderboard-mini-scores .mini-score.fail{color:#b84c3b}.btn-export{background:#555;color:#fff;border:none;padding:6px 12px;border-radius:12px;font-weight:700;font-size:.7rem;cursor:pointer;margin-top:6px;transition:.2s}.btn-export:hover{background:#444}.shop-main-flex{display:flex;gap:20px;align-items:flex-start;justify-content:center;flex-wrap:nowrap}.shop-main-flex .shop-layout{flex:1 1 auto}.shop-overlay-bg .modal{max-width:1100px;flex:1 1 auto;max-height:90vh;overflow-y:auto}</style></head><body><div class="main-wrapper"><div class="game-container" id="gameContainer"><div class="level-banner hidden" id="levelBanner">🏆 <span id="levelName">教程</span></div><div class="global-message hidden" id="globalMessage"></div><div class="attrs-panel hidden" id="attrsPanel"></div><div class="active-skills-bar hidden" id="activeSkillsBar"></div><div class="score-progress-panel hidden" id="scoreProgressPanel"><span class="score-progress-label">📊总分</span><div class="score-bar-outer"><div class="score-bar-inner" id="scoreBarInner"></div></div><span class="score-number" id="scoreNumber">0/0</span></div><div class="time-panel hidden" id="timePanel"><span class="time-icon">⏱️</span><span class="time-label">精力/时间</span><div class="time-bars-group"><div class="time-bar-outer hidden" id="staminaBarOuter"><div class="stamina-bar" id="staminaBar"></div></div><div class="time-bar-outer" id="timeBarOuter"><div class="time-bar-inner" id="timeBarInner"></div></div></div><span class="time-number" id="timeNumber">0</span><span style="font-size:.7rem;color:#888;" id="staminaRefSpan" class="hidden">/精力<span id="staminaRef">20</span></span></div><div class="map-selector hidden" id="mapSelector"></div><div class="canvas-wrapper" id="canvasWrapper"><canvas id="treeCanvas"></canvas></div><div class="info-bar hidden" id="infoBar"><div class="legend"><span class="legend-item"><span class="legend-dot process"></span>过程</span><span class="legend-item"><span class="legend-dot important"></span>重要</span><span class="legend-item"><span class="legend-dot result"></span>结果</span><span class="legend-item"><span class="legend-dot skill-node"></span>技能点</span><span class="legend-item"><span class="legend-dot check-ring"></span>可检查</span><span class="legend-item"><span class="legend-dot correct-box"></span>正确</span><span class="legend-item"><span class="legend-dot broken"></span>错误</span></div><div>地图<span id="mapIndexDisplay">1</span>/<span id="totalMapsDisplay">1</span> | 解锁<span id="unlockedCount">0</span> | 最高分<span id="maxScoreDisplay">-</span><span id="correctFoundHint" class="correct-found-hint" style="display:none">✅正确路径已找到</span></div></div><button class="btn btn-restart hidden" id="btnRestart">🔄 重新开始</button></div><div class="tutorial-side-panel" id="tutorialSidePanel"><div class="tutorial-msg highlight" id="tutorialMsg">欢迎来到教程!</div></div><div class="side-panel hidden" id="sidePanel"><div class="side-panel-title">🧠属性面板</div><div class="side-attr-row"><span class="side-attr-label">🧠思维</span><span class="side-attr-value" id="sideMindValue">4</span><span class="attr-focus-bonus" id="sideFocusBonus" style="display:none">+0</span></div><div class="side-attr-row"><span class="side-attr-label">👁️凝聚</span><button id="btnFocusSide" class="focus-btn-inline hidden" title="聚焦(消耗1时间2精力,思维临时+1)">👁️</button></div><div style="border-top:1px solid #eee;padding-top:6px;margin-top:2px;"><div style="font-weight:700;font-size:.78rem;color:#555;text-align:center;margin-bottom:4px;">📦升级存量</div><div class="side-stock-row"><span class="side-stock-icon">⏰</span><span class="side-stock-name">时间</span><span class="side-stock-count" id="sideTimeStock">0</span><div class="side-stock-bar"><div class="side-stock-fill time-fill" id="sideTimeStockBar" style="width:0%"></div></div></div><div class="side-stock-row"><span class="side-stock-icon">🧠</span><span class="side-stock-name">思维</span><span class="side-stock-count" id="sideMindStock">0</span><div class="side-stock-bar"><div class="side-stock-fill mind-fill" id="sideMindStockBar" style="width:0%"></div></div></div><div class="side-stock-row"><span class="side-stock-icon">💠</span><span class="side-stock-name">提升</span><span class="side-stock-count" id="sideBoostStock">0</span><div class="side-stock-bar"><div class="side-stock-fill boost-fill" id="sideBoostStockBar" style="width:0%"></div></div></div><div class="side-stock-row"><span class="side-stock-icon">⚡</span><span class="side-stock-name">振奋</span><span class="side-stock-count" id="sideInspireStock">0</span><div class="side-stock-bar"><div class="side-stock-fill inspire-fill" id="sideInspireStockBar" style="width:0%"></div></div></div></div><div style="border-top:1px solid #eee;padding-top:6px;margin-top:6px;"><div style="font-weight:700;font-size:.78rem;color:#555;text-align:center;margin-bottom:4px;">📖 图例</div><div class="legend" style="flex-direction:column;gap:3px;"><div class="legend-item"><span class="legend-dot process"></span> 过程</div><div class="legend-item"><span class="legend-dot important"></span> 重要</div><div class="legend-item"><span class="legend-dot result"></span> 结果</div><div class="legend-item"><span class="legend-dot skill-node"></span> 技能点</div><div class="legend-item"><span class="legend-dot check-ring"></span> 可检查</div><div class="legend-item"><span class="legend-dot correct-box"></span> 正确</div><div class="legend-item"><span class="legend-dot broken"></span> 错误</div><div class="legend-item"><span class="legend-dot upgrade-node"></span> 升级存量</div></div></div></div></div><div class="overlay hidden" id="shopOverlay"><div class="modal"><div class="overlay-tut-msg" id="overlayShopTutMsg" style="display:none"></div><h2>🏪商店</h2><p class="skill-points-display">💎技能点:<span id="shopSkillPoints">0</span></p><div class="shop-main-flex"><div class="shop-side-column" style="display:flex;flex-direction:column;gap:12px;width:260px;flex-shrink:0;"><div id="shopProgressPanel" class="shop-progress-panel"></div><div id="shopPreviewPanel" class="shop-preview-panel"><div class="shop-right-title" style="font-size:.78rem;">下一场比赛预览</div><div id="shopPreviewNextMatch" style="font-size:.7rem;color:#555;text-align:center;"></div><div style="border-top:1px dashed #ddd;margin:6px 0;"></div><div class="shop-right-title" style="font-size:.78rem;">个人信息</div><div id="shopPreviewPersonal" style="font-size:.7rem;color:#555;"></div></div></div><div class="shop-layout"><div class="shop-left"><div id="shopLeftContent"></div></div><div class="shop-right"><div class="leaderboard-section"><div class="shop-right-title" style="font-size:.78rem;">排行榜</div><div id="leaderboardList" style="font-size:.7rem;color:#555;"></div></div></div></div></div><button class="btn-continue" id="btnCloseShop">▶继续</button></div></div><div class="overlay hidden" id="timeoutOverlay"><div class="modal"><h2>教程已完成</h2><p>您可以现在返回游戏游玩。</p><div style="text-align:left;display:inline-block;margin:10px auto;font-size:.85rem;line-height:1.8;"><div><b>部分操作快捷键</b></div><div>提交题目 / 进入下一场比赛 --- W</div><div>切换上一道题 --- A</div><div>切换下一道题 --- D</div><div>解锁节点 --- E</div><div>收起侧边信息栏 --- F</div><div>说 P 话 --- P</div><div>存量购买 --- 1 2 3 4</div><div>食物购买 --- 5 6 7</div></div><br><a href="index.html" class="btn-continue" style="display:inline-block;margin-top:10px;">返回游戏</a></div></div><div class="overlay hidden php-overlay-bg" id="phpOverlay"><div class="modal php-modal"><div class="php-post"><span class="php-post-author"></span><span class="php-post-content"></span></div><div class="php-replies"></div><div class="php-result" style="display:none"></div><div class="php-tip">说 P 话会根据比赛和分数高低产生成功和失败的结果,获得或失去技能点。分数不足就不要赌了。</div><div class="php-close-hint">点击空白处关闭</div></div></div><script>
(function(){
const LW=1200,LH=700,canvas=document.getElementById('treeCanvas'),ctx=canvas.getContext('2d');canvas.width=LW;canvas.height=LH;
let maps=[],activeMapIdx=0,remTime=40,remStamina=40,maxStaminaActual=40,focusStacks=0,focusMapIdx=-1,inferMode=!1,inferResults=new Map(),nodeAnimations={},gm=4,sp=0,gameStarted=!0,tutorialStep=0,stepAchecked=!1,stepBunlocked=!1,stepBchecked=!1,step7map2created=!1,step7switched=!1,shop={timeToSp:!1,timeMaster:!1,pocket:0,sharpIntuition:!1,convenience:!1,moneyPower:!1},timeStock=0,mindStock=0,boostStock=0,inspireStock=0,timeBonus=0,mindBonus=0,boostLevel=0,inspireCount=0,shakeRaf=null,pUsed=false,usedPhpNames=[],lastPhpStage=-1,lastMouseCanvasPos=null,playerName='新手',levelHistory=[],totalHistScore=0,everBoughtStock=false,level=0,phpFirstTime=true;
let ch={I:!1,II:!1,III:!1,I_exp:!1,IV:!1,V:!1,VI:!1,VII:!1,II_exp:!1,VIII:!1,IX:!1,X:!1,III_exp:!1,fun_I:!1,fun_II:!1,assist_I:!1};
const LV=[{name:'CSP-S模拟赛',maps:4,pass:200,stam:25,sim:!0},{name:'CSP-S',maps:4,pass:200,stam:25,sim:!1},{name:'NOIP模拟赛1',maps:4,pass:200,stam:35,sim:!0},{name:'NOIP模拟赛2',maps:4,pass:200,stam:35,sim:!0},{name:'NOIP',maps:4,pass:200,stam:35,sim:!1},{name:'省选模拟赛1',maps:6,pass:400,stam:45,sim:!0},{name:'省选模拟赛2',maps:6,pass:400,stam:45,sim:!0},{name:'省选',maps:6,pass:400,stam:45,sim:!1},{name:'NOI模拟赛1',maps:6,pass:400,stam:45,sim:!0},{name:'NOI模拟赛2',maps:6,pass:400,stam:45,sim:!0},{name:'NOI',maps:6,pass:400,stam:45,sim:!1},{name:'CTT',maps:6,pass:400,stam:45,sim:!1},{name:'CTS',maps:6,pass:400,stam:45,sim:!1},{name:'IOI',maps:6,pass:0,stam:45,sim:!1}];
function cfgL(l){return LV[Math.min(l,LV.length-1)]}
function minCorDepth(l){let b=Math.floor(l/3)+2;if(l>=5&&l<=10)b--;if(ch.X)b++;return b}
function minNodes(l){let b;if(l<=1)b=8;else if(l<=4)b=12;else if(l<=7)b=18;else b=24;if(l<=4)b+=4;if(ch.X)b+=8;return b}
function rI(a,b){return Math.floor(Math.random()*(b-a+1))+a}
function shuf(a){for(let i=a.length-1;i>0;i--){const j=Math.floor(Math.random()*(i+1));[a[i],a[j]]=[a[j],a[i]]}return a}
function seedR(s){let x=s;return function(){x=(x*16807)%2147483647;return(x-1)/2147483646}}
function getEffMind(){return gm+focusStacks+mindBonus}
function staminaCost(n){return Math.max(1,(n.req||0)-getEffMind())}
function getMaxS(lv){if(lv<=1)return 70;if(lv<=4)return 80;if(lv<=10)return 90;return 100}
function getK(){return ch.V?15:10}
function randomReq(depth,gl){const minR=gl+Math.floor(depth*gl/12),maxR=Math.ceil(gl*1.5+depth*gl/6);if(minR>=maxR)return Math.max(0,maxR);return rI(Math.floor(minR),Math.floor(maxR))}
function genTree(minCorD,level){let id=0;function nid(){return 'N'+(id++)}const k=getK(),maxS=getMaxS(level);const root={id:'R',name:'R',type:'process',isCorrect:!1,children:[],parent:null,depth:0,req:randomReq(0,level+1),score:null};const all=[root];const exp=[root];while(all.length<minNodes(level)){let cand=exp.filter(p=>p.children.length<(p.type==='important'?2:3));if(!cand.length)cand=all.filter(n=>n.type!=='result'&&n.children.length<(n.type==='important'?2:3));if(!cand.length){const nn={id:nid(),name:nid(),type:'process',isCorrect:!1,children:[],parent:root,depth:1,req:randomReq(1,level+1),score:null};root.children.push(nn);all.push(nn);cand=[nn]}const par=cand[rI(0,cand.length-1)];const rem=minNodes(level)-all.length;const avail=Math.min((par.type==='important'?2:3)-par.children.length,rI(1,Math.min(3,rem)));for(let i=0;i<avail;i++){if(all.length>=minNodes(level))break;const cd=par.depth+1;let tp;if(all.length<minNodes(level))tp=Math.random()<0.15?'important':(Math.random()<0.85?'process':'result');else tp=Math.random()<0.2?'important':(Math.random()<0.6?'process':'result');const child={id:nid(),name:nid(),type:tp,isCorrect:!1,children:[],parent:par,depth:cd,req:randomReq(cd,level+1),score:null};all.push(child);par.children.push(child);if(tp!=='result')exp.push(child)}const i=exp.indexOf(par);if(i>=0&&par.children.length>=(par.type==='important'?2:3))exp.splice(i,1)}let resLeaves=all.filter(n=>n.type==='result');if(!resLeaves.length){const p=all.find(n=>n.type==='process'&&n.children.length<3)||all[all.length-1];if(p.type==='result')p.type='process';const ch={id:nid(),name:nid(),type:'result',isCorrect:!1,children:[],parent:p,depth:p.depth+1,req:randomReq(p.depth+1,level+1),score:null};p.children.push(ch);all.push(ch);resLeaves.push(ch)}let deep=resLeaves.filter(n=>n.depth>=minCorD);if(!deep.length){let d=resLeaves.reduce((a,b)=>a.depth>b.depth?a:b);while(d.depth<minCorD){const nch={id:nid(),name:nid(),type:'result',isCorrect:!1,children:[],parent:d,depth:d.depth+1,req:randomReq(d.depth+1,level+1),score:null};d.children.push(nch);all.push(nch);d=nch;resLeaves.push(nch)}deep=[d]}const cor=deep[rI(0,deep.length-1)];cor.score=100;function lca(a,b){const p=new Set();let cur=a;while(cur){p.add(cur);cur=cur.parent}cur=b;while(cur){if(p.has(cur))return cur;cur=cur.parent}return null}resLeaves.forEach(rn=>{if(rn===cor)return;const l=lca(rn,cor);const distMax=Math.max(rn.depth-cor.depth,0)+Math.max(rn.depth-l.depth,cor.depth-l.depth);rn.score=Math.max(1,Math.floor(maxS-distMax*k))});let cur=cor;while(cur){cur.isCorrect=!0;cur=cur.parent}return{defs:all.map(n=>({id:n.id,name:n.name,type:n.type,isCorrect:n.isCorrect,childIds:n.children.map(c=>c.id),req:n.req,score:n.score,depth:n.depth})),correctId:cor.id}}
function buildMap(defs){const m={};defs.forEach(d=>m[d.id]={...d,children:[],parent:null,state:'hidden',x:0,y:0,isFork:!1,req:d.req,score:d.score,depth:d.depth,_b:null,_cb:null,_importantHasCorrect:!1,upgradeType:d.upgradeType||null});Object.values(m).forEach(n=>{n.childIds.forEach(cid=>{const c=m[cid];if(c){n.children.push(c);c.parent=n}});if(n.type==='process'&&n.children.length>1)n.isFork=!0});return m}
function createMap(minD,level){const{defs,correctId}=genTree(minD,level);const nm=buildMap(defs);const root=nm['R'];Object.values(nm).forEach(n=>n.state='hidden');root.state='visible_locked';return{nodeMap:nm,root,correctResult:nm[correctId],totalUnlocked:0,gameOver:!1,gameResult:null,maxResultScore:0,hasSkillNode:!1,skillNodeId:null,totalStaminaSpent:0}}
function createTutorialMap1(){const defs=[{id:'R',name:'R',type:'process',isCorrect:!0,childIds:['A','B'],req:3,score:null,depth:0},{id:'A',name:'A',type:'important',isCorrect:!1,childIds:['A1','A2'],req:4,score:null,depth:1},{id:'B',name:'B',type:'important',isCorrect:!0,childIds:['B1','B2'],req:5,score:null,depth:1},{id:'A1',name:'A1',type:'result',isCorrect:!1,childIds:[],req:4,score:60,depth:2},{id:'A2',name:'A2',type:'result',isCorrect:!1,childIds:[],req:4,score:70,depth:2},{id:'B1',name:'B1',type:'result',isCorrect:!1,childIds:[],req:5,score:50,depth:2},{id:'B2',name:'B2',type:'result',isCorrect:!0,childIds:[],req:6,score:100,depth:2}];const nm=buildMap(defs);const root=nm['R'];Object.values(nm).forEach(n=>n.state='hidden');root.state='visible_locked';return{nodeMap:nm,root,correctResult:nm['B2'],totalUnlocked:0,gameOver:!1,gameResult:null,maxResultScore:0,hasSkillNode:!1,skillNodeId:null,totalStaminaSpent:0}}
function createTutorialMap2(){const defs=[{id:'R2',name:'R2',type:'process',isCorrect:!0,childIds:['C','E'],req:2,score:null,depth:0},{id:'C',name:'C',type:'important',isCorrect:!0,childIds:['C_skill','C2','C_time_stock'],req:6,score:null,depth:1},{id:'E',name:'E',type:'process',isCorrect:!1,childIds:['E1','E2'],req:3,score:null,depth:1},{id:'C_skill',name:'💎奖励',type:'skill',isCorrect:!0,childIds:[],req:3,score:100,depth:2},{id:'C2',name:'C2',type:'result',isCorrect:!1,childIds:[],req:3,score:35,depth:2},{id:'C_time_stock',name:'⏰时间存量',type:'result',isCorrect:!1,childIds:[],req:2,score:0,depth:2,upgradeType:'time'},{id:'E1',name:'E1',type:'result',isCorrect:!1,childIds:[],req:3,score:25,depth:2},{id:'E2',name:'E2',type:'result',isCorrect:!1,childIds:[],req:3,score:15,depth:2}];const nm=buildMap(defs);const root=nm['R2'];Object.values(nm).forEach(n=>n.state='hidden');root.state='visible_locked';return{nodeMap:nm,root,correctResult:null,totalUnlocked:0,gameOver:!1,gameResult:null,maxResultScore:0,hasSkillNode:!0,skillNodeId:'C_skill',totalStaminaSpent:0}}
function getActive(){return maps[activeMapIdx]}
function canUnlock(n,map){return n.state==='visible_locked'&&!map.gameOver&&remTime>0&&remStamina>0&&(n===map.root||(n.parent&&(n.parent.state==='unlocked'||n.parent.state==='correct'||n.parent.state==='incorrect')))}
function canCheck(n,map){return n.state==='unlocked'&&!map.gameOver&&remTime>0&&remStamina>0&&(n.type==='important'||n.type==='result'||n.type==='skill')}
function markCorrect(n){if(n.state!=='correct')n.state='correct'}
function markIncorrect(n){if(n.state==='incorrect'||n.state==='correct')return;n.state='incorrect';n.children.forEach(c=>markIncorrect(c))}
function checkFork(f){if(!f.isFork||f.state==='incorrect'||f.state==='correct')return;if(f.children.every(c=>c.state==='incorrect')){markIncorrect(f);if(f.parent?.isFork)checkFork(f.parent)}}
function getMaxSub(node){if(node.type==='result'||node.type==='skill')return node.score||0;let m=0;function dfs(n){if((n.type==='result'||n.type==='skill')&&n.score>m)m=n.score;n.children.forEach(dfs)}dfs(node);return m}
function flashCorrectBorder(){const gc=document.getElementById('gameContainer');gc.classList.add('correct-flash');setTimeout(()=>gc.classList.remove('correct-flash'),550)}
function flashBlueBorder(){const gc=document.getElementById('gameContainer');gc.classList.add('blue-flash');setTimeout(()=>gc.classList.remove('blue-flash'),550)}
function computeLayout(md){const{nodeMap,root}=md;const lvls={},nlvl={};function assignLv(n,lv){n.depth=lv;nlvl[n.id]=lv;if(!lvls[lv])lvls[lv]=[];lvls[lv].push(n);n.children.forEach(c=>assignLv(c,lv+1))}assignLv(root,0);const maxLv=Math.max(...Object.keys(lvls).map(Number),0);const lvH=LH/(maxLv+2),topM=lvH*0.9;function leafCnt(n){if(!n.children.length)return 1;return n.children.reduce((s,c)=>s+leafCnt(c),0)}const lc={};Object.values(nodeMap).forEach(n=>lc[n.id]=leafCnt(n));const totalL=lc[root.id]||1,margin=60;function assignX(n,left,right){const w=(right-left)*(lc[n.id]/totalL);n.x=n===root?LW/2:left+w/2;n.y=topM+nlvl[n.id]*lvH;let childLeft=left;n.children.forEach(c=>{const cw=(right-left)*(lc[c.id]/totalL);assignX(c,childLeft,childLeft+cw);childLeft+=cw})}assignX(root,margin,LW-margin);Object.values(lvls).forEach(lns=>{lns.sort((a,b)=>a.x-b.x);for(let i=1;i<lns.length;i++)if(lns[i].x-lns[i-1].x<70)lns[i].x=lns[i-1].x+70;const avg=lns.reduce((s,n)=>s+n.x,0)/lns.length;lns.forEach(n=>n.x+=LW/2-avg);lns.forEach(n=>n.x=Math.max(margin,Math.min(LW-margin,n.x)))})}
function isActionAllowed(action,node,map){const ts=tutorialStep,mIdx=maps.indexOf(map);if(ts>=16)return!0;if(ts>=15)return!0;if(ts===14)return!1;if(action==='check'&&ts>=8&&node.state==='unlocked'&&canCheck(node,map))return!0;if(mIdx===0){if(ts>=7)return!1;if(ts===0){if(action==='unlock'&&node.id==='R')return!0;return!1}if(ts===1){if(action==='unlock'&&node.id==='A')return!0;if(action==='unlock'&&node.id==='B'){setGM('⚠️请先解锁节点A','warning');return!1}return!1}if(ts===2){if(action==='check'&&node.id==='A')return!0;return!1}if(ts===3){const a=map.nodeMap['A'];if(a&&(a.state==='correct'||a.state==='incorrect')){const children=a.children.filter(c=>c.type==='result');if(action==='unlock'&&children.some(c=>c.id===node.id&&c.state==='visible_locked'))return!0;if(action==='check'&&children.some(c=>c.id===node.id&&c.state==='unlocked'))return!0}return!1}if(ts===4){if(action==='unlock'&&node.id==='B')return!0;if(action==='unlock'&&node.id==='A'){setGM('⚠️请解锁节点B','warning');return!1}return!1}if(ts===5){if(action==='check'&&node.id==='B')return!0;return!1}if(ts===6){const b=map.nodeMap['B'];if(b&&(b.state==='correct'||b.state==='incorrect')){const children=b.children.filter(c=>c.type==='result');if(action==='unlock'&&children.some(c=>c.id===node.id&&c.state==='visible_locked'&&c.isCorrect))return!0;if(action==='check'&&children.some(c=>c.id===node.id&&c.state==='unlocked'&&c.isCorrect))return!0}return!1}return!1}if(mIdx===1){if(ts===7)return!1;if(ts===8){if(action==='unlock'&&node.id==='R2')return!0;return!1}if(ts===9){if(action==='unlock'&&node.id==='C')return!0;return!1}if(ts===10){if((action==='unlock'||action==='check')&&node.id==='C_skill')return!0;return!1}if(ts===11){if(action==='unlock'&&node.id==='C_time_stock')return!0;return!1}if(ts===12){if(action==='check'&&node.id==='C_time_stock')return!0;return!1}if(ts>=13)return!0;return!1}return!1}
function unlockNode(node,map){if(!canUnlock(node,map)){if(node.state!=='visible_locked')setGM('⚠️节点无法解锁','warning');else if(map.gameOver)setGM('⚠️地图已结束','warning');else if(remTime<=0)setGM('⏰时间不足','warning');else if(remStamina<=0)setGM('⚡精力不足','warning');return!1}if(!isActionAllowed('unlock',node,map))return!1;remTime=Math.max(0,remTime-1);const sc=staminaCost(node);remStamina=Math.max(0,remStamina-sc);map.totalStaminaSpent=(map.totalStaminaSpent||0)+sc;map.totalUnlocked++;node.state='unlocked';nodeAnimations[node.id]={type:'unlock',start:performance.now(),dur:300};node.children.forEach(c=>{if(c.state==='hidden')c.state='visible_locked'});refreshUI();checkGameEndCondition(map);checkTutorialProgress();return!0}
function performCheck(node,map){if(!canCheck(node,map)){if(node.state!=='unlocked')setGM('⚠️节点不可检查','warning');else if(map.gameOver)setGM('⚠️地图已结束','warning');else if(remTime<=0)setGM('⏰时间不足','warning');else if(remStamina<=0)setGM('⚡精力不足','warning');return!1}if(!isActionAllowed('check',node,map))return!1;remTime=Math.max(0,remTime-1);const stc=staminaCost(node);remStamina=Math.max(0,remStamina-stc);map.totalStaminaSpent=(map.totalStaminaSpent||0)+stc;if(node.isCorrect){markCorrect(node);flashCorrectBorder();let fork=node.parent;while(fork&&!fork.isFork)fork=fork.parent;if(fork){let cur=node;while(cur&&cur!==fork){if(cur.type==='process'||cur.type==='skill')markCorrect(cur);cur=cur.parent}}}else{node.state='incorrect';let fork=node.parent;while(fork&&!fork.isFork)fork=fork.parent;if(fork){let cur=node;while(cur&&cur!==fork){if(cur.type==='process'||cur.type==='skill')cur.state='incorrect';cur=cur.parent}checkFork(fork)}}if(node.type==='important'){function hasCorrectDescendant(n){if(n===map.correctResult)return!0;for(const c of n.children)if(hasCorrectDescendant(c))return!0;return!1}if(hasCorrectDescendant(node)){node._importantHasCorrect=!0}}if(node.upgradeType){switch(node.upgradeType){case'time':timeStock++;setGM('⏰获得时间存量!('+timeStock+')','success');break;case'mind':mindStock++;setGM('🧠获得思维存量!('+mindStock+')','success');break;case'boost':boostStock++;setGM('💠获得提升存量!('+boostStock+')','success');break;case'inspire':inspireStock++;setGM('⚡获得振奋存量!('+inspireStock+')','success');break}}map.maxResultScore=Math.max(map.maxResultScore||0,node.score||0);refreshUI();checkGameEndCondition(map);checkTutorialProgress();return!0}
function checkGameEndCondition(map){if(map.gameOver)return;if(remTime<=0||remStamina<=0){map.gameOver=!0;map.gameResult=null;showTimeoutOverlay();}else if(map.correctResult&&map.correctResult.state==='correct'){map.gameOver=!0;map.gameResult='win';setGM('🎉正确结果已找到!','success')}if(map.gameOver)refreshUI()}
function showTimeoutOverlay(){const overlay=document.getElementById('timeoutOverlay');if(overlay)overlay.classList.remove('hidden')}
const tmsgEl=document.getElementById('tutorialMsg'),gmEl=document.getElementById('globalMessage'),ostEl=document.getElementById('overlayShopTutMsg');
function setTMsg(t,cls){tmsgEl.innerHTML=t;tmsgEl.className='tutorial-msg';if(cls)tmsgEl.classList.add(cls)}
function setGM(t,ty){gmEl.textContent=t;gmEl.className='global-message';if(ty)gmEl.classList.add(ty);if(t){clearTimeout(gmEl._t);gmEl._t=setTimeout(()=>{gmEl.textContent='';gmEl.className='global-message'},6000)}}
function fsp(n){return Number.isInteger(n)?n.toString():n.toFixed(1)}
function refreshUI(){const map=getActive();if(!map)return;document.getElementById('timeNumber').textContent=remTime;document.getElementById('staminaRef').textContent=maxStaminaActual;document.getElementById('unlockedCount').textContent=map.totalUnlocked;document.getElementById('mapIndexDisplay').textContent=activeMapIdx+1;document.getElementById('totalMapsDisplay').textContent=maps.length;document.getElementById('maxScoreDisplay').textContent=map.maxResultScore>0?map.maxResultScore:'-';document.getElementById('correctFoundHint').style.display=(map.correctResult&&map.correctResult.state==='correct'&&!map.gameOver)?'inline-block':'none';const ts=maps.reduce((s,m)=>s+(m.maxResultScore||0),0),mp=maps.length*100;document.getElementById('scoreBarInner').style.width=mp?Math.min(1,ts/mp)*100+'%':'0%';document.getElementById('scoreNumber').textContent=ts+'/'+mp;const tR=remTime/Math.max(1,40),sR=remStamina/Math.max(1,maxStaminaActual);document.getElementById('timeBarInner').style.width=(tR*100)+'%';document.getElementById('staminaBar').style.width=(sR*100)+'%';document.getElementById('sideMindValue').textContent=getEffMind();document.getElementById('sideFocusBonus').style.display=focusStacks>0?'inline-block':'none';updateMapBtns();drawTree(map);updateActBar();syncAllSp();updateStockDisplay();updateSideStocks();updateShopPreview()}
function updateSideStocks(){document.getElementById('sideTimeStock').textContent=timeStock;document.getElementById('sideMindStock').textContent=mindStock;document.getElementById('sideBoostStock').textContent=boostStock;document.getElementById('sideInspireStock').textContent=inspireStock;const maxStock=Math.max(timeStock,mindStock,boostStock,inspireStock,1);document.getElementById('sideTimeStockBar').style.width=(timeStock/maxStock*100)+'%';document.getElementById('sideMindStockBar').style.width=(mindStock/maxStock*100)+'%';document.getElementById('sideBoostStockBar').style.width=(boostStock/maxStock*100)+'%';document.getElementById('sideInspireStockBar').style.width=(inspireStock/maxStock*100)+'%'}
function updateMapBtns(){document.querySelectorAll('.map-btn').forEach(b=>{const i=+b.dataset.index,m=maps[i];if(!m)return;b.classList.remove('active','win','lose','correct-found');if(i===activeMapIdx)b.classList.add('active');if(m.gameOver&&m.gameResult==='win')b.classList.add('win');else if(m.gameOver&&m.gameResult==='lose')b.classList.add('lose');else if(!m.gameOver&&m.correctResult&&m.correctResult.state==='correct')b.classList.add('correct-found');let ic='⏳';if(m.gameOver)ic=m.gameResult==='win'?'✅':'❌';else if(m.correctResult&&m.correctResult.state==='correct')ic='🔍';b.innerHTML=ic+' 地图'+(i+1)})}
function updateActBar(){const b=document.getElementById('activeSkillsBar');let p=[];if(inferMode)p.push('<span class="active-skill-tag" style="color:#f90">按R退出推理</span>');if(timeBonus)p.push('<span class="active-skill-tag">⏰+'+timeBonus+'</span>');if(mindBonus)p.push('<span class="active-skill-tag">🧠+'+mindBonus+'</span>');if(boostLevel)p.push('<span class="active-skill-tag">💠×'+(1+boostLevel)+'</span>');if(inspireCount)p.push('<span class="active-skill-tag">⚡×'+inspireCount+'</span>');if(shop.moneyPower)p.push('<span class="active-skill-tag">💰就绪</span>');b.innerHTML=p.join(' ')}
function drawTree(map){ctx.clearRect(0,0,LW,LH);ctx.fillStyle='#fcfcfc';ctx.fillRect(0,0,LW,LH);const vis=Object.values(map.nodeMap).filter(n=>{if(inferMode)return n.state==='unlocked'||n.state==='correct'||n.state==='incorrect';return n.state!=='hidden'});vis.forEach(n=>n.children.forEach(c=>{if(vis.includes(c))drawEdge(n,c)}));vis.forEach(n=>drawNode(n,map));if(map.gameOver&&map.gameResult==='lose'){Object.values(map.nodeMap).filter(n=>n.isCorrect&&n.state!=='hidden').forEach(n=>{ctx.save();ctx.strokeStyle='rgba(80,80,80,0.7)';ctx.lineWidth=3;ctx.setLineDash([5,3]);ctx.beginPath();ctx.arc(n.x,n.y,(n.type==='important'?22:20)+6,0,Math.PI*2);ctx.stroke();ctx.setLineDash([]);ctx.restore()})}}
function drawEdge(p,c){let col='#999';if(p.state==='correct'&&c.state==='correct')col='#555';else if(p.state==='incorrect'||c.state==='incorrect')col='#bbb';ctx.strokeStyle=col;ctx.lineWidth=2.5;ctx.beginPath();ctx.moveTo(p.x,p.y);ctx.lineTo(c.x,c.y);ctx.stroke()}
function drawNode(node,map){let cx=node.x,cy=node.y;const baseR=node.type==='important'?22:20;let r=baseR;const anim=nodeAnimations[node.id];if(anim&&anim.type==='unlock'){const elapsed=performance.now()-anim.start;const p=Math.min(1,elapsed/anim.dur);if(p<1){const scale=1+0.35*Math.sin(p*Math.PI);r=baseR*scale}else{delete nodeAnimations[node.id]}}let fill,stroke,tc,alpha=1;switch(node.state){case'visible_locked':fill=node.type==='process'?'#d5d5d5':(node.type==='important'?'#888':'#999');stroke='#b0b0b0';tc=node.type==='important'?'#fff':'#444';break;case'unlocked':fill='#3a3a3a';stroke='#1a1a1a';tc='#fff';break;case'correct':fill='#3a3a3a';stroke='#1a1a1a';tc='#fff';break;case'incorrect':fill='#fff';stroke='#999';tc='#555';break;default:return}if(node.upgradeType&&(node.state==='unlocked'||node.state==='correct'||node.state==='incorrect'||node.state==='visible_locked')){ctx.save();ctx.globalAlpha=alpha;let ugCol='#f90';if(node.upgradeType==='time')ugCol='#5b9bd5';else if(node.upgradeType==='mind')ugCol='#e8943a';else if(node.upgradeType==='boost')ugCol='#9b59b6';else if(node.upgradeType==='inspire')ugCol='#d4a017';ctx.strokeStyle=ugCol;ctx.lineWidth=3;ctx.setLineDash([3,2]);const ur=r+7;ctx.beginPath();ctx.arc(cx,cy,ur,0,Math.PI*2);ctx.stroke();ctx.setLineDash([]);ctx.restore()}ctx.save();ctx.globalAlpha=alpha;if(node.type==='skill'){stroke=node.state==='incorrect'?'#999':(node.state==='correct'?'#1a1a1a':'#aaa');ctx.fillStyle=fill;ctx.strokeStyle=stroke;ctx.lineWidth=2.5;if(node.state==='incorrect')ctx.setLineDash([5,3]);ctx.beginPath();ctx.moveTo(cx,cy-r);ctx.lineTo(cx+r,cy);ctx.lineTo(cx,cy+r);ctx.lineTo(cx-r,cy);ctx.closePath();ctx.fill();ctx.stroke();ctx.setLineDash([]);node._b={x:cx-r,y:cy-r,w:r*2,h:r*2}}else if(node.type==='result'){const hs=r*0.85;ctx.fillStyle=fill;ctx.strokeStyle=stroke;ctx.lineWidth=2.5;if(node.state==='incorrect')ctx.setLineDash([5,3]);ctx.beginPath();ctx.rect(cx-hs,cy-hs,hs*2,hs*2);ctx.fill();ctx.stroke();ctx.setLineDash([]);node._b={x:cx-hs,y:cy-hs,w:hs*2,h:hs*2}}else{ctx.fillStyle=fill;ctx.strokeStyle=stroke;ctx.lineWidth=2.5;if(node.state==='incorrect')ctx.setLineDash([5,3]);ctx.beginPath();ctx.arc(cx,cy,r,0,Math.PI*2);ctx.fill();ctx.stroke();ctx.setLineDash([]);node._b=null}if(node.state==='incorrect'&&node._b){const rng=seedR(node.id.split('').reduce((h,c)=>h*31+c.charCodeAt(0),0));for(let i=0;i<3;i++){const ang=rng()*Math.PI*2,len=(node.type==='result'?r*0.85:r)*(0.65+rng()*0.5),sx=cx+Math.cos(ang)*len*0.3,sy=cy+Math.sin(ang)*len*0.3,ex=cx+Math.cos(ang)*len,ey=cy+Math.sin(ang)*len;ctx.strokeStyle='#aaa';ctx.lineWidth=1;ctx.beginPath();ctx.moveTo(sx,sy);ctx.lineTo(ex,ey);ctx.stroke();const pa=ang+Math.PI/2,bl=len*0.25,mx=(sx+ex)/2,my=(sy+ey)/2;ctx.beginPath();ctx.moveTo(mx,my);ctx.lineTo(mx+Math.cos(pa)*bl,my+Math.sin(pa)*bl);ctx.stroke()}}if((node.state==='correct'||node._importantHasCorrect)&&node.type==='important'){const bs=r+7;ctx.strokeStyle='#999';ctx.lineWidth=2.5;ctx.setLineDash([4,3]);ctx.beginPath();ctx.rect(cx-bs,cy-bs,bs*2,bs*2);ctx.stroke();ctx.setLineDash([])}if(node.state==='unlocked'){const showRing=node.type==='important'||node.type==='result'||node.type==='skill';if(showRing&&!map.gameOver){const rr=(node.type==='result'?r*0.85:r)+5;ctx.strokeStyle='#333';ctx.lineWidth=2.8;ctx.beginPath();ctx.arc(cx,cy,rr,0,Math.PI*2);ctx.stroke();node._cb={x:cx-rr-3,y:cy-rr-3,w:(rr+3)*2,h:(rr+3)*2}}else node._cb=null}else node._cb=null;if(node.state==='incorrect'){const sc=getMaxSub(node);ctx.fillStyle='#888';ctx.font='bold 14px sans-serif';ctx.textAlign='center';ctx.fillText(sc,cx,cy)}else{ctx.fillStyle=tc;ctx.font='bold 11px sans-serif';ctx.textAlign='center';ctx.fillText(node.name,cx,cy);if((node.type==='result'||node.type==='skill')&&node.score!==null&&(node.state==='unlocked'||node.state==='correct')){ctx.font='bold 9px sans-serif';ctx.fillText(node.score,cx,cy+12)}}const stCost=staminaCost(node);ctx.fillStyle=stCost<=1?'#aaa':(stCost<=3?'#777':(stCost===4?'#444':'#222'));ctx.font='bold 10px sans-serif';ctx.textAlign='center';ctx.fillText(stCost,cx,cy-r-3);ctx.fillStyle=(node.state==='correct'||node.state==='unlocked')?'#555':'#888';ctx.font='9px sans-serif';ctx.fillText('需≥'+node.req,cx,cy+r+12);ctx.restore()}
function hitTest(pos,map){const vis=Object.values(map.nodeMap).filter(n=>inferMode?(n.state==='unlocked'||n.state==='correct'||n.state==='incorrect'):n.state!=='hidden');if(inferMode){for(const n of vis){if(n.state!=='unlocked')continue;let inRange=!1;if(n._cb&&pos.x>=n._cb.x&&pos.x<=n._cb.x+n._cb.w&&pos.y>=n._cb.y&&pos.y<=n._cb.y+n._cb.h)inRange=!0;else if(n._b&&pos.x>=n._b.x&&pos.x<=n._b.x+n._b.w&&pos.y>=n._b.y&&pos.y<=n._b.y+n._b.h)inRange=!0;else{const r=(n.type==='important'?22:20)+3;inRange=Math.hypot(pos.x-n.x,pos.y-n.y)<=r}if(inRange)return{node:n,target:'infer'}}return null}for(const n of vis){if(n._cb&&pos.x>=n._cb.x&&pos.x<=n._cb.x+n._cb.w&&pos.y>=n._cb.y&&pos.y<=n._cb.y+n._cb.h)return{node:n,target:'check'}}for(const n of vis){if(n._b){if(pos.x>=n._b.x&&pos.x<=n._b.x+n._b.w&&pos.y>=n._b.y&&pos.y<=n._b.y+n._b.h){if(n.state==='unlocked'&&canCheck(n,map))return{node:n,target:'check'};if(n.state==='visible_locked'&&canUnlock(n,map))return{node:n,target:'node'};return null}}else{const r=(n.type==='important'?22:20)+3;if(Math.hypot(pos.x-n.x,pos.y-n.y)<=r){if(n.state==='unlocked'&&canCheck(n,map))return{node:n,target:'check'};if(n.state==='visible_locked'&&canUnlock(n,map))return{node:n,target:'node'};return null}}}return null}
canvas.addEventListener('click',e=>{if(!gameStarted)return;const map=getActive();if(!map||map.gameOver)return;if(tutorialStep===14)return;const rect=canvas.getBoundingClientRect();const pos={x:(e.clientX-rect.left)*(LW/canvas.clientWidth),y:(e.clientY-rect.top)*(LH/canvas.clientHeight)};lastMouseCanvasPos=pos;const hit=hitTest(pos,map);if(!hit)return;if(inferMode){if(hit.target==='infer'){setGM('推理模式在教程中已移除','warning');return}}else{if(hit.target==='check')performCheck(hit.node,map);else if(hit.target==='node')unlockNode(hit.node,map)}});
canvas.addEventListener('mousemove',e=>{if(!gameStarted){canvas.style.cursor='default';return}const map=getActive();if(!map||map.gameOver||tutorialStep===14){canvas.style.cursor='default';lastMouseCanvasPos=null;return}const rect=canvas.getBoundingClientRect();const pos={x:(e.clientX-rect.left)*(LW/canvas.clientWidth),y:(e.clientY-rect.top)*(LH/canvas.clientHeight)};lastMouseCanvasPos=pos;const hit=hitTest(pos,map);canvas.style.cursor=hit?'pointer':'default'});
function clearAllShake(){const map=getActive();if(map)Object.values(map.nodeMap).forEach(n=>{delete n._shake});if(shakeRaf){cancelAnimationFrame(shakeRaf);shakeRaf=null}}
function syncAllSp(){const ssp=document.getElementById('shopSkillPoints');if(ssp)ssp.textContent=fsp(sp)}
function updateStockDisplay(){const cont=document.getElementById('shopLeftContent');if(cont){initShopPanel();return}const stockCont=document.getElementById('stockItemsContainer');if(stockCont){const stocks=[{name:'⏰ 时间存量',count:timeStock,cost:5,key:'time',desc:'初始时间+3'},{name:'🧠 思维存量',count:mindStock,cost:5,key:'mind',desc:'思维永久+1'},{name:'💠 提升存量',count:boostStock,cost:7,key:'boost',desc:'特殊节点技能点+1'},{name:'⚡ 振奋存量',count:inspireStock,cost:8,key:'inspire',desc:'正确时恢复更多精力'}];let html='';stocks.forEach(s=>{const canBuy=s.count>0&&sp>=s.cost;html+=`<div class="stock-item"><span class="stock-item-name">${s.name}</span><span class="stock-item-count">×${s.count}</span><span class="stock-item-cost">${s.desc}</span><button class="btn-stock-buy" onclick="window._buyStock('${s.key}')" ${canBuy?'':'disabled'}>${s.cost}sp购买</button></div>`});stockCont.innerHTML=html}}
window._buyStock=function(key){const costs={time:5,mind:5,boost:7,inspire:8};const cost=costs[key];if(sp<cost){setGM('技能点不足','warning');return}if(key==='time'&&timeStock<1){setGM('时间存量不足','warning');return}if(key==='mind'&&mindStock<1){setGM('思维存量不足','warning');return}if(key==='boost'&&boostStock<1){setGM('提升存量不足','warning');return}if(key==='inspire'&&inspireStock<1){setGM('振奋存量不足','warning');return}sp-=cost;if(key==='time'){timeStock--;timeBonus+=3;setGM('⏰时间升级!初始时间+3','success')}else if(key==='mind'){mindStock--;mindBonus++;setGM('🧠思维升级!思维+1','success')}else if(key==='boost'){boostStock--;boostLevel++;setGM('💠提升升级!特殊节点奖励+1','success')}else if(key==='inspire'){inspireStock--;inspireCount++;setGM('⚡振奋升级!','success')}everBoughtStock=true;syncAllSp();updateStockDisplay();updateSideStocks();updateActBar();refreshUI();checkTutorialProgress()}
function initShopPanel(){const cont=document.getElementById('shopLeftContent');syncAllSp();let html='';const isProvinceOrLater=level>=4;const priceHike=0;let stockCosts=isProvinceOrLater?{time:5+priceHike,mind:5+priceHike,boost:7+priceHike,inspire:8+priceHike}:{time:3,mind:3,boost:4,inspire:4};html+='<div class="stock-section"><div class="stock-section-title">📦 升级存量(检查地图中标记节点获得)</div>';const stocks=[{name:'⏰ 时间存量',count:timeStock,cost:stockCosts.time,key:'time',desc:ch.I_exp?'初始时间+2.5':'初始时间+3'},{name:'🧠 思维存量',count:mindStock,cost:stockCosts.mind,key:'mind',desc:'思维+1,思维不足时解锁节点需要额外精力'},{name:'💠 提升存量',count:boostStock,cost:stockCosts.boost,key:'boost',desc:'检查特殊奖励节点奖励的技能点+1'},{name:'⚡ 振奋存量',count:inspireStock,cost:stockCosts.inspire,key:'inspire',desc:'检查正确节点可以获得 1 精力,搭配推理十分有用'}];stocks.forEach(s=>{const canBuy=s.count>0&&sp>=s.cost;html+=`<div class="stock-item"><span class="stock-item-name">${s.name}</span><span class="stock-item-count">×${s.count}</span><span class="stock-item-cost">${s.desc}</span><button class="btn-stock-buy" onclick="window._buyStock('${s.key}')" ${canBuy?'':'disabled'}>${s.cost}sp购买</button></div>`;});html+='</div>';html+='<hr class="shop-separator"><div class="shop-section-title">📦 通用升级</div>';const upgs=[{name:'充分利用时间',desc:'剩余每2时间→1技能点',cost:15+priceHike,key:'timeToSp'},{name:'时间管理大师',desc:'初始时间×1.2',cost:25+priceHike,key:'timeMaster'},{name:'敏锐直觉',desc:'推理显示3层内最高分',cost:20+priceHike,key:'sharpIntuition'},{name:'顺手的事',desc:'推理时显示子节点升级存量',cost:12+priceHike,key:'convenience'},{name:'💰 钞能力',desc:'正式赛失败时满分通过(每场1次)',cost:20+priceHike,key:'moneyPower'}];upgs.forEach(u=>{const owned=shop[u.key]===!0;html+=`<div class="shop-item"><span><b>${u.name}</b><br><small>${u.desc}</small></span>`;if(!owned)html+=`<button class="shop-btn" onclick="window._buyUpgrade('${u.key}')">购买(${u.cost}sp)</button>`;else html+=`<span>✅已拥有</span>`;html+='</div>'});html+='<hr class="shop-separator"><div class="shop-section-title">🗣️ 说P话</div><div style="text-align:center;font-size:.7rem;color:#888;margin-bottom:6px;">试下说P话吧,每一个阶段你都可以进行一次说P话,分数超过分数线越高成功概率越高</div><div style="text-align:center;"><button class="btn-php" onclick="window._startPhp()" '+(pUsed?'disabled':'')+'>说P话(每阶段1次)</button></div>';cont.innerHTML=html;updateShopPreview();updateShopProgressPanel();updateLeaderboardUI()}
window._buyUpgrade=function(key){const costs={timeToSp:15,timeMaster:25,sharpIntuition:20,convenience:12,moneyPower:20};if(sp<costs[key]){setGM('技能点不足','warning');return}sp-=costs[key];shop[key]=!0;syncAllSp();initShopPanel();updateActBar();updateShopPreview();refreshUI();checkTutorialProgress()}
function updateShopPreview(){const nextMatchEl=document.getElementById('shopPreviewNextMatch');const personalEl=document.getElementById('shopPreviewPersonal');if(!nextMatchEl||!personalEl)return;let nextLv=0;if(nextLv>13){nextMatchEl.innerHTML='<span style="color:#888;">已是最终关卡</span>';}else{const ncfg=cfgL(nextLv);let nextBaseStam=ncfg.stam;let nextTime=nextBaseStam+timeBonus;if(shop.timeMaster)nextTime=Math.floor(nextTime*1.2);let nextStamina=Math.floor(nextTime*1.2);nextMatchEl.innerHTML=`<div class="shop-preview-row"><span class="shop-preview-label">比赛名称</span><span class="shop-preview-value">${ncfg.name}</span></div><div class="shop-preview-row"><span class="shop-preview-label">初始时间</span><span class="shop-preview-value">${nextTime}</span></div><div class="shop-preview-row"><span class="shop-preview-label">精力上限</span><span class="shop-preview-value">${nextStamina}</span></div><div class="shop-preview-row"><span class="shop-preview-label">题目数</span><span class="shop-preview-value">${ncfg.maps}</span></div><div class="shop-preview-row"><span class="shop-preview-label">分数线</span><span class="shop-preview-value">${ncfg.pass+(ch.II_exp?30:0)}</span></div>`;}const effMind=getEffMind();const skillReward=0.5+boostLevel;personalEl.innerHTML=`<div class="shop-preview-row"><span class="shop-preview-label">🧠 思维</span><span class="shop-preview-value">${effMind}</span></div><div class="shop-preview-row"><span class="shop-preview-label">💎 特殊节点奖励</span><span class="shop-preview-value">${fsp(skillReward)} sp/个</span></div><div class="shop-preview-row"><span class="shop-preview-label">⚡ 振奋效果乘数</span><span class="shop-preview-value">${inspireCount>0?'×'+inspireCount:'未激活'}</span></div><div class="shop-preview-row"><span class="shop-preview-label">💠 提升等级</span><span class="shop-preview-value">Lv.${boostLevel}</span></div><div class="shop-preview-row"><span class="shop-preview-label">💰 钞能力</span><span class="shop-preview-value">${shop.moneyPower?'可用':'未解锁'}</span></div>`}
function updateShopProgressPanel(){const panel=document.getElementById('shopProgressPanel');if(!panel)return;const nextLv=0;let html='<div class="shop-right-title" style="font-size:.78rem;">📅 比赛进度</div>';for(let i=0;i<LV.length;i++){const cfg=LV[i];const hist=levelHistory.find(e=>e.level===i);const isNext=i===nextLv;const isPassed=hist&&hist.passed;const isFailed=hist&&!hist.passed;let leftText='';if(hist){if(hist.passed)leftText=hist.totalScore+'分';else leftText='未通过';}else{leftText='未开始';}let prefix='';if(isNext)prefix='➡️ ';else if(hist)prefix=isPassed?'✅ ':'❌ ';else prefix='⬜ ';html+=`<div class="shop-progress-item ${isNext?'next-match':''} ${isPassed?'passed':''} ${isFailed?'failed':''}"><span class="shop-progress-status">${prefix}</span><span class="shop-progress-name">${cfg.name}</span><span class="shop-progress-score">${hist?leftText:''}</span></div>`;}panel.innerHTML=html;}
function updateLeaderboardUI(){const listEl=document.getElementById('leaderboardList');if(!listEl)return;listEl.innerHTML='<div class="shop-right-empty">暂无记录</div>';}
function cleanupOstEl(){if(ostEl){ostEl.innerHTML='';ostEl.className='overlay-tut-msg';ostEl.style.display='none'}}
document.getElementById('btnCloseShop').addEventListener('click',()=>{document.getElementById('shopOverlay').classList.add('hidden');cleanupOstEl();if(tutorialStep===13){tutorialStep=14;if(timeBonus>0){setTMsg('太棒了!你已购买时间升级,初始时间+3。\n现在准备进行最终实战!','highlight')}else{setTMsg('好的,商店已关闭。现在准备进行最终实战!','highlight')}}checkTutorialProgress()});
document.getElementById('btnFocusSide').addEventListener('click',()=>{if(!gameStarted||!getActive()||getActive().gameOver)return;if(remTime<1||remStamina<2){setGM('资源不足','warning');return}remTime--;remStamina-=2;focusStacks++;focusMapIdx=activeMapIdx;updateActBar();refreshUI()});
document.addEventListener('keydown',e=>{if(e.key==='e'||e.key==='E'){if(e.target.tagName==='INPUT'||e.target.tagName==='TEXTAREA')return;if(!gameStarted)return;if(document.getElementById('shopOverlay').classList.contains('hidden')===false)return;if(lastMouseCanvasPos){const map=getActive();if(map&&!map.gameOver){const hit=hitTest(lastMouseCanvasPos,map);if(hit){if(hit.target==='check')performCheck(hit.node,map);else if(hit.target==='node')unlockNode(hit.node,map)}}}}if(e.key==='f'||e.key==='F'){document.getElementById('sidePanel').classList.toggle('collapsed');}if(e.key==='w'||e.key==='W'){if(document.getElementById('shopOverlay').classList.contains('hidden')===false){document.getElementById('btnCloseShop').click();}else if(gameStarted&&!getActive().gameOver){const map=getActive();if(map.correctResult&&map.correctResult.state==='correct'){map.gameOver=true;map.gameResult='win';refreshUI();checkTutorialProgress();}}}if(e.key==='d'||e.key==='D'){if(gameStarted&&document.getElementById('shopOverlay').classList.contains('hidden')){if(activeMapIdx<maps.length-1){activeMapIdx++;if(focusStacks&&focusMapIdx!==activeMapIdx){focusStacks=0;focusMapIdx=-1}refreshUI();}}}if(e.key==='a'||e.key==='A'){if(gameStarted&&document.getElementById('shopOverlay').classList.contains('hidden')){if(activeMapIdx>0){activeMapIdx--;if(focusStacks&&focusMapIdx!==activeMapIdx){focusStacks=0;focusMapIdx=-1}refreshUI();}}}if(document.getElementById('shopOverlay').classList.contains('hidden')===false){if(e.key==='1')window._buyStock('time');else if(e.key==='2')window._buyStock('mind');else if(e.key==='3')window._buyStock('boost');else if(e.key==='4')window._buyStock('inspire');else if(e.key==='p'||e.key==='P'){window._startPhp();}}});
document.getElementById('mapSelector').addEventListener('click',e=>{const btn=e.target.closest('.map-btn');if(!btn)return;const idx=+btn.dataset.index;if(!isNaN(idx)&&idx<maps.length){activeMapIdx=idx;if(focusStacks&&focusMapIdx!==activeMapIdx){focusStacks=0;focusMapIdx=-1}refreshUI();checkTutorialProgress()}});
document.getElementById('btnRestart').addEventListener('click',()=>{tutorialStep=0;stepAchecked=!1;stepBunlocked=!1;stepBchecked=!1;step7map2created=!1;step7switched=!1;gm=4;sp=0;focusStacks=0;focusMapIdx=-1;inferMode=!1;inferResults.clear();timeStock=0;mindStock=0;boostStock=0;inspireStock=0;timeBonus=0;mindBonus=0;boostLevel=0;inspireCount=0;pUsed=false;usedPhpNames=[];shop={timeToSp:!1,timeMaster:!1,pocket:0,sharpIntuition:!1,convenience:!1,moneyPower:!1};remTime=40;remStamina=40;maxStaminaActual=40;phpFirstTime=true;clearAllShake();cleanupOstEl();hideAllUI();initTutorial()});
function hideAllUI(){document.getElementById('levelBanner').classList.add('hidden');document.getElementById('attrsPanel').classList.add('hidden');document.getElementById('activeSkillsBar').classList.add('hidden');document.getElementById('scoreProgressPanel').classList.add('hidden');document.getElementById('timePanel').classList.add('hidden');document.getElementById('mapSelector').classList.add('hidden');document.getElementById('infoBar').classList.add('hidden');document.getElementById('btnRestart').classList.add('hidden');document.getElementById('sidePanel').classList.add('hidden');document.getElementById('staminaBarOuter').classList.add('hidden');document.getElementById('staminaRefSpan').classList.add('hidden');document.getElementById('btnFocusSide').classList.add('hidden');document.getElementById('sideFocusBonus').style.display='none'}
function showUI(ids){ids.forEach(id=>{const el=document.getElementById(id);if(el)el.classList.remove('hidden')})}
function initTutorial(){maps=[createTutorialMap1()];activeMapIdx=0;computeLayout(maps[0]);remTime=40;remStamina=40;maxStaminaActual=40;gm=4;sp=0;focusStacks=0;focusMapIdx=-1;inferMode=!1;inferResults.clear();timeStock=0;mindStock=0;boostStock=0;inspireStock=0;timeBonus=0;mindBonus=0;boostLevel=0;inspireCount=0;nodeAnimations={};tutorialStep=0;stepAchecked=!1;stepBunlocked=!1;stepBchecked=!1;step7map2created=!1;step7switched=!1;pUsed=false;usedPhpNames=[];phpFirstTime=true;cleanupOstEl();hideAllUI();showUI(['canvasWrapper']);document.getElementById('canvasWrapper').classList.remove('inference');setTMsg('欢迎来到 OI 比赛模拟器教程!\n点击或在上面按下 E 键解锁根节点R\n初始时间/精力:40','highlight');refreshUI();gameStarted=!0}
function checkTutorialProgress(){const map=getActive();if(!map)return;switch(tutorialStep){case 0:{if(map.root&&map.root.state==='unlocked'){tutorialStep=1;setTMsg('很好!根节点已解锁。\n现在请先解锁节点A(左侧的重要检查节点,深色圆形)。\n⚠️请按顺序:先A后B','highlight');refreshUI()}break}case 1:{const a=map.nodeMap['A'];if(a&&a.state==='unlocked'){tutorialStep=2;setTMsg('节点A已解锁!现在检查它(点击有深色圆环的A或对着它按下 E 键)。\n检查会揭示它下面结果节点的信息。','highlight');refreshUI()}break}case 2:{const a=map.nodeMap['A'];if(a&&(a.state==='correct'||a.state==='incorrect')){stepAchecked=!0;tutorialStep=3;const maxSc=getMaxSub(a);setTMsg(`节点A已检查!它显示破碎痕迹——最高分${maxSc}分。\n这说明A下面没有100分的正确结果。\n现在解锁并检查A下面的一个结果节点。`,'highlight');refreshUI()}break}case 3:{const a=map.nodeMap['A'];if(a&&(a.state==='correct'||a.state==='incorrect')){const children=a.children.filter(c=>c.type==='result');const checked=children.find(c=>c.state==='correct'||c.state==='incorrect');if(checked){tutorialStep=4;setTMsg('结果节点已检查!\n现在解锁节点B(右侧的重要检查节点,方形)。\n⚠️B是另一个重要检查节点,请解锁它。','highlight');refreshUI()}}break}case 4:{const b=map.nodeMap['B'];if(b&&b.state==='unlocked'){stepBunlocked=!0;tutorialStep=5;setTMsg('节点B已解锁!现在检查它(点击有深色圆环的B)。\nB下面可能藏着正确结果。','highlight');refreshUI()}break}case 5:{const b=map.nodeMap['B'];if(b&&(b.state==='correct'||b.state==='incorrect')){stepBchecked=!0;tutorialStep=6;const hasCor=b._importantHasCorrect||b.state==='correct';if(hasCor){setTMsg('节点B已检查!注意看B外面的灰色方形虚线边框——\n这表示B的子树中有正确结果节点(100分)!\n正确结果节点是B2,请解锁并检查它。','highlight')}else{setTMsg('节点B已检查!现在解锁B下面的正确结果节点B2。','highlight')}refreshUI()}break}case 6:{const b=map.nodeMap['B'];const correctChild=b&&b.children.find(c=>c.isCorrect&&(c.state==='correct'));if(correctChild){tutorialStep=7;if(!step7map2created){step7map2created=!0;const map2=createTutorialMap2();computeLayout(map2);maps.push(map2);activeMapIdx=0}updateMapSelectorBtns2();showUI(['mapSelector']);document.getElementById('mapSelector').classList.remove('hidden');setTMsg('🎉太棒了!第一个地图的正确结果B2已找到!\n现在请注意上方出现了"题目切换界面"。\n请点击或按下 D 键切换到地图2,我们将在新地图中学习更多机制。','highlight');refreshUI()}break}case 7:{if(activeMapIdx===1&&maps.length>=2){step7switched=!0;tutorialStep=8;showUI(['timePanel']);document.getElementById('staminaBarOuter').classList.add('hidden');document.getElementById('staminaRefSpan').classList.add('hidden');setTMsg('很好!你切换到了地图2。\n现在请解锁根节点R2(点击它)。\n注意观察时间条的变化——解锁节点会消耗时间!','highlight');refreshUI()}break}case 8:{const m2=maps[1];if(m2&&m2.root&&m2.root.state==='unlocked'){tutorialStep=9;showUI(['sidePanel','staminaBarOuter','staminaRefSpan']);document.getElementById('btnFocusSide').classList.add('hidden');document.getElementById('sideFocusBonus').style.display='none';setTMsg('根节点R2已解锁!时间从40减为39(消耗1时间)。\n现在请解锁节点C(左侧的圆形重要节点)。\n⚠️注意:节点C的思维需求为6,而你当前思维为4。\n思维低于需求时,解锁需额外消耗精力(2精力而非1精力)!\n观察精力条的变化。','highlight');refreshUI()}break}case 9:{const m2=maps[1];const cNode=m2&&m2.nodeMap['C'];if(cNode&&cNode.state==='unlocked'){tutorialStep=10;remStamina+=8;setGM('☕精力恢复了8点','success');refreshUI();setTMsg('节点C已解锁!注意精力条减少了2点(而非通常的1点)。\n这就是思维低导致的额外精力消耗。\n系统已为你恢复8点精力。\n现在请解锁节点C下面的💎奖励节点(菱形技能节点),\n然后检查它。这个特殊节点可以提供技能点奖励!','highlight');refreshUI()}break}case 10:{const skNode=maps[1]&&maps[1].nodeMap['C_skill'];if(!skNode||skNode.state!=='correct')break;tutorialStep=11;sp+=20;syncAllSp();setTMsg('💎奖励节点已检查!获得20技能点!\n现在注意节点C下方出现了一个⏰时间存量节点(带橙色虚线的结果节点)。\n请解锁它,检查后你将获得时间存量。','highlight');refreshUI();break}case 11:{const sn=maps[1]&&maps[1].nodeMap['C_time_stock'];if(!sn||sn.state!=='unlocked')break;tutorialStep=12;setTMsg('时间存量节点已解锁!现在检查它来获得存量。','highlight');refreshUI();break}case 12:{const sn=maps[1]&&maps[1].nodeMap['C_time_stock'];if(!sn||(sn.state!=='correct'&&sn.state!=='incorrect'))break;tutorialStep=13;if(ostEl){ostEl.innerHTML='🎉时间存量已获得!你可以在商店中使用存量并付出一点技能点升级。\n要注意,存量每场比赛开始清空,要买可得抓紧\n珍贵的技能点可以通过拿到高分、AC 某道题或检查奖励节点获得。';ostEl.className='overlay-tut-msg highlight';ostEl.style.display='';}refreshUI();openShopOverlay();break}case 13:{break}case 14:{if(document.getElementById('shopOverlay').classList.contains('hidden')){tutorialStep=15;showUI(['levelBanner','sidePanel','activeSkillsBar','scoreProgressPanel','timePanel','mapSelector','infoBar','btnRestart','staminaBarOuter','staminaRefSpan']);document.getElementById('btnFocusSide').classList.remove('hidden');remTime=25+timeBonus;remStamina=25;maxStaminaActual=25;gm=Math.max(4,gm);const finalMaps=[];for(let i=0;i<4;i++){const md=createMap(minCorDepth(1),1);computeLayout(md);finalMaps.push(md)}const totalMaps=finalMaps.length;const allRes=[];finalMaps.forEach((md,mi)=>{Object.values(md.nodeMap).filter(n=>n.type==='result').forEach(r=>allRes.push({node:r,mapIdx:mi}))});const sel=shuf([...Array(allRes.length).keys()]).slice(0,totalMaps);const cnt={};sel.forEach(i=>{const{node,mapIdx}=allRes[i];if(!cnt[mapIdx])cnt[mapIdx]=0;if(cnt[mapIdx]<1&&node.type==='result'){node.type='skill';node.name='💎'+node.name;finalMaps[mapIdx].hasSkillNode=!0;finalMaps[mapIdx].skillNodeId=node.id;cnt[mapIdx]++}});maps=finalMaps;activeMapIdx=0;updateMapSelectorBtns2();document.getElementById('levelName').textContent='CSP-S练手';setTMsg('🎉教程完成!所有UI已显示。\n这是CSP-S级别的地图,试试用你学到的技能完成它吧!\n💡你仍可通过商店购买升级,存量可在商店中使用。\n灰色方形虚线边框=重要节点包含正确结果(100分)\n祝你好运!🚀','success');refreshUI()}break}}}
function updateMapSelectorBtns2(){const sel=document.getElementById('mapSelector');sel.innerHTML='';for(let i=0;i<maps.length;i++){const b=document.createElement('button');b.className='map-btn';b.dataset.index=i;b.textContent='⏳地图'+(i+1);sel.appendChild(b)}updateMapBtns()}
function openShopOverlay(){document.getElementById('shopOverlay').classList.remove('hidden');syncAllSp();initShopPanel();updateStockDisplay()}
function animLoop(){let needsRedraw=!1;const now=performance.now();for(const k in nodeAnimations){const a=nodeAnimations[k];if(a.type==='unlock'&&now-a.start<a.dur){needsRedraw=!0}else if(now-a.start>=a.dur){delete nodeAnimations[k];needsRedraw=!0}}if(needsRedraw&&getActive())drawTree(getActive());if(Object.keys(nodeAnimations).length>0)requestAnimationFrame(animLoop)}setInterval(()=>{if(Object.keys(nodeAnimations).length>0)animLoop()},50);
function getPhpStage(lv){if(lv<=1)return 0;if(lv<=4)return 1;if(lv<=7)return 2;if(lv<=10)return 3;if(lv===11)return 4;if(lv===12)return 5;return 6;}
window._startPhp=function(){if(pUsed){setGM('本阶段已经说过P话了','warning');return;}if(!playerName){setGM('请先设置名字','warning');return;}const totalScore=maps.reduce((s,m)=>s+(m.maxResultScore||0),0);const cfgName='CSP-S练手';let decrement=0,base=0;if(tutorialStep>=15||maps.length===4){decrement=5;base=200;}else{decrement=5;base=200;}const reduction=Math.max(0,Math.floor((totalScore-base)/50))*decrement;let result,spDelta=0;if(phpFirstTime){result='大成功';spDelta=5;phpFirstTime=false;}else{const rand=Math.floor(Math.random()*100)+1;const t1=20-reduction,t2=40-reduction,t3=60-reduction,t4=85-reduction;if(rand<=t1)result='大失败';else if(rand<=t2)result='失败';else if(rand<=t3)result='平淡';else if(rand<=t4)result='成功';else result='大成功';if(result==='大成功')spDelta=5;else if(result==='成功')spDelta=3;else if(result==='平淡')spDelta=0;else if(result==='失败')spDelta=-3;else if(result==='大失败')spDelta=-5;}sp+=spDelta;syncAllSp();let postText;const postOpts=[`${cfgName}只考了${totalScore}分区完了怎么办`,`${cfgName}拼尽全力只有${totalScore}未来如何`,`我在${cfgName}中获得了${totalScore}的高分,你也来试试吧`];postText=postOpts[Math.floor(Math.random()*postOpts.length)];const replies=[];const thresholdReduction=0;const blueT=Math.max(0,35-thresholdReduction);const greenT=Math.max(0,60-thresholdReduction);const orangeT=Math.max(0,90-thresholdReduction);const normalNames=["xjking","tyh2016_Ai_","Charles312","llamn","Phact","lyingOvO"];const used=new Set(usedPhpNames);function pickUniqueName(pool,specials,allowIvan){let available=pool.concat(specials).filter(n=>!used.has(n));if(allowIvan&&!used.has('Ivan422')&&Math.random()<0.05)available.push('Ivan422');if(available.length===0)return pool[Math.floor(Math.random()*pool.length)];const name=available[Math.floor(Math.random()*available.length)];used.add(name);return name;}for(let i=0;i<3;i++){let replyPool;if(result==='大成功')replyPool=["P","orz","%%%","膜拜","巨佬%%%","STO"];else if(result==='成功')replyPool=["P","orz","%%%","膜拜","巨佬%%%","STO","?!强强!?","我的一辈子","太巨了"];else if(result==='平淡')replyPool=["?!强强!?","P","我的一辈子","太巨了","遇 P 话哥,请举此牌","有这时间说 P 话不如多做几道黑题"];else if(result==='失败')replyPool=["遇 P 话哥,请举此牌","有这时间说 P 话不如多做几道黑题","就这","拉完了","bro 的实力还不够说 P 话","说 P 话有意思吗"];else if(result==='大失败')replyPool=["就这","拉完了","bro 的实力还不够说 P 话","说 P 话有意思吗"];const replyText=replyPool[Math.floor(Math.random()*replyPool.length)];let specials=[];if(result==='成功'||result==='大成功')specials=["txy120607","TLE_ZPB"];let name=pickUniqueName(normalNames,specials,true);let colorClass='';const isPurple=Math.random()<0.001;if(name==='txy120607'||name==='TLE_ZPB'){colorClass=isPurple?'name-purple':'name-red';}else if(isPurple){colorClass='name-purple';}else{const c=Math.floor(Math.random()*100)+1;if(c<=blueT)colorClass='name-blue';else if(c<=greenT)colorClass='name-green';else if(c<=orangeT)colorClass='name-orange';else colorClass='name-red';}replies.push({name,text:replyText,colorClass});}usedPhpNames=Array.from(used);const overlay=document.getElementById('phpOverlay');overlay.querySelector('.php-post-author').textContent=playerName||'匿名';overlay.querySelector('.php-post-content').textContent=postText;const repliesContainer=overlay.querySelector('.php-replies');repliesContainer.innerHTML='';const resultDiv=overlay.querySelector('.php-result');resultDiv.textContent=(spDelta>0?'+':'')+spDelta;resultDiv.style.display='none';overlay.classList.remove('hidden');pUsed=true;const btn=document.querySelector('.btn-php');if(btn)btn.disabled=true;let delay=500;replies.forEach((r,idx)=>{setTimeout(()=>{const div=document.createElement('div');div.className='php-reply';div.innerHTML=`<span class="php-reply-name ${r.colorClass}">${r.name}</span><span class="php-reply-content">${r.text}</span>`;repliesContainer.appendChild(div);if(idx===replies.length-1){resultDiv.style.display='flex';}},delay);delay+=500;});overlay.onclick=function(e){if(e.target===overlay){overlay.classList.add('hidden');}};};
hideAllUI();initTutorial();
})();</script></body></html>