mirror of
https://github.com/jarodlee/mini-browser-games.git
synced 2026-12-01 23:19:33 +08:00
100 lines
26 KiB
HTML
100 lines
26 KiB
HTML
<!doctype html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
<meta name="theme-color" content="#27363a">
|
|
<title>方块熔炉:十二张锻造蓝图</title>
|
|
<style>
|
|
:root{--ink:#243034;--muted:#66757a;--paper:#fff;--line:#b8c4c5;--deep:#27363a;--steel:#34708a;--mint:#3f8a72;--gold:#b67a26;--red:#b94f55;--violet:#705f8e;--radius:8px;--shadow:0 12px 30px rgba(39,54,58,.14)}
|
|
*{box-sizing:border-box;letter-spacing:0}html,body{margin:0;min-height:100%;color:var(--ink);background:#e7eceb;font-family:"Microsoft YaHei","PingFang SC",system-ui,sans-serif}button{font:inherit}.app{width:min(1180px,calc(100vw - 24px));margin:auto;padding:16px 0 30px}.head{display:flex;align-items:flex-end;justify-content:space-between;gap:18px;padding:17px 20px;border-bottom:4px solid #d5a346;color:#fff;background:var(--deep)}h1{margin:0;font-size:28px}.sub{margin:5px 0 0;color:#cfdbda;font-size:13px}.totals{display:flex;gap:18px;text-align:right}.totals b{display:block;color:#f0ca70;font-size:20px}.totals span{color:#c8d4d3;font-size:10px}.contracts{display:grid;grid-template-columns:repeat(12,minmax(42px,1fr));gap:5px;padding:11px 0}.contract{height:46px;border:1px solid #aab7b8;border-radius:6px;color:#405257;background:#f7f9f8;font-weight:900;cursor:pointer}.contract.active{border-color:var(--steel);color:#fff;background:var(--steel)}.contract:disabled{opacity:.42}.contract small{display:block;height:11px;color:#f2cc74;font-size:9px}.layout{display:grid;grid-template-columns:minmax(340px,720px) 330px;gap:14px;align-items:start}.forge{display:grid;grid-template-columns:minmax(280px,390px) minmax(150px,1fr);gap:12px;padding:12px;border:1px solid #8fa1a3;border-radius:var(--radius);background:#172125;box-shadow:var(--shadow)}.board-wrap{position:relative;display:grid;place-items:center;min-width:0}.board-wrap canvas{display:block;width:min(100%,390px);height:auto;aspect-ratio:1/2;border:1px solid #607477;border-radius:6px;background:#0e171a}.board-hud{position:absolute;inset:8px 8px auto;display:flex;justify-content:space-between;gap:6px;pointer-events:none}.board-hud span{padding:5px 7px;border:1px solid rgba(255,255,255,.2);border-radius:5px;color:#dce9e8;background:rgba(23,33,37,.86);font-size:10px}.forge-info{display:flex;flex-direction:column;gap:9px;min-width:0;color:#e9f0ef}.forge-info h2{margin:0;color:#fff;font-size:19px}.brief{margin:0;color:#b7c6c5;font-size:12px;line-height:1.55}.metrics{display:grid;grid-template-columns:1fr 1fr;gap:6px}.metric{padding:8px;border:1px solid #52666a;border-radius:6px;background:#202e32}.metric b{display:block;color:#6cd3c0;font-size:18px}.metric span{color:#a9b9b8;font-size:9px}.queue{display:flex;flex-wrap:wrap;gap:5px;min-height:38px}.piece-chip{display:grid;place-items:center;width:34px;height:34px;border:1px solid #607579;border-radius:5px;color:#fff;background:#26373b;font-weight:900}.hold-box{display:flex;align-items:center;justify-content:space-between;padding:8px;border:1px solid #53686b;border-radius:6px;background:#202e32}.hold-box b{color:#f1ca72;font-size:20px}.forge-status{min-height:65px;margin:0;padding:9px;border-left:4px solid var(--gold);color:#cfdbda;background:#202e32;font-size:11px;line-height:1.55}.side{display:flex;flex-direction:column;gap:10px}.panel{padding:12px;border:1px solid var(--line);border-radius:var(--radius);background:var(--paper)}.panel h3{margin:0 0 9px;font-size:14px}.rigs{display:grid;grid-template-columns:repeat(3,1fr);gap:5px}.rig{min-height:61px;padding:6px;border:1px solid #a9b7b8;border-radius:6px;color:#405257;background:#f0f4f3;font-size:9px;font-weight:900;cursor:pointer}.rig b{display:block;font-size:12px}.rig.active{border-color:var(--steel);color:#fff;background:var(--steel)}.commands,.archive{display:grid;grid-template-columns:1fr 1fr;gap:6px}.commands button,.archive button,.touch button{min-height:40px;border:1px solid #9dafb1;border-radius:6px;color:#34484d;background:#edf2f1;font-weight:900;cursor:pointer}.commands .primary{grid-column:1/-1;border-color:var(--steel);color:#fff;background:var(--steel)}.touch{display:grid;grid-template-columns:repeat(5,1fr);gap:5px;margin-top:8px}.touch button{padding:0;font-size:18px}.touch .wide{grid-column:span 2;font-size:12px}.help{margin:9px 0 0;color:var(--muted);font-size:11px;line-height:1.6}.overlay{position:absolute;inset:0;display:grid;place-items:center;padding:14px;background:rgba(13,22,25,.88);text-align:center}.overlay[hidden]{display:none}.overlay-card{width:min(350px,100%);padding:22px;border-radius:var(--radius);color:#fff;background:#2b3b3f;box-shadow:0 24px 60px rgba(0,0,0,.45)}.overlay-card h2{margin:0;font-size:24px}.overlay-card p{color:#d0dddc;line-height:1.6}.overlay-stars{color:#efc667;font-size:34px}.overlay-card button{min-height:42px;padding:0 20px;border:0;border-radius:6px;color:#293537;background:#efc667;font-weight:900;cursor:pointer}
|
|
@media(max-width:930px){.layout{grid-template-columns:1fr}.side{display:grid;grid-template-columns:1fr 1fr}.side .panel:first-child{grid-column:1/-1}}
|
|
@media(max-width:650px){.app{width:calc(100vw - 12px);padding-top:6px}.head{display:block;padding:13px}.head h1{font-size:23px}.totals{justify-content:space-between;margin-top:11px;text-align:left}.contracts{grid-template-columns:repeat(6,1fr)}.contract{height:39px}.forge{grid-template-columns:minmax(0,1fr);padding:7px}.board-wrap canvas{width:min(100%,340px)}.forge-info{padding:4px}.side{display:flex}.panel{padding:10px}.sub{font-size:11px}}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<main class="app">
|
|
<header class="head"><div><h1>方块熔炉:十二张锻造蓝图</h1><p class="sub">读取固定炉床与方块序列,让每一块嵌入蓝图缺口;连续清层、控制废渣并完成十二件锻造合同。</p></div><div class="totals"><div><b id="starTotal">0 / 36</b><span>锻造星章</span></div><div><b id="clearTotal">0 / 12</b><span>完成合同</span></div><div><b id="perfectTotal">0 / 12</b><span>无废渣</span></div></div></header>
|
|
<nav class="contracts" id="contracts" aria-label="锻造合同"></nav>
|
|
<section class="layout">
|
|
<section class="forge">
|
|
<div class="board-wrap"><canvas id="board" width="300" height="600" aria-label="熔炉棋盘"></canvas><div class="board-hud"><span>用时 <b id="clock">0.0s</b></span><span>分数 <b id="score">0</b></span></div><div class="overlay" id="overlay"><div class="overlay-card"><h2 id="overlayTitle"></h2><p id="overlayText"></p><div class="overlay-stars" id="overlayStars"></div><button id="overlayButton">开始</button></div></div></div>
|
|
<div class="forge-info"><h2 id="contractTitle"></h2><p class="brief" id="contractBrief"></p><div class="metrics"><div class="metric"><b id="lines">0 / 0</b><span>清除炉层</span></div><div class="metric"><b id="chain">0</b><span>连续成型</span></div><div class="metric"><b id="slag">0</b><span>废渣锁定</span></div><div class="metric"><b id="pieces">0 / 0</b><span>已用锻块</span></div></div><div><p class="brief">后续序列</p><div class="queue" id="queue"></div></div><div class="hold-box"><span>暂存模具</span><b id="hold">—</b></div><p class="forge-status" id="status"></p></div>
|
|
</section>
|
|
<aside class="side">
|
|
<section class="panel"><h3>选择炉型</h3><div class="rigs"><button class="rig" data-rig="steady"><b>稳态炉</b>一次回炉</button><button class="rig" data-rig="hot"><b>高温炉</b>硬降加分</button><button class="rig" data-rig="precise"><b>精密炉</b>显示蓝图</button></div></section>
|
|
<section class="panel"><div class="commands"><button class="primary" id="start">开始锻造</button><button id="pause">暂停</button><button id="restart">重开</button><button id="rewind">回炉</button><button id="holdButton">暂存 C</button></div><div class="touch" aria-label="触屏操作"><button data-action="left" title="左移">←</button><button data-action="rotate" title="旋转">↻</button><button data-action="right" title="右移">→</button><button data-action="down" title="软降">↓</button><button data-action="drop" title="硬降">⇊</button></div><p class="help">键盘:`A/D` 或左右键移动,`W/↑` 旋转,`S/↓` 软降,`Space` 硬降,`C` 暂存,`Z` 回炉。蓝色轮廓是精密炉显示的当前蓝图槽位。</p></section>
|
|
<section class="panel"><div class="archive"><button id="exportSave">导出档案</button><button id="importSave">导入档案</button></div></section>
|
|
</aside>
|
|
</section>
|
|
</main>
|
|
<script>
|
|
(()=>{
|
|
"use strict";
|
|
const W=10,H=20,SAVE_KEY="block_forge_v2",colors={I:"#49c8df",O:"#e9bd50",T:"#9b78c7",L:"#df8a45",J:"#568bd2",S:"#54b98b",Z:"#cf5c68",X:"#596a6d"},base={I:[[1,1,1,1]],O:[[1,1],[1,1]],T:[[0,1,0],[1,1,1]],L:[[1,0],[1,0],[1,1]],J:[[0,1],[0,1],[1,1]],S:[[0,1,1],[1,1,0]],Z:[[1,1,0],[0,1,1]]};
|
|
const contracts=[
|
|
{title:"青钢试炉",brief:"三种基础模具依次嵌入炉床,熟悉蓝图缺口与硬降。",limit:70,hold:1,waves:[["I",0,3],["O",0,1],["T",0,5]]},
|
|
{title:"双层铆接",brief:"方块会一次封合多层,观察轮廓高度后再落锤。",limit:72,hold:1,waves:[["O",0,6],["J",0,1],["I",0,4],["S",0,2]]},
|
|
{title:"折角梁柱",brief:"L 与 J 的方向相反,旋转错误会把废渣留在炉口。",limit:76,hold:1,waves:[["L",1,5],["J",3,1],["T",2,3],["O",0,7]]},
|
|
{title:"赤铜连铸",brief:"连续四次成型维持炉温,任何空投都会打断连铸。",limit:78,hold:0,waves:[["Z",0,1],["S",0,5],["I",1,8],["T",1,3]]},
|
|
{title:"四层淬火",brief:"竖直长条会同时封合四层,是本合同的核心锻序。",limit:82,hold:1,waves:[["I",1,2],["O",0,6],["L",2,1],["S",1,5],["T",0,3]]},
|
|
{title:"镜像齿轮",brief:"镜像模具交替出现,必须区分 S/Z 与 L/J 的咬合面。",limit:84,hold:1,waves:[["S",1,1],["Z",1,6],["L",3,2],["J",1,5],["O",0,7]]},
|
|
{title:"冷弯桁架",brief:"窄槽分布在两侧,墙踢可帮助模具贴近炉壁。",limit:88,hold:1,waves:[["J",0,0],["L",0,8],["I",0,2],["T",3,6],["Z",0,1]]},
|
|
{title:"白银回火",brief:"先处理高层薄片,再为竖直模具让出下降通道。",limit:90,hold:1,waves:[["I",0,5],["T",2,1],["I",1,8],["S",0,3],["O",0,0],["L",1,6]]},
|
|
{title:"棱角机芯",brief:"六枚不对称模具组成机芯,蓝图阅读比反应速度更重要。",limit:94,hold:1,waves:[["T",1,0],["L",2,6],["Z",1,3],["J",3,1],["S",0,6],["O",0,3]]},
|
|
{title:"金线重锻",brief:"连续多层封合提高得分,高温炉可以放大硬降收益。",limit:98,hold:1,waves:[["I",1,1],["I",0,5],["O",0,2],["T",0,6],["L",3,0],["Z",0,4]]},
|
|
{title:"星纹合金",brief:"七类模具全部进入序列,暂存只应处理一次顺序判断。",limit:104,hold:1,waves:[["S",1,7],["J",2,1],["O",0,5],["Z",0,0],["T",3,6],["L",1,2],["I",0,4]]},
|
|
{title:"冠冕终锻",brief:"七段蓝图覆盖全部方向,零废渣完成才是熔炉大师。",limit:110,hold:1,waves:[["T",2,3],["I",1,8],["L",3,1],["S",0,5],["J",1,0],["Z",1,6],["O",0,3]]}
|
|
];
|
|
const $=id=>document.getElementById(id),canvas=$("board"),ctx=canvas.getContext("2d"),overlay=$("overlay"),contractEl=$("contracts");let profile=load(),selected=0,rig=profile.rig||"steady",q=null,last=0,raf=0;
|
|
function defaults(){return{version:2,stars:{},best:{},perfect:{},rig:"steady",updatedAt:Date.now()}}
|
|
function normalize(value){const clean=defaults();if(!value||value.version!==2)return clean;for(let i=0;i<contracts.length;i++){clean.stars[i]=Math.max(0,Math.min(3,Number(value.stars?.[i])||0));if(Number.isFinite(Number(value.best?.[i])))clean.best[i]=Math.max(0,Number(value.best[i]));clean.perfect[i]=Boolean(value.perfect?.[i])}if(["steady","hot","precise"].includes(value.rig))clean.rig=value.rig;return clean}
|
|
function load(){try{return normalize(JSON.parse(localStorage.getItem(SAVE_KEY)))}catch{return defaults()}}
|
|
function save(){profile.rig=rig;profile.updatedAt=Date.now();localStorage.setItem(SAVE_KEY,JSON.stringify(profile));renderCampaign()}
|
|
function checksum(text){let h=2166136261;for(const ch of text){h^=ch.charCodeAt(0);h=Math.imul(h,16777619)}return(h>>>0).toString(36)}
|
|
function encodeProfile(){const body=btoa(unescape(encodeURIComponent(JSON.stringify(profile))));return`FORGE2.${body}.${checksum(body)}`}
|
|
function decodeProfile(code){const part=code.trim().split(".");if(part.length!==3||part[0]!=="FORGE2"||checksum(part[1])!==part[2])throw Error("锻造档案校验失败");return normalize(JSON.parse(decodeURIComponent(escape(atob(part[1])))))}
|
|
function rotate(matrix){return matrix[0].map((_,i)=>matrix.map(row=>row[i]).reverse())}
|
|
function shape(kind,rotation=0){let matrix=base[kind].map(row=>row.slice());for(let i=0;i<(rotation%4+4)%4;i++)matrix=rotate(matrix);return matrix}
|
|
function moldBoard(step){const [kind,rotation,x]=step,matrix=shape(kind,rotation),rows=[];for(let y=0;y<matrix.length;y++){const row=Array(W).fill("X");for(let z=0;z<matrix[y].length;z++)row[x+z]="";rows.push(row)}return Array.from({length:H-rows.length},()=>Array(W).fill("")).concat(rows)}
|
|
function compileContract(index){return contracts[index].waves.map(moldBoard)}
|
|
const plans=contracts.map((contract,index)=>({boards:compileContract(index),queue:contract.waves.map(([kind])=>kind),targetLines:contract.waves.reduce((sum,[kind,rotation])=>sum+shape(kind,rotation).length,0),signature:contract.waves.map(w=>w.join(":" )).join("|")}));
|
|
function cloneBoard(board){return board.map(row=>row.slice())}
|
|
function makeState(index=selected,simulation=false){const plan=plans[index],contract=contracts[index];return{index,contract,simulation,board:cloneBoard(plan.boards[0]),queue:plan.queue.slice(),cursor:0,blueprint:0,p:null,hold:"",canHold:true,lines:0,score:0,chain:0,maxChain:0,slag:0,pieces:0,elapsed:0,run:false,paused:false,ended:false,won:false,rewinds:rig==="steady"?1:0,snapshot:null}}
|
|
function hit(state,piece,dx=0,dy=0,matrix=piece.m){for(let y=0;y<matrix.length;y++)for(let x=0;x<matrix[y].length;x++)if(matrix[y][x]){const gx=piece.x+x+dx,gy=piece.y+y+dy;if(gx<0||gx>=W||gy>=H||gy>=0&&state.board[gy][gx])return true}return false}
|
|
function nextPiece(state){if(state.cursor>=state.queue.length){state.p=null;state.ended=true;state.run=false;state.won=state.blueprint>=state.contract.waves.length;return false}const kind=state.queue[state.cursor++];state.p={kind,m:shape(kind),rotation:0,x:3,y:0};state.canHold=true;if(hit(state,state.p)){state.ended=true;state.run=false;state.won=false;return false}return true}
|
|
function snapshot(state){state.snapshot={board:cloneBoard(state.board),queue:state.queue.slice(),cursor:state.cursor,blueprint:state.blueprint,p:state.p?{...state.p,m:state.p.m.map(r=>r.slice())}:null,hold:state.hold,canHold:state.canHold,lines:state.lines,score:state.score,chain:state.chain,maxChain:state.maxChain,slag:state.slag,pieces:state.pieces,elapsed:state.elapsed}}
|
|
function restore(state){if(!state.snapshot||state.rewinds<=0)return false;const copy=state.snapshot;Object.assign(state,{...copy,board:cloneBoard(copy.board),p:copy.p?{...copy.p,m:copy.p.m.map(r=>r.slice())}:null,rewinds:state.rewinds-1,run:true,paused:false,ended:false,won:false,snapshot:null});return true}
|
|
function moveState(state,dx,dy){if(!state.p||hit(state,state.p,dx,dy))return false;state.p.x+=dx;state.p.y+=dy;return true}
|
|
function rotateState(state){if(!state.p)return false;const matrix=rotate(state.p.m);for(const kick of [0,-1,1,-2,2])if(!hit(state,state.p,kick,0,matrix)){state.p.m=matrix;state.p.x+=kick;state.p.rotation=(state.p.rotation+1)%4;return true}return false}
|
|
function lockState(state){const piece=state.p,expected=state.contract.waves[state.blueprint],expectedMatrix=expected?shape(expected[0],expected[1]):[],expectedRows=expectedMatrix.length,correct=Boolean(expected&&piece.kind===expected[0]&&piece.rotation%4===expected[1]%4&&piece.x===expected[2]&&piece.y===H-expectedRows);for(let y=0;y<piece.m.length;y++)for(let x=0;x<piece.m[y].length;x++)if(piece.m[y][x]&&piece.y+y>=0)state.board[piece.y+y][piece.x+x]=piece.kind;if(correct)for(let y=H-expectedRows;y<H;y++)for(let x=0;x<W;x++)if(!state.board[y][x])state.board[y][x]="X";const cleared=state.board.filter(row=>row.every(Boolean)).length;state.board=state.board.filter(row=>!row.every(Boolean));while(state.board.length<H)state.board.unshift(Array(W).fill(""));state.lines+=cleared;state.pieces++;if(correct&&cleared===expectedRows){state.blueprint++;state.chain++;state.maxChain=Math.max(state.maxChain,state.chain);state.score+=[0,120,360,700,1200][cleared]*(1+state.chain*.12);if(state.blueprint<plans[state.index].boards.length)state.board=cloneBoard(plans[state.index].boards[state.blueprint])}else{state.chain=0;state.slag++}state.score=Math.round(state.score);return nextPiece(state)}
|
|
function hardDropState(state){if(!state.p)return 0;snapshot(state);let distance=0;while(moveState(state,0,1))distance++;state.score+=Math.round(distance*2*(rig==="hot"?1.5:1));lockState(state);return distance}
|
|
function holdState(state){if(!state.p||!state.canHold)return false;const current=state.p.kind;if(state.hold){const incoming=state.hold;state.hold=current;state.p={kind:incoming,m:shape(incoming),rotation:0,x:3,y:0};if(hit(state,state.p)){state.ended=true;state.run=false;state.won=false}}else{state.hold=current;nextPiece(state)}state.canHold=false;return true}
|
|
function stepState(state,dt){if(!state.run||state.paused||state.ended)return;state.elapsed+=dt;if(state.elapsed>=state.contract.limit){state.ended=true;state.run=false;state.won=false;return}state.fall=(state.fall||0)+dt;const interval=Math.max(.28,.78-state.index*.025);if(state.fall>=interval){state.fall=0;if(!moveState(state,0,1)){snapshot(state);lockState(state)}}}
|
|
function placeReference(state,step){const [kind,rotation,x]=step;if(!state.p||state.p.kind!==kind)throw Error("参考模具顺序错误");state.p.m=shape(kind,rotation);state.p.rotation=rotation;state.p.x=x;if(hit(state,state.p))throw Error("参考模具无法进入炉床");hardDropState(state)}
|
|
function simulateReference(index){const state=makeState(index,true);state.run=true;nextPiece(state);for(const step of contracts[index].waves){if(state.ended)break;placeReference(state,step)}return{won:state.won,lines:state.lines,slag:state.slag,pieces:state.pieces,maxChain:state.maxChain,score:state.score}}
|
|
function validateContent(){if(contracts.length!==12)throw Error("锻造合同数量错误");const signatures=new Set();let blueprintPieces=0,targetLines=0,referenceWins=0;for(let i=0;i<contracts.length;i++){const plan=plans[i];if(signatures.has(plan.signature))throw Error(`第 ${i+1} 张蓝图重复`);signatures.add(plan.signature);if(plan.boards.length!==contracts[i].waves.length)throw Error(`第 ${i+1} 张子蓝图缺失`);blueprintPieces+=plan.queue.length;targetLines+=plan.targetLines;const result=simulateReference(i);if(!result.won||result.slag||result.pieces!==plan.queue.length||result.lines!==plan.targetLines)throw Error(`第 ${i+1} 张参考锻序未通过`);referenceWins++}return{contracts:12,rigs:3,blueprintPieces,targetLines,referenceWins,uniqueBlueprints:signatures.size}}
|
|
function unlocked(index){return index===0||Number(profile.stars[index-1])>0}
|
|
function begin(index=selected){if(!unlocked(index))return;selected=index;q=makeState(index);renderAll();showOverlay("蓝图简报",`${q.contract.title}:固定序列包含 ${q.queue.length} 枚模具,目标封合 ${plans[index].targetLines} 层。`,"","点火",()=>{q.run=true;nextPiece(q);hideOverlay();setStatus("先观察炉床缺口,再移动和旋转当前模具。错误锁定会形成废渣并打断连续成型。")})}
|
|
function finalize(){if(!q?.ended)return;if(q.won){const stars=1+(q.slag===0?1:0)+(q.slag===0&&q.maxChain===q.contract.waves.length&&q.elapsed<=q.contract.limit?1:0);profile.stars[q.index]=Math.max(Number(profile.stars[q.index])||0,stars);profile.best[q.index]=Math.min(Number(profile.best[q.index])||Infinity,q.elapsed);profile.perfect[q.index]=profile.perfect[q.index]||q.slag===0;save();renderAll();showOverlay("锻件验收通过",`封合 ${q.lines} 层,连续成型 ${q.maxChain},废渣 ${q.slag}。`,"★".repeat(stars)+"☆".repeat(3-stars),q.index<11?"下一张蓝图":"返回合同簿",()=>{const next=q.index<11?q.index+1:q.index;selected=next;begin(next)})}else showOverlay("锻件未成型",q.elapsed>=q.contract.limit?"炉温窗口已经结束。":"固定模具已经用完,但蓝图仍有缺口。","","重新点火",()=>begin(q.index))}
|
|
function perform(action){if(!q?.run||q.paused||q.ended)return;if(action==="left")moveState(q,-1,0);if(action==="right")moveState(q,1,0);if(action==="down"){if(!moveState(q,0,1)){snapshot(q);lockState(q)}else q.score++}if(action==="rotate")rotateState(q);if(action==="drop")hardDropState(q);if(action==="hold")holdState(q);if(action==="rewind")restore(q);renderAll();if(q.ended)finalize()}
|
|
function setStatus(text){$("status").textContent=text}
|
|
function showOverlay(title,text,stars,label,handler){$("overlayTitle").textContent=title;$("overlayText").textContent=text;$("overlayStars").textContent=stars;$("overlayButton").textContent=label;$("overlayButton").onclick=handler;overlay.hidden=false}
|
|
function hideOverlay(){overlay.hidden=true}
|
|
function renderCampaign(){contractEl.innerHTML=contracts.map((contract,index)=>`<button class="contract ${index===selected?"active":""}" data-index="${index}" ${unlocked(index)?"":"disabled"}>${String(index+1).padStart(2,"0")}<small>${"★".repeat(Number(profile.stars[index])||0)}</small></button>`).join("");$("starTotal").textContent=`${Object.values(profile.stars).reduce((a,b)=>a+Number(b||0),0)} / 36`;$("clearTotal").textContent=`${Object.values(profile.stars).filter(Boolean).length} / 12`;$("perfectTotal").textContent=`${Object.values(profile.perfect).filter(Boolean).length} / 12`;document.querySelectorAll(".rig").forEach(button=>button.classList.toggle("active",button.dataset.rig===rig))}
|
|
function renderInfo(){if(!q)return;$("contractTitle").textContent=`${String(q.index+1).padStart(2,"0")} · ${q.contract.title}`;$("contractBrief").textContent=q.contract.brief;$("lines").textContent=`${q.lines} / ${plans[q.index].targetLines}`;$("chain").textContent=q.maxChain;$("slag").textContent=q.slag;$("pieces").textContent=`${q.pieces} / ${q.contract.waves.length}`;$("clock").textContent=`${q.elapsed.toFixed(1)}s`;$("score").textContent=q.score;$("hold").textContent=q.hold||"—";$("queue").innerHTML=q.queue.slice(q.cursor,q.cursor+7).map(kind=>`<span class="piece-chip" style="border-color:${colors[kind]}">${kind}</span>`).join("")||"<span class='brief'>序列已尽</span>";$("rewind").textContent=`回炉 ${q.rewinds}`}
|
|
function drawBlock(x,y,kind,alpha=1,outline=false){const z=canvas.width/W;ctx.globalAlpha=alpha;if(outline){ctx.strokeStyle="#65d6e5";ctx.lineWidth=2;ctx.strokeRect(x*z+3,y*z+3,z-6,z-6)}else{ctx.fillStyle=colors[kind]||colors.X;ctx.fillRect(x*z+1,y*z+1,z-2,z-2);ctx.fillStyle="rgba(255,255,255,.16)";ctx.fillRect(x*z+3,y*z+3,z-6,4)}ctx.globalAlpha=1}
|
|
function draw(){if(!q)return;const z=canvas.width/W;ctx.fillStyle="#0d1719";ctx.fillRect(0,0,canvas.width,canvas.height);for(let y=0;y<H;y++)for(let x=0;x<W;x++){ctx.strokeStyle="#1c2a2d";ctx.strokeRect(x*z,y*z,z,z);if(q.board[y][x])drawBlock(x,y,q.board[y][x])}const step=q.contract.waves[q.blueprint];if(step&&!q.ended){const matrix=shape(step[0],step[1]),targetY=H-matrix.length;if(rig==="precise"){ctx.fillStyle="rgba(73,200,223,.07)";ctx.fillRect(step[2]*z,0,matrix[0].length*z,targetY*z)}for(let a=0;a<matrix.length;a++)for(let b=0;b<matrix[a].length;b++)if(matrix[a][b])drawBlock(step[2]+b,targetY+a,step[0],1,true)}if(q.p){const ghost={...q.p,y:q.p.y};while(!hit(q,ghost,0,1))ghost.y++;for(let y=0;y<ghost.m.length;y++)for(let x=0;x<ghost.m[y].length;x++)if(ghost.m[y][x])drawBlock(ghost.x+x,ghost.y+y,ghost.kind,.22);for(let y=0;y<q.p.m.length;y++)for(let x=0;x<q.p.m[y].length;x++)if(q.p.m[y][x]&&q.p.y+y>=0)drawBlock(q.p.x+x,q.p.y+y,q.p.kind)}}
|
|
function renderAll(){renderCampaign();renderInfo();draw()}
|
|
function loop(time){const dt=Math.min(.05,(time-last)/1000||0);last=time;if(q){const before=q.ended;stepState(q,dt);renderInfo();draw();if(!before&&q.ended)finalize()}raf=requestAnimationFrame(loop)}
|
|
contractEl.addEventListener("click",event=>{const button=event.target.closest("[data-index]");if(button){selected=Number(button.dataset.index);begin(selected)}});document.querySelectorAll(".rig").forEach(button=>button.addEventListener("click",()=>{if(q?.run)return;rig=button.dataset.rig;save();renderAll()}));document.querySelectorAll("[data-action]").forEach(button=>button.addEventListener("pointerdown",event=>{event.preventDefault();perform(button.dataset.action)}));
|
|
addEventListener("keydown",event=>{const map={ArrowLeft:"left",KeyA:"left",ArrowRight:"right",KeyD:"right",ArrowDown:"down",KeyS:"down",ArrowUp:"rotate",KeyW:"rotate",Space:"drop",KeyC:"hold",KeyZ:"rewind"};if(map[event.code]){event.preventDefault();perform(map[event.code])}if(event.code==="KeyP")$("pause").click()});
|
|
$("start").onclick=()=>begin(selected);$("restart").onclick=()=>begin(q?.index??selected);$("holdButton").onclick=()=>perform("hold");$("rewind").onclick=()=>perform("rewind");$("pause").onclick=()=>{if(!q||q.ended)return;q.paused=!q.paused;$("pause").textContent=q.paused?"继续":"暂停";setStatus(q.paused?"熔炉已暂停。":"熔炉继续运转。")};
|
|
$("exportSave").onclick=async()=>{const code=encodeProfile();try{await navigator.clipboard.writeText(code);setStatus("锻造档案已复制。") }catch{prompt("复制锻造档案",code)}};$("importSave").onclick=()=>{const code=prompt("粘贴 FORGE2 锻造档案");if(!code)return;try{profile=decodeProfile(code);rig=profile.rig;save();setStatus("锻造档案已导入。");begin(selected)}catch(error){setStatus(error.message)}};
|
|
q=makeState(0);renderAll();showOverlay("熔炉待机","选择炉型与合同。固定蓝图中的灰色砖层不会移动,依次把彩色模具嵌入空槽即可完成锻件。","","查看蓝图",()=>begin(selected));raf=requestAnimationFrame(loop);
|
|
window.__blockForgeTest={contracts,plans,shape,compileContract,makeState,simulateReference,validateContent,begin,getState:()=>q,getProfile:()=>profile,encodeProfile,decodeProfile,perform,forceFinish(){if(!q)return;q.lines=plans[q.index].targetLines;q.slag=0;q.maxChain=q.contract.waves.length;q.pieces=q.contract.waves.length;q.ended=true;q.run=false;q.won=true;finalize()}};
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>
|