feat: shake the puzzle tank with single flick gestures

This commit is contained in:
2026-10-16 23:05:58 +08:00
parent 63dbedf457
commit 465fee1d07
11 changed files with 159 additions and 45 deletions
+10 -7
View File
@@ -16,6 +16,7 @@ npm run test:browser
npm run test:results
npm run test:interactions
npm run test:container
npm run test:swipes
```
浏览器测试目前默认使用 macOS 已安装的 Google Chrome,路径见 `tests/browser.mjs`。构建要求 Python 3,以及官方 [minitool-zip-builder 1.8.0 Skill](https://fe-static.xhscdn.com/minitool/20261015161653/minitool-zip-builder-1.8.0.skill)。克隆后需将 Skill 解压到本地 `.codex/skills/minitool-zip-builder/`,该目录应直接包含 `SKILL.md`、`references/` 和 `scripts/`。本地工具、依赖、构建输出和报告均已忽略,不推送到代码库。所有运行依赖与地图随最终 ZIP 提供,无联网运行逻辑。
@@ -36,9 +37,9 @@ npm run test:container
## 玩法与得分
进入页选择省级 / 地级版、地区、四档下落速度和三档弹性,点击“开启这局旅程”后开局。独立的整屏游戏页底部提供“左晃 / 上晃 / 右晃”:左右支持按住,向上点击轻颠,也支持键盘 ← ↑ →。操作的是整个框和其中所有组合,没有单片拖动、旋转或加速。弹跳和倾斜有上限,松手后自动回正。
进入页选择省级 / 地级版、地区、四档下落速度和三档弹性,点击“开启这局旅程”后开局。在容器内快速轻划并松手,给容器一次惯性晃动;划过位置附近的地块反应更强。每次轻划只在松手时触发一次,地块获得带少量方向、力度差异的冲量后自由运动,手指只能决定大致方向。慢拖、按住、取消触摸或暂停不会持续施力,也不会抓取、牵引或瞬移单块碎片。底部只有一个无文字的圆形暂停图标,统一查看本局旅程、继续、结束或重开;电脑保留方向键辅助。弹跳、倾斜和速度有上限。
只有真实相邻关系、正确地理位置接近时才自动吸合。全部落下后仍可晃动,直到通关、稳定堆过红线超过 2.4 秒,或主动结束。顶部暂停 / 返回都打开暂停页,可继续、结束旅程、重新开局。结束旅程会保留成绩,即使零分或未通关也会生成图片;通关和判负自动生成。
只有真实相邻关系、正确地理位置接近时才自动吸合。全部落下后仍可晃动,直到通关、稳定堆过红线超过 2.4 秒,或主动结束。底部圆形暂停图标打开旅程菜单,可继续、结束旅程、重新开局。结束旅程会保留成绩,即使零分或未通关也会生成图片;通关和判负自动生成。
省级海岛使用明确标注的“跨海连接”;地级版中因海域、未纳入本关的省直辖县等产生的间隔,使用明确标注的“隔区连接”。这两种连接都是游戏规则,不能当作陆地邻接关系。入口地图保留相对地理位置。
@@ -49,7 +50,7 @@ npm run test:container
| 一路狂飙 | 4 秒 | 0.7 | ×2 |
| 山河起飞 | 2.5 秒 | 1 | ×3 |
每次合并分数 = `(100 + 40 × (合并后块数 − 2)) × 连合系数 × 速度倍率 × 特殊连接系数`,四舍五入到整数。8.5 秒内再次合并视为连合,系数每次增加 0.25,从 1 起、最高 2;跨海和隔区连接额外乘 0.8。通关再奖 `1000 × 速度倍率`。三向晃动不限次数、不扣分。弹性不改变得分倍率。
每次合并分数 = `(100 + 40 × (合并后块数 − 2)) × 连合系数 × 速度倍率 × 特殊连接系数`,四舍五入到整数。8.5 秒内再次合并视为连合,系数每次增加 0.25,从 1 起、最高 2;跨海和隔区连接额外乘 0.8。通关再奖 `1000 × 速度倍率`。轻划不限次数、不扣分。弹性不改变得分倍率。
弹性三档为“轻轻弹 / 蹦蹦跳 / 弹力全开”,碰撞恢复系数分别为 0.65 / 0.82 / 0.96,同时调整空气阻力、横向冲量和上抛上限。现在最低档对应上一版最高档;默认推荐“蹦蹦跳”,便于腾挪,“弹力全开”需要更好地控制节奏。省级、地级碎片均在上一版基础上线性再缩小 10%;地级仍比相同地图基准额外小 30%;组合过大时仍会全局等比缩放。
@@ -66,8 +67,8 @@ npm run test:container
## 代码与数据
- `src/core.js`:相邻关系、地理位置与角度吸合判断、计分、纪录清洗。
- `src/game.js`:Matter.js 刚体、出片、组合、胜负、速度、弹性、三向容器晃动、得分时间点和尺寸变化。
- `src/app.js`:入口 / 游戏 / 成绩页切换、Canvas 绘制、三向输入、暂停与结束、原生 Storage、发笔记和相册导出。
- `src/game.js`:Matter.js 刚体、出片、组合、胜负、速度、弹性、容器滑动与上晃、得分时间点和尺寸变化。
- `src/app.js`:入口 / 游戏 / 成绩页切换、Canvas 绘制、容器手势与键盘输入、暂停与结束、原生 Storage、发笔记和相册导出。
- `src/result.js`:真实结局快照与得分曲线的成绩图绘制。
- `src/index.html`、`src/style.css`:单入口、响应式布局、安全区和 Chrome 61 样式基线。
- `src/maps.js`:构建期简化的省级 / 地级真实轮廓与预计算连接图。
@@ -88,7 +89,7 @@ npm run test:container
棋盘改为较窄的开口实体容器,侧壁和底边清晰可见,红色警戒线位于顶部 78px。以 320×435 逻辑尺寸为例,全国开局缩放约 0.4995,相对最初约 0.215 的版本仍明显更大,本轮比上一版的0.555再缩小10%。保持各省之间真实比例,微小地区保持真实相对比例,同样通过框体晃动参与拼接。
晃动采用阻尼弹簧模型:容器位移和施加给所有碎片的惯性来自同一状态,并有 14px 的视觉位移限制。左右按钮和键盘左右键均可以持续按住,松开即停止继续施力。无需加速度计或设备运动 API。
晃动采用阻尼弹簧模型:容器位移和施加给所有碎片的惯性来自同一状态,并有 14px 的视觉位移限制。在容器内滑动可朝任意方向施加冲量,力度随滑速增加,按与手指的距离平滑衰减;所有组合都受影响,近处更强。移动时只采集手势,在松手时识别一次轻划;使用最近约180ms轨迹,位移至少18px、平均速度至少0.16px/ms,慢拖和按住不触发。触发间隔至少240ms,系统取消或暂停清理尚未触发的手势。键盘左右键仍支持长按。无需加速度计或设备运动 API。
较大组合超出容器可用空间时,全体碎片按相同比例缩小,保持地理相对比例、分数与队列,继续容纳完整地图。难度和拥堵由关卡形状、晃动、速度及弹性共同影响;本地模拟只用于排查物理问题,不能推断真机性能或玩家通关难度。
@@ -110,8 +111,10 @@ npm run test:container
入口和游戏页均按可见视口及安全区排版:在320×568、375×667、390×844以及740×390横屏检查一屏显示;小屏会缩减装饰地图和冗余文案,保留所有主要选择与开局按钮。省区选择采用27项网格,不再使用原生长下拉框,弹窗注明无地级数据的范围。
四档名称为“佛系看山 / 说走就走 / 一路狂飙 / 山河起飞”,速度与倍率参数保持原值。三个晃动按钮居中排版,成绩页同样一屏显示。游戏地图先绘制全部形状,再统一绘制标签;名称采用独立布局、边距约束、避让,以及小地区标签底色 / 引线,防止名称贴底被裁或被其他省份覆盖。
四档名称为“佛系看山 / 说走就走 / 一路狂飙 / 山河起飞”,速度与倍率参数保持原值。底部仅保留无文字的圆形暂停图标,合并全部旅程操作,容器顶部说明标签已移除,成绩页同样一屏显示。游戏地图先绘制全部形状,再统一绘制标签;名称采用独立布局、边距约束、避让,以及小地区标签底色 / 引线,防止名称贴底被裁或被其他省份覆盖。
构建补回源数据的小离岛外环及独立海域线层,34省级代码、名称及外环数量均与保存的原始数据对比。台湾省14个源外环、香港9个、澳门2个、海南133个全部保留。详见`artifacts/MAP_AUDIT.md`,这不是标准地图审图结论。
`npm run test:container`在现代浏览器模拟平台顶部按钮与四组手机尺寸/安全区,逐页点击并检查布局,不替代小红书真机验证。
`tests/swipes.mjs` 使用真实触摸事件验证单次轻划松手触发、移动中不施力、慢拖和按住过滤、松手后的惯性运动、系统取消、滑动中暂停和恢复、圆形无文字菜单;物理单测另检查附近力度更强、远处仍动、快速更有力和三档边界限制。
+2 -1
View File
@@ -11,7 +11,8 @@
"test:browser": "node tests/browser.mjs",
"test:results": "node tests/results.mjs",
"test:interactions": "node tests/interactions.mjs",
"test:container": "node tests/container-layout.mjs"
"test:container": "node tests/container-layout.mjs",
"test:swipes": "node tests/swipes.mjs"
},
"dependencies": {
"matter-js": "0.20.0",
+36 -18
View File
@@ -5,7 +5,7 @@ var colors=['#c3d4b4','#e3c78f','#d2b5a5','#b5cbd0','#d2c69d','#b1c5a0','#d9bca6
var provinceCode='330000',mode='province',speed=0,bounce=1,result=null,level=data.levels[0],game=null,screen='entry',records={},pausedByModal=false,toastTimer=null;
var canvas=$('board'),ctx=canvas.getContext('2d'),w=0,h=0,dpr=1,miniTool=null,storageNative=false,storeReady=false,saveChain=Promise.resolve();
var reducedMotion=typeof window.matchMedia==='function'?window.matchMedia('(prefers-reduced-motion: reduce)'):null,modeGesture=null,suppressModeClickUntil=0;
var holdTimer=null,inputDirection=0,pointerDirection=0,keys={left:false,right:false},rafId=0,last=0,uiAt=0,lastLabelBoxes=[],labelObstacles=[];
var holdTimer=null,inputDirection=0,tankGesture=null,swipeTrace=null,keys={left:false,right:false},rafId=0,last=0,uiAt=0,lastLabelBoxes=[],labelObstacles=[];
function motionAllowed(){return !reducedMotion||!reducedMotion.matches;}
function pulseButton(button,kind){if(!button||button.disabled||!motionAllowed())return;button.classList.remove('tap-pop','bounce-pop');void button.offsetWidth;button.classList.add(kind||'tap-pop');}
document.addEventListener('animationend',function(e){if(e.target.classList){e.target.classList.remove('tap-pop','bounce-pop');}});
@@ -30,7 +30,7 @@ function layout(){
if(screen==='entry'){fitEntryMap();drawReference();return;}if(screen==='result'){fitCard();return;}
var r=canvas.getBoundingClientRect(),nw=Math.round(r.width),nh=Math.round(r.height);
if(nw<1||nh<1)return;
var changed=w!==nw||h!==nh;w=nw;h=nh;sizeCanvas(canvas,w,h);labelObstacles=['board-name','board-status'].map(function(id){var box=$(id).getBoundingClientRect();return {x:box.left-r.left-3,y:box.top-r.top-2,w:box.width+6,h:box.height+4};});var danger=document.querySelector('.danger-label').getBoundingClientRect();labelObstacles.push({x:danger.left-r.left-3,y:danger.top-r.top-2,w:danger.width+6,h:danger.height+4});
var changed=w!==nw||h!==nh;w=nw;h=nh;sizeCanvas(canvas,w,h);labelObstacles=['board-status'].map(function(id){var box=$(id).getBoundingClientRect();return {x:box.left-r.left-3,y:box.top-r.top-2,w:box.width+6,h:box.height+4};});var danger=document.querySelector('.danger-label').getBoundingClientRect();labelObstacles.push({x:danger.left-r.left-3,y:danger.top-r.top-2,w:danger.width+6,h:danger.height+4});
if(game&&changed)game.resize(w,h);drawNext();if(game)draw();
}
function fitEntryMap(){
@@ -49,12 +49,11 @@ function closeModal(resume){$('province-picker').classList.remove('expanded');va
$('modal').addEventListener('cancel',function(e){e.preventDefault();closeModal();});$('close-modal').addEventListener('click',function(){closeModal();});
function start(){
stopInput();result=null;lastLabelBoxes=[];if(game)game.destroy();game=null;screen='game';document.body.classList.add('is-playing');$('entry-screen').hidden=true;$('result-screen').hidden=true;$('game-screen').hidden=false;window.scrollTo(0,0);
$('board-status').textContent='左右轻摇 / 向上轻颠,晃动整个框';$('tank').style.transform='translateX(0px)';layout();
$('board-status').textContent='轻划后松手,让山河随惯性相遇';$('tank').style.transform='translateX(0px)';layout();
game=new Engine.Game(level,w,h,speed,onGameEvent,null,bounce);game.start();last=0;drawNext();updateUI();schedule();
}
function showEntry(){stopInput();cancelAnimationFrame(rafId);rafId=0;if(game)game.destroy();game=null;lastLabelBoxes=[];screen='entry';document.body.classList.remove('is-playing');$('game-screen').hidden=true;$('result-screen').hidden=true;$('entry-screen').hidden=false;result=null;$('tank').style.transform='translateX(0px)';window.scrollTo(0,0);updateUI();layout();}
function finishJourney(){closeModal(false);if(game)game.finish();}
function askBack(){pause();}
function pause(){if(!game||screen!=='game'||$('modal').hasAttribute('open'))return;if(game.endReason){showResult();return;}openModal('TAKE A BREATH','<h2>山河等你回来</h2><p>'+level.name+' · '+Engine.SPEEDS[speed].name+' · '+Engine.BOUNCES[bounce].name+'</p><p>暂停不计时。随时结束,也能带走这一程的成绩图。</p>',[{label:'继续游戏',primary:true,action:function(){closeModal();}},{label:'结束旅程',action:finishJourney},{label:'重新开局',action:function(){closeModal(false);start();}}]);}
function onGameEvent(type,detail){
if(type==='spawn'){drawNext();if(game.queue.length===0)$('board-status').textContent='碎片已全部落下 · 继续晃动容器';}
@@ -69,16 +68,12 @@ function updateUI(){
$('city-select-panel').hidden=mode!=='city';$('city-note').textContent='27 个省区可选 · 仅拼地级市、自治州、地区、盟';
$('multiplier').textContent='得分 ×'+config.multiplier;var comments=['慢慢来,也能看见山河','找到自己的拼图节奏','眼疾手快,山河相逢','留给地理高手的挑战'];$('speed-note').textContent=config.interval/1000+' 秒落下一块 · '+comments[speed];
document.querySelectorAll('[data-mode]').forEach(function(b){var selected=b.getAttribute('data-mode')===mode;b.classList.toggle('selected',selected);b.setAttribute('aria-pressed',String(selected));});
var modeTabs=document.querySelector('.mode-tabs');
modeTabs.addEventListener('pointerdown',function(e){if(screen==='entry'&&e.isPrimary!==false)modeGesture={x:e.clientX,y:e.clientY,id:e.pointerId};});
document.addEventListener('pointerup',function(e){if(!modeGesture||modeGesture.id!==e.pointerId)return;var dx=e.clientX-modeGesture.x,dy=e.clientY-modeGesture.y;modeGesture=null;if(screen==='entry'&&Math.abs(dx)>35&&Math.abs(dx)>Math.abs(dy)*1.3){mode=dx<0?'city':'province';suppressModeClickUntil=performance.now()+350;selectLevel();}});
document.addEventListener('pointercancel',function(){modeGesture=null;});
document.querySelectorAll('[data-speed]').forEach(function(b){var selected=Number(b.getAttribute('data-speed'))===speed;b.classList.toggle('selected',selected);b.setAttribute('aria-pressed',String(selected));});
document.querySelectorAll('[data-bounce]').forEach(function(b){var selected=Number(b.getAttribute('data-bounce'))===bounce;b.classList.toggle('selected',selected);b.setAttribute('aria-pressed',String(selected));});
var playable=!!game&&game.status==='playing';$('left').disabled=!playable;$('right').disabled=!playable;$('up').disabled=!playable;$('pause').disabled=!game;
$('pause').disabled=!game;
if(!game)return;
$('score').textContent=game.score.toLocaleString('zh-CN');$('merged').textContent=game.groups.reduce(function(n,g){return Math.max(n,g.ids.length);},0);$('total').textContent=level.regions.length;
$('game-title').textContent=level.name+(mode==='city'?' · 地级拼图':'');$('game-speed').textContent=config.name+' · '+Engine.BOUNCES[bounce].name+' · ×'+config.multiplier;$('board-name').textContent='山河容器 · 碰撞后自动回正';
$('game-title').textContent=level.name+(mode==='city'?' · 地级拼图':'');$('game-speed').textContent=config.name+' · '+Engine.BOUNCES[bounce].name+' · ×'+config.multiplier;
$('progress-label').textContent='已落下 '+game.dropped+' / '+level.regions.length+' 块'+(game.maxChain>1?' · 最佳 '+game.maxChain+' 连合':'');
}
function polygon(context,ring,transform){context.beginPath();ring.forEach(function(p,i){var q=transform(p);if(i===0)context.moveTo(q.x,q.y);else context.lineTo(q.x,q.y);});context.closePath();}
@@ -107,19 +102,42 @@ function contactTransform(g){
}
function draw(){if(!game)return;ctx.clearRect(0,0,w,h);ctx.fillStyle='#f1f2e9';ctx.fillRect(0,0,w,h);ctx.fillStyle='#d8decd';for(var x=15;x<w;x+=22)for(var y=16;y<h;y+=22){ctx.beginPath();ctx.arc(x,y,.65,0,Math.PI*2);ctx.fill();}ctx.strokeStyle=game.overflow>0?'#bd3e42':'#d46e70';ctx.setLineDash([4,5]);ctx.beginPath();ctx.moveTo(0,Engine.DANGER_Y);ctx.lineTo(w,Engine.DANGER_Y);ctx.stroke();ctx.setLineDash([]);
var labels=[];game.groups.forEach(function(g){var trans=contactTransform(g);g.ids.forEach(function(i){var r=level.regions[i];drawPiece(ctx,r,i,trans,{label:false,physical:true,impact:motionAllowed()&&g.hitUntil>game.clock});var points=r.rings[0].map(trans),xs=points.map(function(p){return p.x;}),ys=points.map(function(p){return p.y;}),rw=Math.max.apply(null,xs)-Math.min.apply(null,xs),rh=Math.max.apply(null,ys)-Math.min.apply(null,ys);labels.push({name:mode==='province'?shortName(r.name):r.name,anchor:trans(r.label||r.center),tiny:rw<32||rh<25});});if(g.ids.length===level.regions.length)drawDecorations(ctx,trans);});
if(swipeTrace&&swipeTrace.until>game.clock&&motionAllowed()){var life=(swipeTrace.until-game.clock)/280;ctx.save();ctx.globalAlpha=life*.30;ctx.strokeStyle='#9b8b62';ctx.lineWidth=1.5;ctx.beginPath();ctx.arc(swipeTrace.x,swipeTrace.y,9+(1-life)*12,0,Math.PI*2);ctx.moveTo(swipeTrace.x,swipeTrace.y);var length=Math.max(1,Math.hypot(swipeTrace.dx,swipeTrace.dy));ctx.lineTo(swipeTrace.x+swipeTrace.dx/length*19,swipeTrace.y+swipeTrace.dy/length*19);ctx.stroke();ctx.restore();}
lastLabelBoxes=renderLabels(ctx,labels,w,h,Math.max(9,Math.min(12,12*Math.sqrt(game.zoom))),labelObstacles);
if(motionAllowed())game.impacts.forEach(function(f){var life=Math.max(0,(f.until-game.clock)/Engine.SPARK_MS),radius=1.5+(1-life)*(2+f.strength*2);ctx.save();ctx.globalAlpha=life*.38;ctx.strokeStyle='#b8a779';ctx.lineWidth=1;ctx.beginPath();ctx.arc(f.x,f.y,radius,0,Math.PI*2);ctx.stroke();for(var i=0;i<2;i++){var angle=i*Math.PI+.7;ctx.beginPath();ctx.moveTo(f.x+Math.cos(angle)*(radius+1),f.y+Math.sin(angle)*(radius+1));ctx.lineTo(f.x+Math.cos(angle)*(radius+3),f.y+Math.sin(angle)*(radius+3));ctx.stroke();}ctx.restore();});
game.fx.forEach(function(f){ctx.save();ctx.globalAlpha=Math.min(1,(f.until-game.clock)/500);ctx.textAlign='center';ctx.font='500 12px sans-serif';ctx.fillStyle='#557642';ctx.fillText(f.text,Math.max(70,Math.min(w-70,f.x)),f.y-28-(1600-f.until+game.clock)*.018);ctx.restore();});
}
function schedule(){if(!rafId&&!document.hidden&&game)rafId=requestAnimationFrame(frame);}
function frame(t){rafId=0;if(!game||screen!=='game')return;if(!last)last=t;game.tick(t-last);last=t;if(screen!=='game')return;$('tank').style.transform='translate('+game.shake.offset.toFixed(2)+'px,'+game.shake.y.toFixed(2)+'px)';$('tank').classList.toggle('impact',game.wallHitUntil>game.clock);draw();if(t-uiAt>120){uiAt=t;updateUI();}if(game.status==='playing')schedule();}
function stopInput(){if(game)game.groups.forEach(function(g){g.pendingHopUntil=-1;});clearInterval(holdTimer);holdTimer=null;inputDirection=0;pointerDirection=0;keys.left=false;keys.right=false;$('left').classList.remove('pressed');$('right').classList.remove('pressed');}
function refreshInput(){var direction=pointerDirection||((keys.right?1:0)-(keys.left?1:0));if(!game||game.status!=='playing')direction=0;if(direction===inputDirection)return;clearInterval(holdTimer);holdTimer=null;inputDirection=direction;$('left').classList.toggle('pressed',direction<0);$('right').classList.toggle('pressed',direction>0);if(direction){game.nudge(direction);holdTimer=setInterval(function(){if(game&&game.status==='playing')game.nudge(direction);else stopInput();},150);}}
function bindDirection(id,direction){var b=$(id);b.addEventListener('pointerdown',function(e){if(b.disabled)return;e.preventDefault();pointerDirection=direction;if(typeof b.setPointerCapture==='function')b.setPointerCapture(e.pointerId);refreshInput();});function release(){if(pointerDirection===direction){pointerDirection=0;refreshInput();}}['pointerup','pointercancel','lostpointercapture'].forEach(function(type){b.addEventListener(type,release);});b.addEventListener('click',function(e){if(e.detail===0&&game&&game.status==='playing')game.nudge(direction);});}
bindDirection('left',-1);bindDirection('right',1);$('up').addEventListener('click',function(){if(game)game.nudgeUp();});
document.addEventListener('keydown',function(e){if(screen!=='game'||$('modal').hasAttribute('open'))return;if(e.key===' '){e.preventDefault();if(!e.repeat)pause();return;}if(e.key==='ArrowUp'){e.preventDefault();if(!e.repeat&&game){if(game.nudgeUp())pulseButton($('up'),'bounce-pop');}return;}if(e.key!=='ArrowLeft'&&e.key!=='ArrowRight')return;e.preventDefault();if(e.repeat)return;keys[e.key==='ArrowLeft'?'left':'right']=true;refreshInput();});
function endTankGesture(){var gesture=tankGesture;tankGesture=null;$('tank').classList.remove('swiping');if(gesture&&typeof canvas.hasPointerCapture==='function'&&canvas.hasPointerCapture(gesture.id))canvas.releasePointerCapture(gesture.id);}
function stopInput(){if(game)game.groups.forEach(function(g){g.pendingHopUntil=-1;});endTankGesture();swipeTrace=null;clearInterval(holdTimer);holdTimer=null;inputDirection=0;keys.left=false;keys.right=false;}
function refreshInput(){var direction=(keys.right?1:0)-(keys.left?1:0);if(!game||game.status!=='playing')direction=0;if(direction===inputDirection)return;clearInterval(holdTimer);holdTimer=null;inputDirection=direction;if(direction){game.nudge(direction);holdTimer=setInterval(function(){if(game&&game.status==='playing')game.nudge(direction);else stopInput();},150);}}
// Collect a short flick, then emit exactly one impulse on release. Pointer
// movement itself never applies force, sets a body position or selects a piece.
function sampleTankGesture(e){
var g=tankGesture,now=performance.now();g.x=e.clientX;g.y=e.clientY;g.active=Math.hypot(g.x-g.startX,g.y-g.startY)>=18;
g.samples.push({x:g.x,y:g.y,t:now});while(g.samples.length>2&&g.samples[1].t<now-180)g.samples.shift();if(g.samples.length>24)g.samples.splice(1,1);
}
function releaseTankFlick(e){
var g=tankGesture;if(!g||g.id!==e.pointerId)return;
sampleTankGesture(e);var samples=g.samples,end=samples[samples.length-1],first=samples[0],dx=end.x-first.x,dy=end.y-first.y,elapsed=end.t-first.t,distance=Math.hypot(dx,dy);
// A slow drag or a held finger is not a flick. Pauses/cancellations discard it.
if(game&&game.status==='playing'&&distance>=18&&elapsed<=350&&distance/Math.max(16,elapsed)>=.16){
var rect=canvas.getBoundingClientRect(),point={x:Math.max(0,Math.min(w,((first.x+end.x)/2-rect.left)*w/rect.width)),y:Math.max(0,Math.min(h,((first.y+end.y)/2-rect.top)*h/rect.height))};
if(game.swipe(point,{x:dx,y:dy},elapsed))swipeTrace={x:point.x,y:point.y,dx:dx,dy:dy,until:game.clock+280};
}
endTankGesture();
}
canvas.addEventListener('pointerdown',function(e){
if(screen!=='game'||!game||game.status!=='playing'||$('modal').hasAttribute('open')||tankGesture||e.isPrimary===false||(e.pointerType==='mouse'&&e.button!==0))return;
e.preventDefault();var now=performance.now();tankGesture={id:e.pointerId,startX:e.clientX,startY:e.clientY,x:e.clientX,y:e.clientY,active:false,samples:[{x:e.clientX,y:e.clientY,t:now}]};if(typeof canvas.setPointerCapture==='function')canvas.setPointerCapture(e.pointerId);
});
canvas.addEventListener('pointermove',function(e){if(!tankGesture||tankGesture.id!==e.pointerId)return;e.preventDefault();sampleTankGesture(e);});
canvas.addEventListener('pointerup',releaseTankFlick);
['pointercancel','lostpointercapture'].forEach(function(type){canvas.addEventListener(type,function(e){if(tankGesture&&tankGesture.id===e.pointerId)endTankGesture();});});
document.addEventListener('keydown',function(e){if(screen!=='game'||$('modal').hasAttribute('open'))return;if(e.key===' '){e.preventDefault();if(!e.repeat)pause();return;}if(e.key==='ArrowUp'){e.preventDefault();if(!e.repeat&&game)game.nudgeUp();return;}if(e.key!=='ArrowLeft'&&e.key!=='ArrowRight')return;e.preventDefault();if(e.repeat)return;keys[e.key==='ArrowLeft'?'left':'right']=true;refreshInput();});
document.addEventListener('keyup',function(e){if(e.key==='ArrowLeft'||e.key==='ArrowRight'){keys[e.key==='ArrowLeft'?'left':'right']=false;refreshInput();}});
document.addEventListener('pointerdown',function(){document.body.classList.add('using-pointer');});document.addEventListener('keydown',function(e){if(e.key==='Tab')document.body.classList.remove('using-pointer');});$('start').addEventListener('click',start);$('pause').addEventListener('click',pause);$('back').addEventListener('click',askBack);
document.addEventListener('pointerdown',function(){document.body.classList.add('using-pointer');});document.addEventListener('keydown',function(e){if(e.key==='Tab')document.body.classList.remove('using-pointer');});$('start').addEventListener('click',start);$('pause').addEventListener('click',pause);
function openProvincePicker(){
openModal('PICK A DESTINATION','<h2>这局,拼哪里?</h2><div id="province-grid" class="province-grid" role="group" aria-label="选择省区"></div><p class="picker-note">直辖市、港澳没有地级关卡;台湾省暂缺地级轮廓数据。省级版包含全部 34 个省级行政区。</p>');$('modal').classList.add('province-picker-modal');$('province-picker').classList.add('expanded');
data.levels.slice(1).forEach(function(l){var button=document.createElement('button');button.type='button';button.textContent=shortName(l.name);button.setAttribute('data-province',l.id);button.setAttribute('aria-pressed',String(l.id===provinceCode));button.className=l.id===provinceCode?'selected':'';button.addEventListener('click',function(){provinceCode=l.id;selectLevel();closeModal();});$('province-grid').appendChild(button);});
@@ -131,7 +149,7 @@ modeTabs.addEventListener('pointerdown',function(e){if(screen==='entry'&&e.isPri
document.addEventListener('pointerup',function(e){if(!modeGesture||modeGesture.id!==e.pointerId)return;var dx=e.clientX-modeGesture.x,dy=e.clientY-modeGesture.y;modeGesture=null;if(screen==='entry'&&Math.abs(dx)>35&&Math.abs(dx)>Math.abs(dy)*1.3){mode=dx<0?'city':'province';suppressModeClickUntil=performance.now()+350;selectLevel();}});
document.addEventListener('pointercancel',function(){modeGesture=null;});
document.querySelectorAll('[data-speed]').forEach(function(b){b.addEventListener('click',function(){if(screen!=='entry')return;speed=Number(b.getAttribute('data-speed'));updateUI();});});document.querySelectorAll('[data-bounce]').forEach(function(b){b.addEventListener('click',function(){if(screen!=='entry')return;bounce=Number(b.getAttribute('data-bounce'));updateUI();});});$('province-picker').addEventListener('click',openProvincePicker);
$('rules-button').addEventListener('click',function(){openModal('HOW TO PLAY','<h2>轻摇轻颠,拼一片山河</h2><ol><li><b>先选旅程,再开一局。</b>选择省级 / 地级版、地区、下落速度和弹性,点击开始。</li><li><b>晃动整个框。</b>按住左晃或右晃,点击中间上晃轻颠,也可使用键盘 ← ↑ →;框体左右晃动,所有碎片受到惯性影响。</li><li><b>相邻的边自动吸合。</b>碎片碰撞时会轻微弹跳、翻动,停稳后自动回正;只有真实相邻地区按正确方位接触时才合并。把所有碎片拼为一个整体即可通关。</li></ol><div class="rules-score">合并基础分:100 + 40 ×(合并后块数 − 2)<br>8.5 秒内连合,每次系数 +0.25,最高 ×2。<br>速度倍率:佛系看山 ×1 / 说走就走 ×1.5 / 一路狂飙 ×2 / 山河起飞 ×3。<br>跨海 / 隔区连接 ×0.8;通关再奖 1000 × 速度倍率。<br>三向晃动不限次数、不扣分;弹性不改变得分倍率,最佳纪录按速度和弹性分别保存。</div><p>弹性推荐“蹦蹦跳”,方便腾挪;“轻轻弹”偏沉稳,“弹力全开”需要控制节奏。稳定堆过顶部红线超过 2.4 秒,本局结束;也可随时从暂停页结束并生成成绩图。省级离岛和地级间隔分别标记为跨海、隔区连接。</p>');});
$('rules-button').addEventListener('click',function(){openModal('HOW TO PLAY','<h2>轻摇轻颠,拼一片山河</h2><ol><li><b>先选旅程,再开一局。</b>选择省级 / 地级版、地区、下落速度和弹性,点击开始。</li><li><b>晃动整个框。</b>在容器内快速轻划并松手,触发一次晃动。划过位置附近更剧烈,所有地块随后自由运动;手指只给出大致方向,不能牵引地块。慢拖或按住不触发,点击底部圆形暂停图标可查看本局、结束或重开;电脑也可使用方向键。</li><li><b>相邻的边自动吸合。</b>碎片碰撞时会轻微弹跳、翻动,停稳后自动回正;只有真实相邻地区按正确方位接触时才合并。把所有碎片拼为一个整体即可通关。</li></ol><div class="rules-score">合并基础分:100 + 40 ×(合并后块数 − 2)<br>8.5 秒内连合,每次系数 +0.25,最高 ×2。<br>速度倍率:佛系看山 ×1 / 说走就走 ×1.5 / 一路狂飙 ×2 / 山河起飞 ×3。<br>跨海 / 隔区连接 ×0.8;通关再奖 1000 × 速度倍率。<br>轻划不限次数、不扣分;弹性不改变得分倍率,最佳纪录按速度和弹性分别保存。</div><p>弹性推荐“蹦蹦跳”,方便腾挪;“轻轻弹”偏沉稳,“弹力全开”需要控制节奏。稳定堆过顶部红线超过 2.4 秒,本局结束;也可随时从暂停页结束并生成成绩图。省级离岛和地级间隔分别标记为跨海、隔区连接。</p>');});
$('data-button').addEventListener('click',function(){openModal('MAP NOTES','<h2>关于这片山河</h2><p>轮廓来源:阿里云 DataV.GeoAtlas 公开行政区数据,2026-10-16 下载,随包离线提供。轮廓已为游戏做简化,所有源数据外环及独立海域线段随包保留。</p><p>省级版包含 34 块;地级版提供 27 个省区关卡、333 个地级单元,包含地级市、自治州、地区、盟,不含县和县级市。直辖市、港澳不设地级关卡;数据源暂缺台湾省地级轮廓。</p><p>岛屿及未纳入的省直辖县造成的间隔,使用明确标记的跨海 / 隔区连接。地图仅供游戏示意,不用于测绘、导航或区划查询。</p><p>纪录仅在本地保存,存储失败不影响游玩。</p>');});
function fitCard(){var box=$('result-card').parentNode,r=box.getBoundingClientRect(),sc=Math.max(.01,Math.min((r.width-22)/750,(r.height-22)/1400));$('result-card').style.width=Math.floor(750*sc)+'px';$('result-card').style.height=Math.floor(1400*sc)+'px';}
function showResult(){
@@ -158,5 +176,5 @@ window.addEventListener('resize',layout);if(window.visualViewport&&typeof window
document.addEventListener('visibilitychange',function(){if(document.hidden){stopInput();pause();cancelAnimationFrame(rafId);rafId=0;}else{last=0;if(game&&game.status==='playing')schedule();}});
layout();updateUI();storePromise=initStore();
// Read-only development diagnostics: interaction is exclusively through the tank controls.
window.shanheDebug={state:function(){return {screen:screen,status:game?game.status:'entry',score:game?game.score:0,level:level.id,speed:speed,bounce:bounce,bounceName:Engine.BOUNCES[bounce].name,history:game?game.history.map(function(p){return {ms:p.ms,score:p.score};}):[],elapsed:game?game.clock:0,result:result,shakeY:game?game.shake.y:0,dropped:game?game.dropped:0,remaining:game?game.queue.length:level.regions.length,groups:game?game.groups.length:0,shakeCount:game?game.shakeCount:0,hopCount:game?game.hopCount:0,shakeOffset:game?game.shake.offset:0,scale:game?game.scale:0,initialScale:game?game.initialScale:0,zoom:game?game.zoom:1,width:w,height:h,collisionCount:game?game.collisionCount:0,impactCount:game?game.impacts.length:0,contactPulse:game?game.groups.filter(function(g){return g.hitUntil>game.clock;}).length:0,labels:lastLabelBoxes.map(function(b){return {name:b.name,x:b.x,y:b.y,w:b.w,h:b.h};}),regions:game?game.groups.map(function(g){return {ids:g.ids.slice(),x:g.body.position.x,y:g.body.position.y,angle:g.body.angle,vx:g.body.velocity.x,vy:g.body.velocity.y};}):[]};}};
window.shanheDebug={state:function(){return {screen:screen,status:game?game.status:'entry',score:game?game.score:0,level:level.id,speed:speed,bounce:bounce,bounceName:Engine.BOUNCES[bounce].name,history:game?game.history.map(function(p){return {ms:p.ms,score:p.score};}):[],elapsed:game?game.clock:0,result:result,shakeY:game?game.shake.y:0,dropped:game?game.dropped:0,remaining:game?game.queue.length:level.regions.length,groups:game?game.groups.length:0,shakeCount:game?game.shakeCount:0,swipeCount:game?game.swipeCount:0,swiping:!!(tankGesture&&tankGesture.active),hopCount:game?game.hopCount:0,shakeOffset:game?game.shake.offset:0,scale:game?game.scale:0,initialScale:game?game.initialScale:0,zoom:game?game.zoom:1,width:w,height:h,collisionCount:game?game.collisionCount:0,impactCount:game?game.impacts.length:0,contactPulse:game?game.groups.filter(function(g){return g.hitUntil>game.clock;}).length:0,labels:lastLabelBoxes.map(function(b){return {name:b.name,x:b.x,y:b.y,w:b.w,h:b.h};}),regions:game?game.groups.map(function(g){return {ids:g.ids.slice(),x:g.body.position.x,y:g.body.position.y,angle:g.body.angle,vx:g.body.velocity.x,vy:g.body.velocity.y};}):[]};}};
})();
+19 -1
View File
@@ -6,7 +6,7 @@ function baseScale(level,w,h){var maxw=0,maxh=0;level.regions.forEach(function(r
var SPEEDS=[{name:'佛系看山',interval:8500,gravity:.32,multiplier:1},{name:'说走就走',interval:6000,gravity:.48,multiplier:1.5},{name:'一路狂飙',interval:4000,gravity:.7,multiplier:2},{name:'山河起飞',interval:2500,gravity:1,multiplier:3}];
var BOUNCES=[{name:'轻轻弹',restitution:.65,hop:2.15,rise:90,air:.022,push:1,maxX:7.2,friction:.22,scatter:0},{name:'蹦蹦跳',restitution:.82,hop:6,rise:250,air:.012,push:1.22,maxX:9.5,friction:.16,scatter:2.6},{name:'弹力全开',restitution:.96,hop:14,rise:540,air:.006,push:1.7,maxX:13,friction:.10,scatter:5}];
function Game(level,width,height,speed,emit,rng,bounce){
this.bounceIndex=BOUNCES[bounce]?bounce:0;this.bounce=BOUNCES[this.bounceIndex];this.history=[{ms:0,score:0}];this.endReason=null;this.lastUp=-1000;this.level=level;this.w=width;this.h=height;this.speed=SPEEDS[speed];this.emit=emit||function(){};this.rng=rng||Math.random;this.scale=baseScale(level,width,height);this.initialScale=this.scale;this.zoom=1;this.shake={offset:0,velocity:0,y:0,vy:0};this.shakeCount=0;this.hopCount=0;this.engine=M.Engine.create({enableSleeping:true});this.engine.gravity.y=this.speed.gravity;this.groups=[];this.queue=C.shuffle(level.regions.map(function(_,i){return i;}),this.rng);this.score=0;this.chain=0;this.maxChain=0;this.merges=0;this.dropped=0;this.clock=0;this.lastMerge=-99999;this.nextAt=0;this.overflow=0;this.status='ready';this.fx=[];this.impacts=[];this.collisionCount=0;this.wallHitUntil=0;
this.bounceIndex=BOUNCES[bounce]?bounce:0;this.bounce=BOUNCES[this.bounceIndex];this.history=[{ms:0,score:0}];this.endReason=null;this.lastUp=-1000;this.lastSwipe=-1000;this.level=level;this.w=width;this.h=height;this.speed=SPEEDS[speed];this.emit=emit||function(){};this.rng=rng||Math.random;this.scale=baseScale(level,width,height);this.initialScale=this.scale;this.zoom=1;this.shake={offset:0,velocity:0,y:0,vy:0};this.shakeCount=0;this.swipeCount=0;this.hopCount=0;this.engine=M.Engine.create({enableSleeping:true});this.engine.gravity.y=this.speed.gravity;this.groups=[];this.queue=C.shuffle(level.regions.map(function(_,i){return i;}),this.rng);this.score=0;this.chain=0;this.maxChain=0;this.merges=0;this.dropped=0;this.clock=0;this.lastMerge=-99999;this.nextAt=0;this.overflow=0;this.status='ready';this.fx=[];this.impacts=[];this.collisionCount=0;this.wallHitUntil=0;
var self=this;M.Events.on(this.engine,'collisionStart',function(e){self.onContacts(e.pairs,true);});M.Events.on(this.engine,'collisionActive',function(e){self.onContacts(e.pairs,false);});
this.walls=[M.Bodies.rectangle(width/2,height+25,width+100,50,{isStatic:true}),M.Bodies.rectangle(-25,height/2,50,height*4,{isStatic:true}),M.Bodies.rectangle(width+25,height/2,50,height*4,{isStatic:true})];M.Composite.add(this.engine.world,this.walls);
}
@@ -52,6 +52,24 @@ Game.prototype.tryQueuedHops=function(){
M.Sleeping.set(g.body,false);var acceleration=this.speed.gravity*.001*Math.pow(1000/60,2);M.Body.setVelocity(g.body,{x:g.body.velocity.x,y:Math.min(g.body.velocity.y,-Math.sqrt(2*acceleration*height))});g.lastHop=this.clock;g.pendingHopUntil=-1;this.hopCount++;
},this);
};
// One released flick delivers one short impulse with a spatial falloff.
// Every group moves; no piece is selected, grabbed or teleported by the finger.
Game.prototype.swipe=function(point,delta,elapsed){
if(this.status!=='playing'||this.clock-this.lastSwipe<240||!point||!delta||![point.x,point.y,delta.x,delta.y,elapsed].every(Number.isFinite))return false;
var distance=Math.hypot(delta.x,delta.y);if(distance<18)return false;
var dt=Math.max(16,elapsed),speed=Math.min(2.8,distance/dt);if(speed<.16)return false;this.lastSwipe=this.clock;var power=(2.8+Math.min(5.5,speed*2.8))*Math.min(1.2,.6+distance/160);
var dx=delta.x/distance,dy=delta.y/distance,radius=Math.max(90,Math.min(180,this.w*.55)),acc=this.speed.gravity*.001*Math.pow(1000/60,2),maxUp=Math.sqrt(2*acc*this.riseLimit());
this.shake.velocity=Math.max(-.6,Math.min(.6,this.shake.velocity+dx*power*.065));this.shake.vy=Math.max(-.48,Math.min(.48,this.shake.vy+dy*power*.05));
this.groups.forEach(function(g){
var body=g.body,bounds=M.Bounds.create(body.vertices),nearX=Math.max(bounds.min.x,Math.min(bounds.max.x,point.x)),nearY=Math.max(bounds.min.y,Math.min(bounds.max.y,point.y));
var distance2=Math.pow(point.x-nearX,2)+Math.pow(point.y-nearY,2),local=.25+1.25*Math.exp(-2*distance2/(radius*radius)),weight=1/(1+(g.ids.length-1)*.12),impulse=power*local*weight*this.bounce.push*(.85+this.rng()*.3),spread=(this.rng()-.5)*.8,cos=Math.cos(spread),sin=Math.sin(spread),jx=dx*cos-dy*sin,jy=dx*sin+dy*cos;
if(body.isSleeping)g.supportedUntil=this.clock+80;M.Sleeping.set(body,false);
M.Body.setVelocity(body,{x:Math.max(-this.bounce.maxX,Math.min(this.bounce.maxX,body.velocity.x+jx*impulse)),y:Math.max(-maxUp,Math.min(MAX_FALL_SPEED,body.velocity.y+jy*impulse*.85))});
if(dy<.4){g.pendingHopUntil=this.clock+300;g.pendingHopHeight=Math.min((16+speed*12)*this.bounce.hop*local*weight,this.riseLimit()*.92);}
M.Body.setAngularVelocity(body,Math.max(-.02,Math.min(.02,body.angularVelocity+dx*impulse*.0015)));
},this);
this.tryQueuedHops();this.swipeCount=(this.swipeCount||0)+1;this.shakeCount++;return true;
};
// Score events retain the exact active-play time; pauses never advance the clock.
Game.prototype.recordScore=function(){var last=this.history[this.history.length-1];if(last.ms===this.clock){last.score=this.score;return;}this.history.push({ms:this.clock,score:this.score});};
Game.prototype.complete=function(reason){if(this.endReason)return false;this.endReason=reason;this.status=reason==='stopped'?'ended':reason;this.recordScore();this.emit('end',{won:reason==='won',reason:reason});return true;};
+4 -5
View File
@@ -12,7 +12,7 @@
<section id="entry-screen" class="entry-screen" aria-label="选择旅程">
<header class="header"><div class="brand"><span class="brand-mark" aria-hidden="true"><svg viewBox="0 0 32 32"><path d="M3 24 12 9l6 10 4-6 7 11Z" fill="none" stroke="currentColor" stroke-width="1.6"/><circle cx="23" cy="8" r="2" fill="currentColor"/></svg></span><span>山河拼图<small>SHAN HE · MAP PUZZLE</small></span></div></header>
<main class="entry-main">
<div class="entry-story"><div class="eyebrow"><span></span> 一片一片,认识中国</div><h1>把山河,<br><em>拼在一起。</em></h1><p class="lead">晃动这个框,<br>让相邻的山河,在碰撞中相遇。</p><div class="entry-map"><canvas id="reference" width="960" height="700" aria-label="所选旅程的完整地图"></canvas><span id="map-caption">34 个省级行政区 · 等你拼完整</span></div><div class="entry-instruction"><span>←</span><p>左右轻摇,向上轻颠<br><strong>晃动整个容器,碎片自动吸合</strong></p><span>→</span></div></div>
<div class="entry-story"><div class="eyebrow"><span></span> 一片一片,认识中国</div><h1>把山河,<br><em>拼在一起。</em></h1><p class="lead">晃动这个框,<br>让相邻的山河,在碰撞中相遇。</p><div class="entry-map"><canvas id="reference" width="960" height="700" aria-label="所选旅程的完整地图"></canvas><span id="map-caption">34 个省级行政区 · 等你拼完整</span></div><div class="entry-instruction"><span>←</span><p>轻划一下,晃动山河<br><strong>晃动整个容器,碎片自动吸合</strong></p><span>→</span></div></div>
<section class="setup"><div class="section-title"><span class="eyebrow">CHOOSE YOUR JOURNEY</span><span>01</span></div><h2>选择你的旅程</h2><p class="setup-intro">从一片故乡,出发去看山河。</p>
<div class="mode-tabs" role="group" aria-label="版本选择"><button data-mode="province" class="selected" aria-pressed="true">省级版 <small>拼中国</small></button><button data-mode="city" aria-pressed="false">地级版 <small>拼家乡</small></button></div>
<div id="city-select-panel" hidden><button id="province-picker" class="province-picker" aria-haspopup="dialog"><span class="destination-mark" aria-hidden="true">⌖</span><span class="destination-copy"><small>本局目的地</small><strong id="province-name">浙江省</strong></span><span id="province-count" class="destination-count">11 个地级单元</span><span class="destination-arrow" aria-hidden="true">⌄</span></button><p id="city-note" class="field-note"></p></div>
@@ -26,10 +26,9 @@
<section id="game-screen" class="game-screen" hidden aria-label="山河拼图游戏">
<div class="game-topbar"><div><strong id="game-title">中国 · 省级拼图</strong><span id="game-speed">佛系看山 · 得分 ×1</span></div></div>
<div class="game-hud"><div class="score"><span class="stat-label">本局得分</span><strong id="score">0</strong></div><div><span class="stat-label">最大拼合</span><strong><span id="merged">0</span><small> / <span id="total">34</span></small></strong></div><div class="next-inline"><canvas id="next" width="150" height="110" aria-label="下一个地区预览"></canvas><div><span class="stat-label">下一块</span><strong id="next-name">—</strong></div></div></div>
<div class="tank-stage"><div class="board-wrap" id="tank"><canvas id="board" width="840" height="1120" aria-label="晃动容器中的地图碎片。使用左晃、上晃、右晃按钮或键盘方向键操作整个框。"></canvas><div class="board-tag"><span class="live-dot"></span><span id="board-name">山河容器</span></div><div class="danger-label">堆叠警戒线</div><div id="board-status" class="board-status" aria-live="polite"></div></div></div>
<div class="game-progress"><span id="progress-label">已落下 0 / 34 块</span><span>左右轻摇,向上轻颠</span></div>
<div class="game-tools"><button id="back" class="utility-button" aria-label="返回旅程选择">旅程设置</button><span aria-hidden="true">·</span><button id="pause" class="utility-button" aria-label="暂停游戏">Ⅱ 暂停 / 结束</button></div>
<div class="controls" role="group" aria-label="容器晃动操作"><button id="left" aria-label="向左晃动整个容器"><span class="control-arrow" aria-hidden="true">←</span><span class="control-copy"><strong>左晃</strong><small>按住持续晃动</small></span></button><button id="up" aria-label="向上晃动整个容器"><span class="control-copy"><strong>↑ 上晃</strong><small>点击轻颠</small></span></button><button id="right" aria-label="向右晃动整个容器"><span class="control-copy"><strong>右晃</strong><small>按住持续晃动</small></span><span class="control-arrow" aria-hidden="true">→</span></button></div>
<div class="tank-stage"><div class="board-wrap" id="tank"><canvas id="board" width="840" height="1120" aria-label="在容器内快速轻划并松手,触发一次惯性晃动,划过位置附近的地块反应更强。地块不会跟随手指。"></canvas><div class="danger-label">堆叠警戒线</div><div id="board-status" class="board-status" aria-live="polite"></div></div></div>
<div class="game-progress"><span id="progress-label">已落下 0 / 34 块</span><span>轻划松手 · 附近更有力</span></div>
<div class="controls"><button id="pause" class="journey-menu" aria-label="暂停、旅程设置与结束" title="暂停 / 旅程设置"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="M8.5 6.5v11M15.5 6.5v11"/></svg></button></div>
</section>
<section id="result-screen" class="result-screen" hidden aria-label="旅程成绩">
<div class="result-topbar"><span class="eyebrow">YOUR JOURNEY</span></div>
+10 -5
View File
@@ -4,10 +4,10 @@ button,select{font:inherit;color:inherit}button{cursor:pointer;touch-action:mani
.entry-main{display:grid;grid-template-columns:minmax(0,1fr) 370px;grid-column-gap:76px;align-items:center;min-height:690px;padding:42px 0 24px}.entry-story{position:relative;min-width:0}h1{font:700 50px/1.4 "Songti SC","STSong","Noto Serif CJK SC",serif;letter-spacing:2px;margin:14px 0 15px}h1 em{font-style:normal;color:#5d7956}.lead{font-size:13px;line-height:2;color:#87917c;letter-spacing:1px;margin:0}.entry-map{position:relative;height:290px;margin-top:-8px}.entry-map canvas{display:block;width:100%;height:100%}.entry-map>span{display:block;position:absolute;bottom:0;left:0;right:0;text-align:center;font-size:10px;color:#8d9b7d;letter-spacing:1px}.entry-instruction{display:flex;align-items:center;justify-content:center;margin-top:20px;color:#9baa8d}.entry-instruction>span{font-size:25px;font-weight:300}.entry-instruction p{margin:0 25px;text-align:center;font-size:9px;letter-spacing:1px}.entry-instruction strong{display:block;font-weight:400;color:#718564;font-size:11px;margin-top:2px}
.setup{background:var(--card);border:1px solid var(--line);border-radius:18px;padding:29px;box-shadow:0 8px 30px rgba(40,61,52,.04)}.section-title{display:flex;justify-content:space-between;align-items:center;margin-bottom:12px}.section-title>span:last-child{font:10px monospace;color:#a1aa96}.setup h2{font:25px/1.5 serif;letter-spacing:1px;margin:0 0 5px}.setup-intro{font-size:11px;color:#9aa28e;margin:0 0 23px}.mode-tabs{display:flex;padding:4px;background:#eff1e7;border-radius:9px;margin-bottom:23px}.mode-tabs button{flex:1;background:none;border-radius:7px;padding:12px 2px;font-size:13px;color:#8c9583;min-height:64px}.mode-tabs small{display:block;font-size:9px;opacity:.8;margin-top:2px}.mode-tabs button.selected{background:#fffef9;color:#3e6046;box-shadow:0 2px 5px rgba(50,69,45,.05)}.field-label{font-size:11px;color:#78876a;display:block;margin-bottom:8px}select{width:100%;background:#fffef9;border:1px solid #dbe1cf;border-radius:7px;padding:11px 10px;font-size:12px}#city-select-panel{margin-bottom:21px}.field-note{font-size:9px;line-height:1.9;color:#9aa28f;margin:11px 0 0;min-height:17px}.speed-heading{display:flex;justify-content:space-between;font-size:11px;margin-bottom:12px}.speed-heading>span{font-size:10px;color:#a18964}.speed-options{display:flex}.speed-options button{width:25%;margin-right:5px;border:1px solid transparent;border-radius:7px;background:#f4f5ec;color:#8f9884;font-size:11px;display:flex;align-items:center;flex-direction:column;padding:9px 0}.speed-options button:last-child{margin-right:0}.speed-options i{height:21px;font:9px sans-serif;letter-spacing:-1px;display:flex;align-items:center;margin-bottom:3px}.speed-options button.selected{background:#e7eddc;border-color:#cbd7bb;color:#537343}.journey-summary{display:flex;justify-content:space-between;border-top:1px dashed #dfe4d4;padding-top:18px;margin-top:23px}.journey-summary>div:last-child{text-align:right}.journey-summary span{display:block;font-size:9px;letter-spacing:1px;color:#9ca58f}.journey-summary strong{font-size:15px;font-weight:500;color:#617b50;display:block;margin-top:3px}.primary{background:var(--green);color:#fffcdf;border:1px solid var(--green);border-radius:9px;padding:13px 19px;font-size:13px;letter-spacing:1px}.start-button{display:flex;width:100%;align-items:center;justify-content:space-between;margin-top:25px;padding:14px 18px}.start-note{font-size:9px;letter-spacing:1px;text-align:center;color:#a0a88f;margin:12px 0 0}footer{display:flex;align-items:center;justify-content:space-between;border-top:1px solid var(--line);padding:18px 0;font-size:9px;color:#a0a88f}footer button{font-size:9px!important}
body.is-playing{overflow:hidden}.is-playing .app{max-width:760px;padding:0 28px}.game-screen{height:100vh;height:var(--game-height,100vh);min-height:320px;display:flex;flex-direction:column;padding:12px 0 16px}.game-topbar{display:flex;align-items:center;justify-content:space-between;flex:0 0 43px}.game-topbar>div{text-align:center;min-width:0}.game-topbar strong{display:block;font-size:13px;letter-spacing:1px;font-weight:500}.game-topbar>div>span{display:block;font-size:9px;color:#95a086;margin-top:1px}.nav-button{width:35px;height:35px;min-height:35px;flex:0 0 35px;border:1px solid #dbe0d0;border-radius:50%;background:rgba(255,254,249,.65);font-size:20px;line-height:1;padding:0;color:#728566}.game-hud{display:flex;align-items:center;flex:0 0 73px;padding:0 26px}.game-hud>div{margin-right:32px}.stat-label{display:block;font-size:9px;letter-spacing:1px;color:#929d85}.game-hud strong{font-size:23px;line-height:1.4;font-weight:500;font-variant-numeric:tabular-nums}.game-hud .score strong{font-size:30px;font-weight:600;color:var(--green)}.game-hud strong small{font-size:11px;color:#a0ab94}.game-hud .next-inline{display:flex;margin-right:0;margin-left:auto;align-items:center;max-width:46%;min-width:0}.next-inline canvas{display:block;width:64px;height:46px;flex:0 0 64px;margin-right:10px}.next-inline>div{min-width:0}.next-inline strong{font-size:11px;display:block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:140px}
.tank-stage{display:flex;align-items:center;justify-content:center;padding:3px 24px 9px;flex:1;min-height:0}.board-wrap{position:relative;width:100%;max-width:440px;height:100%;max-height:760px;border-left:8px solid #7895a0;border-right:8px solid #7895a0;border-bottom:10px solid #7895a0;border-radius:5px;overflow:hidden;box-shadow:0 5px 0 #e0e3da;will-change:transform;background:#f1f2e9}.board-wrap>canvas{display:block;width:100%;height:100%;touch-action:manipulation}.board-tag{position:absolute;left:12px;top:12px;display:flex;align-items:center;font-size:9px;letter-spacing:1px;color:#7e8c72;pointer-events:none}.live-dot{height:5px;width:5px;border-radius:50%;background:#8ca474;margin-right:6px}.danger-label{position:absolute;right:6px;top:68px;font-size:8px;color:#bd686c;background:#f1f2e9;padding-left:6px;pointer-events:none}.board-status{position:absolute;top:105px;left:8px;right:8px;text-align:center;font-size:9px;color:var(--orange);pointer-events:none;letter-spacing:1px}.game-progress{display:flex;justify-content:space-between;padding:2px 25px 8px;font-size:9px;color:#9ba68c;flex:0 0 27px}.controls{display:flex;flex:0 0 67px;padding:0 24px}.controls button{position:relative;display:flex;align-items:center;justify-content:center;flex:1;min-height:60px;background:#e8eedf;border:1px solid #cad9ba;border-radius:11px;color:#466b3d;user-select:none;-webkit-user-select:none}.controls button:first-child{margin-right:13px}.controls button.pressed{background:#365c47;border-color:#365c47;color:#fffce2}.controls button>span{font-size:30px;font-weight:300;line-height:1}.controls button:first-child>span{margin-right:16px}.controls button:last-child>span{margin-left:16px}.controls strong{font-size:16px;letter-spacing:2px;font-weight:500;margin-top:-9px}.controls small{position:absolute;bottom:10px;left:0;right:0;text-align:center;font-size:8px;letter-spacing:1px;opacity:.65}
.tank-stage{display:flex;align-items:center;justify-content:center;padding:3px 24px 9px;flex:1;min-height:0}.board-wrap{position:relative;width:100%;max-width:440px;height:100%;max-height:760px;border-left:8px solid #7895a0;border-right:8px solid #7895a0;border-bottom:10px solid #7895a0;border-radius:5px;overflow:hidden;box-shadow:0 5px 0 #e0e3da;will-change:transform;background:#f1f2e9}.board-wrap>canvas{display:block;width:100%;height:100%;touch-action:none;cursor:default;-webkit-user-select:none;user-select:none}.danger-label{position:absolute;right:6px;top:68px;font-size:8px;color:#bd686c;background:#f1f2e9;padding-left:6px;pointer-events:none}.board-status{position:absolute;top:105px;left:8px;right:8px;text-align:center;font-size:9px;color:var(--orange);pointer-events:none;letter-spacing:1px}.game-progress{display:flex;justify-content:space-between;padding:2px 25px 8px;font-size:9px;color:#9ba68c;flex:0 0 27px}.controls{display:flex;flex:0 0 67px;padding:0 24px}.controls button{position:relative;display:flex;align-items:center;justify-content:center;flex:1;min-height:60px;background:#e8eedf;border:1px solid #cad9ba;border-radius:11px;color:#466b3d;user-select:none;-webkit-user-select:none}.controls button:first-child{margin-right:13px}.controls button.pressed{background:#365c47;border-color:#365c47;color:#fffce2}.controls button>span{font-size:30px;font-weight:300;line-height:1}.controls button:first-child>span{margin-right:16px}.controls button:last-child>span{margin-left:16px}.controls strong{font-size:16px;letter-spacing:2px;font-weight:500;margin-top:-9px}.controls small{position:absolute;bottom:10px;left:0;right:0;text-align:center;font-size:8px;letter-spacing:1px;opacity:.65}
dialog{border:1px solid #dce0cf;background:var(--card);border-radius:18px;color:var(--ink);padding:26px;width:420px;max-width:calc(100% - 32px);max-height:85vh;overflow:auto;box-shadow:0 16px 80px rgba(29,56,47,.19)}dialog::backdrop{background:rgba(41,61,52,.44)}dialog.modal-fallback{display:block;position:fixed;z-index:100;top:50%;left:50%;margin:0;transform:translate(-50%,-50%);box-shadow:0 0 0 100vmax rgba(41,61,52,.44)}.modal-top{display:flex;align-items:center;justify-content:space-between}.modal-top .eyebrow{font-size:8px}dialog h2{font:26px/1.5 serif;letter-spacing:1px;margin:18px 0}dialog p,dialog li{font-size:12px;line-height:1.9;color:#7c8971}dialog ol{padding-left:20px}dialog li{margin-bottom:8px}dialog b{color:#42643d;font-weight:500}.rules-score{border-radius:9px;background:#eff2e5;padding:13px 15px;font-size:11px;line-height:1.9;color:#718267}#modal-actions{display:flex;flex-wrap:wrap;margin-top:20px}#modal-actions button{flex:1;margin-right:8px;min-width:90px;padding:10px 8px;font-size:11px}#modal-actions button:last-child{margin-right:0}.secondary{border:1px solid #d2dac4;border-radius:8px;background:#f0f3e7;color:#5e7b4e;font-size:12px}.result-number{font:48px/1.2 sans-serif;color:#3e6146;margin:12px 0}.result-label{font-size:10px;letter-spacing:1px;color:#9aa48e}.result-details{display:flex;justify-content:space-between;border-top:1px solid var(--line);padding-top:15px;font-size:10px;color:#8d9980}.toast{position:fixed;z-index:200;bottom:30px;left:50%;transform:translateX(-50%);background:rgba(43,69,56,.94);color:#f6f5e7;border-radius:10px;padding:11px 18px;font-size:12px;max-width:90%;text-align:center;pointer-events:none}
@media(max-width:1000px){.app{padding:0 28px}.entry-main{grid-template-columns:minmax(0,1fr) 340px;grid-column-gap:35px}.setup{padding:24px}h1{font-size:43px}.entry-map{height:260px}}
@media(max-width:720px){.app{padding:0 22px}.header{height:76px}.brand{font-size:19px;letter-spacing:2px}.brand-mark{width:36px;height:36px;margin-right:10px;border-radius:10px}.brand small{font-size:6px;letter-spacing:1.3px}.header .text-button{font-size:10px}.entry-main{display:flex;flex-direction:column;padding:27px 0 20px;min-height:0}.entry-story{width:100%;text-align:center}.eyebrow{font-size:8px}h1{font-size:31px;line-height:1.4;margin:11px 0 9px;letter-spacing:1px}h1 br{display:none}.lead{font-size:10px;line-height:1.8}.lead br{display:none}.entry-map{height:180px;margin-top:5px;max-width:340px;margin-left:auto;margin-right:auto}.entry-map>span{font-size:8px;bottom:0}.entry-instruction{display:none}.setup{width:100%;padding:23px 21px;border-radius:14px;margin-top:19px}.setup h2{font-size:22px}.setup-intro{margin-bottom:18px;font-size:10px}.section-title{margin-bottom:8px}.mode-tabs{margin-bottom:18px}.mode-tabs button{min-height:53px;padding:9px 2px;font-size:12px}.mode-tabs small{display:inline;margin-left:7px;font-size:9px}.speed-heading{font-size:10px;margin-bottom:10px}.speed-options button{font-size:10px;padding:8px 0}.speed-options i{height:16px;margin-bottom:2px}.field-note{font-size:8px;margin-top:9px}.journey-summary{padding-top:14px;margin-top:17px}.journey-summary strong{font-size:13px}.start-button{margin-top:18px;padding:12px 15px;font-size:12px}.start-note{font-size:8px}.field-label{font-size:10px}footer{font-size:8px;padding:12px 0}footer button{font-size:8px!important}.is-playing .app{padding:0 12px}.game-screen{padding:8px 0 12px}.game-topbar{flex-basis:42px;padding:0 4px}.game-topbar strong{font-size:12px}.game-topbar>div>span{font-size:8px}.nav-button{width:32px;height:32px;min-height:32px;flex-basis:32px;font-size:18px}.game-hud{flex-basis:65px;padding:0 22px}.game-hud>div{margin-right:22px}.stat-label{font-size:8px}.game-hud strong{font-size:21px}.game-hud .score strong{font-size:27px}.next-inline canvas{width:46px;height:38px;flex-basis:46px;margin-right:6px}.next-inline strong{font-size:10px;max-width:84px}.tank-stage{padding:3px 22px 8px}.board-wrap{border-left-width:7px;border-right-width:7px;border-bottom-width:9px}.board-tag{font-size:8px;left:9px}.danger-label{font-size:7px;right:4px;top:69px}.board-status{font-size:8px}.game-progress{font-size:8px;padding:2px 22px 7px;flex-basis:24px}.controls{flex-basis:65px;padding:0 22px}.controls button:first-child{margin-right:12px}.controls button>span{font-size:27px}.controls strong{font-size:15px}.controls small{font-size:7px}dialog{padding:22px}dialog h2{font-size:23px}}
@media(max-width:720px){.app{padding:0 22px}.header{height:76px}.brand{font-size:19px;letter-spacing:2px}.brand-mark{width:36px;height:36px;margin-right:10px;border-radius:10px}.brand small{font-size:6px;letter-spacing:1.3px}.header .text-button{font-size:10px}.entry-main{display:flex;flex-direction:column;padding:27px 0 20px;min-height:0}.entry-story{width:100%;text-align:center}.eyebrow{font-size:8px}h1{font-size:31px;line-height:1.4;margin:11px 0 9px;letter-spacing:1px}h1 br{display:none}.lead{font-size:10px;line-height:1.8}.lead br{display:none}.entry-map{height:180px;margin-top:5px;max-width:340px;margin-left:auto;margin-right:auto}.entry-map>span{font-size:8px;bottom:0}.entry-instruction{display:none}.setup{width:100%;padding:23px 21px;border-radius:14px;margin-top:19px}.setup h2{font-size:22px}.setup-intro{margin-bottom:18px;font-size:10px}.section-title{margin-bottom:8px}.mode-tabs{margin-bottom:18px}.mode-tabs button{min-height:53px;padding:9px 2px;font-size:12px}.mode-tabs small{display:inline;margin-left:7px;font-size:9px}.speed-heading{font-size:10px;margin-bottom:10px}.speed-options button{font-size:10px;padding:8px 0}.speed-options i{height:16px;margin-bottom:2px}.field-note{font-size:8px;margin-top:9px}.journey-summary{padding-top:14px;margin-top:17px}.journey-summary strong{font-size:13px}.start-button{margin-top:18px;padding:12px 15px;font-size:12px}.start-note{font-size:8px}.field-label{font-size:10px}footer{font-size:8px;padding:12px 0}footer button{font-size:8px!important}.is-playing .app{padding:0 12px}.game-screen{padding:8px 0 12px}.game-topbar{flex-basis:42px;padding:0 4px}.game-topbar strong{font-size:12px}.game-topbar>div>span{font-size:8px}.nav-button{width:32px;height:32px;min-height:32px;flex-basis:32px;font-size:18px}.game-hud{flex-basis:65px;padding:0 22px}.game-hud>div{margin-right:22px}.stat-label{font-size:8px}.game-hud strong{font-size:21px}.game-hud .score strong{font-size:27px}.next-inline canvas{width:46px;height:38px;flex-basis:46px;margin-right:6px}.next-inline strong{font-size:10px;max-width:84px}.tank-stage{padding:3px 22px 8px}.board-wrap{border-left-width:7px;border-right-width:7px;border-bottom-width:9px}.danger-label{font-size:7px;right:4px;top:69px}.board-status{font-size:8px}.game-progress{font-size:8px;padding:2px 22px 7px;flex-basis:24px}.controls{flex-basis:65px;padding:0 22px}.controls button:first-child{margin-right:12px}.controls button>span{font-size:27px}.controls strong{font-size:15px}.controls small{font-size:7px}dialog{padding:22px}dialog h2{font-size:23px}}
@media(max-width:360px){.app{padding:0 16px}.brand{font-size:18px}.game-hud{padding:0 19px}.game-hud>div{margin-right:14px}.game-hud .next-inline{max-width:43%}.next-inline canvas{width:38px;flex-basis:38px;margin-right:4px}.next-inline strong{max-width:65px;font-size:9px}.game-progress>span:last-child{font-size:7px}}
@media(max-height:680px){.game-screen{padding-top:4px;padding-bottom:8px}.game-topbar{flex-basis:36px}.game-hud{flex-basis:55px}.controls{flex-basis:55px}.controls button{min-height:52px}.controls small{bottom:6px}.game-progress{flex-basis:22px}.game-hud .score strong{font-size:25px}}
@media(prefers-reduced-motion:reduce){*{scroll-behavior:auto!important;transition:none!important}}
@@ -44,19 +44,19 @@ button{transition:background-color .16s,border-color .16s,color .16s,box-shadow
@media(prefers-reduced-motion:reduce){*,*::before,*::after{animation:none!important;transition:none!important}.controls button.pressed{transform:none}}
/* Reserve a separate row for the host's top-left/back and top-right actions. */
body{padding-top:56px;padding-top:calc(56px + var(--safe-area-inset-top,env(safe-area-inset-top,0px)));-webkit-text-size-adjust:100%;text-size-adjust:100%}
.game-topbar{justify-content:center}.game-screen{min-height:200px}.game-tools{display:flex;align-items:center;justify-content:center;flex:0 0 34px;color:#b6beaa}.utility-button{min-height:32px;min-width:104px;border:0;background:transparent;color:#728566;font-size:11px;padding:3px 10px}.game-tools>span{margin:0 7px}.result-topbar{justify-content:center}
.game-topbar{justify-content:center}.game-screen{min-height:200px}.result-topbar{justify-content:center}
footer>.text-button+button{margin-left:12px}
dialog,dialog.modal-fallback{position:fixed;top:calc(var(--content-top,56px) + 12px);bottom:auto;left:0;right:0;margin:0 auto;transform:none;max-height:calc(var(--game-height,100vh) - 24px)}
/* On phones the entrance is a settings page; decorative art cannot compete for height. */
@media(max-width:720px){
.entry-story{display:none!important}.entry-main{padding:10px 0;justify-content:center;align-items:center}.setup{margin:0;max-width:410px;flex:0 0 auto}.header{justify-content:center;flex:0 0 54px}.header .brand{font-size:19px}footer{flex:0 0 30px;flex-wrap:nowrap}footer>span{margin-right:auto}footer .text-button{font-size:8px!important;white-space:nowrap}
.setup h2{font-size:22px}.result-actions button{font-size:10px}.game-tools{flex-basis:32px}
.setup h2{font-size:22px}.result-actions button{font-size:10px}
body.compact-entry .header{flex-basis:44px}body.compact-entry .entry-main{padding:6px 0}body.compact-entry .setup{margin:0;padding:12px}body.compact-entry .mode-tabs{margin-bottom:8px}body.compact-entry .mode-tabs button{min-height:40px}body.compact-entry #city-select-panel{margin-bottom:8px}body.compact-entry .province-picker{min-height:44px;padding:5px 9px}body.compact-entry #city-note{display:none}body.compact-entry .speed-heading{margin-bottom:6px;line-height:1.2}body.compact-entry .speed-options button{min-height:40px}body.compact-entry .bounce-heading{margin-top:8px;margin-bottom:6px;line-height:1.2}body.compact-entry .bounce-options button{min-height:36px}body.compact-entry .start-button{min-height:40px;margin-top:12px}body.compact-entry footer{flex-basis:26px}
body.tiny-entry .setup h2,body.tiny-entry .journey-summary{display:none}body.tiny-entry .header{flex-basis:38px}body.tiny-entry .entry-main{padding:4px 0}body.tiny-entry .setup{padding:10px 12px}body.tiny-entry .mode-tabs button{min-height:38px}body.tiny-entry .destination-mark{width:25px;height:25px}body.tiny-entry footer{flex-basis:24px}
}
@media(max-height:520px) and (min-width:600px){
.entry-story{display:none!important}.entry-main{display:flex!important;justify-content:center;padding:3px 0!important}.entry-screen .header{flex-basis:32px!important;justify-content:center}.brand-mark{width:26px;height:26px;padding:4px}.brand small{display:none}.setup{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);grid-column-gap:14px;grid-row-gap:6px;max-width:640px;padding:10px 12px!important;width:100%}.mode-tabs{grid-column:1;grid-row:1;margin:0!important}.mode-tabs button{min-height:38px!important}#city-select-panel{grid-column:1;grid-row:2;margin:0!important}.province-picker{min-height:40px!important}.speed-heading{grid-column:2;grid-row:1;align-self:end;margin:0 0 5px!important}.speed-options{grid-column:2;grid-row:2}.speed-options button{min-height:40px!important}.bounce-heading{grid-column:1;grid-row:3;margin:0!important}.bounce-options{grid-column:1;grid-row:4}.bounce-options button{min-height:35px!important}.start-button{grid-column:2;grid-row:3 / 5;align-self:end;margin:0!important;min-height:40px!important}.start-note,#speed-note,.setup h2,.journey-summary,#city-note,.section-title,.setup-intro{display:none!important}.entry-screen footer{flex-basis:24px!important}
.game-topbar{flex-basis:23px}.game-hud{flex-basis:34px}.game-hud .score strong{font-size:21px}.game-hud strong{font-size:17px}.next-inline canvas{height:28px}.game-screen{padding:3px 0}.controls{flex-basis:42px}.controls button{min-height:40px}.controls small{display:none}.game-tools{flex-basis:26px}.utility-button{min-height:25px}.game-progress{flex-basis:18px;padding-bottom:2px}.tank-stage{padding-top:0;padding-bottom:4px}
.game-topbar{flex-basis:23px}.game-hud{flex-basis:34px}.game-hud .score strong{font-size:21px}.game-hud strong{font-size:17px}.next-inline canvas{height:28px}.game-screen{padding:3px 0}.controls{flex-basis:42px}.controls button{min-height:40px}.controls small{display:none}.game-progress{flex-basis:18px;padding-bottom:2px}.tank-stage{padding-top:0;padding-bottom:4px}
}
@media(max-width:720px){.province-picker-modal{padding:16px}.province-grid{grid-template-columns:repeat(5,minmax(0,1fr));grid-gap:5px}.province-grid button{min-height:30px;padding:4px 0;font-size:10px}.province-picker-modal h2{font-size:21px;margin:9px 0}.picker-note{font-size:8px;margin-top:8px}}
@media(max-height:520px) and (min-width:600px){.province-picker-modal{width:620px;padding:15px}.province-grid{grid-template-columns:repeat(9,minmax(0,1fr));grid-gap:5px}.province-grid button{min-height:30px;font-size:10px}.province-picker-modal h2{margin:5px 0;font-size:20px}.picker-note{font-size:8px;line-height:1.5;margin-top:7px}}
@@ -80,3 +80,8 @@ dialog,dialog.modal-fallback{position:fixed;top:calc(var(--content-top,56px) + 1
}
@media(max-width:720px){.entry-screen footer{padding:0}.entry-screen footer .text-button{min-height:20px;padding:2px 0}body.tiny-entry .header .brand small{display:none}body.tiny-entry .header .brand-mark{width:28px;height:28px;padding:4px}body.tiny-entry .header .brand{font-size:18px}}
@media(max-height:520px) and (min-width:600px){.entry-screen footer{padding:0}.entry-screen footer .text-button{min-height:20px;padding:2px 0}}
/* One unobtrusive icon opens all journey actions, outside the host toolbar. */
.controls{justify-content:center;align-items:center;flex:0 0 54px;padding:0 16px}.controls #pause{display:flex;align-items:center;justify-content:center;flex:0 0 46px;width:46px;height:46px;min-width:46px;min-height:46px;margin:0;border-radius:50%;background:#e9eedf;border:1px solid #cbd7bd;color:#52734c;box-shadow:0 2px 5px rgba(50,69,45,.06)}.journey-menu svg{display:block;width:23px;height:23px;fill:none;stroke:currentColor;stroke-width:2.3;stroke-linecap:round}.controls #pause:active{background:#dce6cd;transform:scale(.94)}
@media(max-height:520px){.controls{flex-basis:40px}.controls #pause{flex-basis:36px;width:36px;height:36px;min-height:36px;min-width:36px}.journey-menu svg{width:20px;height:20px}}
@media(prefers-reduced-motion:reduce){.controls #pause:active{transform:none}}
+5 -5
View File
@@ -4,15 +4,15 @@ const watch=p=>{p.on('pageerror',e=>errors.push(e.message));p.on('request',r=>{i
const state=p=>p.evaluate(()=>window.shanheDebug.state());
const context=await browser.newContext({viewport:{width:1440,height:1000},deviceScaleFactor:1});const page=await context.newPage();watch(page);
await page.goto('http://localhost:4173');await page.waitForFunction(()=>window.shanheDebug);assert.equal((await state(page)).status,'entry');assert.equal(await page.locator('#entry-screen').isVisible(),true);assert.equal(await page.locator('#game-screen').isVisible(),false);await page.waitForTimeout(300);assert.equal((await state(page)).dropped,0);await page.screenshot({path:'artifacts/desktop.png',fullPage:true});results.push('入口先选版本/地区/速度,未开局不生成碎片');
await page.locator('[data-mode="city"]').click();await page.locator('#province-picker').click();await page.locator('[data-province="440000"]').click();await page.locator('[data-speed="3"]').click();assert.equal((await state(page)).level,'440000');assert.equal((await state(page)).speed,3);await page.locator('#start').click();assert.equal((await state(page)).status,'playing');assert.equal(await page.locator('#entry-screen').isVisible(),false);assert.equal(await page.locator('.controls button').count(),3);assert.equal(await page.locator('#rotate,#drop,#shake,#hint,#shuffle').count(),0);assert.equal(await page.locator('#total').textContent(),'21');results.push('选广东21市和山河起飞后直接开局,游戏包含左晃、上晃、右晃三项操作');
await page.locator('[data-mode="city"]').click();await page.locator('#province-picker').click();await page.locator('[data-province="440000"]').click();await page.locator('[data-speed="3"]').click();assert.equal((await state(page)).level,'440000');assert.equal((await state(page)).speed,3);await page.locator('#start').click();assert.equal((await state(page)).status,'playing');assert.equal(await page.locator('#entry-screen').isVisible(),false);assert.equal(await page.locator('.controls button').count(),1);assert.equal(await page.locator('#rotate,#drop,#shake,#hint,#shuffle,#left,#right,#back,#up,#board-name,.game-tools').count(),0);assert.equal(await page.locator('#total').textContent(),'21');results.push('选广东21市和山河起飞后直接开局,底部仅一个圆形暂停图标,旧操作按钮和容器小字已移除');
const bounds=await page.locator('#tank').boundingBox();assert.ok(bounds.width<=440);const frameStyle=await page.locator('#tank').evaluate(e=>({left:parseFloat(getComputedStyle(e).borderLeftWidth),bottom:parseFloat(getComputedStyle(e).borderBottomWidth)}));assert.ok(frameStyle.left>=7&&frameStyle.bottom>=9);
await page.keyboard.down('ArrowLeft');await page.waitForFunction(()=>{const s=window.shanheDebug.state();return s.shakeOffset<0&&s.shakeCount>=2;});const a=await state(page);assert.ok(a.shakeOffset<0&&a.shakeCount>=2);const x=await page.locator('#tank').evaluate(e=>getComputedStyle(e).transform);assert.notEqual(x,'none');await page.keyboard.up('ArrowLeft');await page.waitForTimeout(350);const released=(await state(page)).shakeCount;await page.waitForTimeout(350);assert.equal((await state(page)).shakeCount,released);await page.keyboard.press('ArrowUp');assert.equal((await state(page)).shakeCount,released+1);await page.keyboard.press('ArrowDown');await page.keyboard.press('s');assert.equal((await state(page)).shakeCount,released+1);assert.ok((await state(page)).regions.every(r=>Math.abs(r.angle)<=.161));results.push('按住左右键驱动整个框,松开停止输入,上键轻颠,旧旋转/加速/S快捷键无效');
await page.waitForTimeout(2200);assert.ok((await state(page)).dropped>=2);await page.screenshot({path:'artifacts/city-desktop.png',fullPage:true});
await page.locator('#pause').click();assert.equal((await state(page)).status,'paused');const paused=await state(page);await page.mouse.move(bounds.x+bounds.width/2,bounds.y+160);await page.mouse.down();await page.mouse.move(bounds.x+bounds.width/2+60,bounds.y+220);await page.mouse.up();await page.waitForTimeout(200);assert.deepEqual((await state(page)).regions,paused.regions);await page.getByRole('button',{name:'继续游戏',exact:true}).click();assert.equal((await state(page)).status,'playing');results.push('暂停冻结物理,棋盘不支持碎片拖动');
await page.locator('#back').click();await page.getByRole('button',{name:'继续游戏',exact:true}).click();assert.equal((await state(page)).status,'playing');await page.locator('#back').click();await page.getByRole('button',{name:'结束旅程',exact:true}).click();assert.equal((await state(page)).screen,'result');await page.locator('#result-back').click();assert.equal((await state(page)).status,'entry');assert.equal((await state(page)).dropped,0);await page.locator('[data-mode="province"]').click();await page.locator('#start').click();assert.equal((await state(page)).level,'100000');assert.equal(await page.locator('#total').textContent(),'34');await page.locator('#pause').click();await page.getByRole('button',{name:'重新开局',exact:true}).click();assert.equal((await state(page)).dropped,1);assert.equal((await state(page)).shakeCount,0);results.push('返回确认、重新选择、重新开局均清理旧局与按键状态');await context.close();
const mobile=await browser.newContext({viewport:{width:390,height:844},deviceScaleFactor:2,isMobile:true,hasTouch:true});const mp=await mobile.newPage();watch(mp);await mp.goto('http://localhost:4173');await mp.waitForFunction(()=>window.shanheDebug);assert.ok(await mp.evaluate(()=>document.documentElement.scrollHeight<=innerHeight+1));await mp.screenshot({path:'artifacts/mobile.png',fullPage:true});await mp.locator('#start').tap();assert.equal((await state(mp)).status,'playing');await mp.locator('#left').tap();await mp.waitForTimeout(90);assert.ok((await state(mp)).shakeCount>0);await mp.screenshot({path:'artifacts/mobile-playing.png',fullPage:true});
await page.locator('#pause').click();assert.equal((await state(page)).status,'paused');const paused=await state(page);await page.mouse.move(bounds.x+bounds.width/2,bounds.y+160);await page.mouse.down();await page.mouse.move(bounds.x+bounds.width/2+60,bounds.y+220);await page.mouse.up();await page.waitForTimeout(200);assert.deepEqual((await state(page)).regions,paused.regions);await page.getByRole('button',{name:'继续游戏',exact:true}).click();assert.equal((await state(page)).status,'playing');results.push('暂停冻结物理,容器滑动不产生输入');
await page.locator('#pause').click();await page.getByRole('button',{name:'继续游戏',exact:true}).click();assert.equal((await state(page)).status,'playing');await page.locator('#pause').click();await page.getByRole('button',{name:'结束旅程',exact:true}).click();assert.equal((await state(page)).screen,'result');await page.locator('#result-back').click();assert.equal((await state(page)).status,'entry');assert.equal((await state(page)).dropped,0);await page.locator('[data-mode="province"]').click();await page.locator('#start').click();assert.equal((await state(page)).level,'100000');assert.equal(await page.locator('#total').textContent(),'34');await page.locator('#pause').click();await page.getByRole('button',{name:'重新开局',exact:true}).click();assert.equal((await state(page)).dropped,1);assert.equal((await state(page)).shakeCount,0);results.push('返回确认、重新选择、重新开局均清理旧局与按键状态');await context.close();
const mobile=await browser.newContext({viewport:{width:390,height:844},deviceScaleFactor:2,isMobile:true,hasTouch:true});const mp=await mobile.newPage();watch(mp);await mp.goto('http://localhost:4173');await mp.waitForFunction(()=>window.shanheDebug);assert.ok(await mp.evaluate(()=>document.documentElement.scrollHeight<=innerHeight+1));await mp.screenshot({path:'artifacts/mobile.png',fullPage:true});await mp.locator('#start').tap();assert.equal((await state(mp)).status,'playing');const board=await mp.locator('#board').boundingBox();const session=await mobile.newCDPSession(mp);await session.send('Input.dispatchTouchEvent',{type:'touchStart',touchPoints:[{x:board.x+60,y:board.y+board.height*.7}]});await session.send('Input.dispatchTouchEvent',{type:'touchMove',touchPoints:[{x:board.x+160,y:board.y+board.height*.7-30}]});await session.send('Input.dispatchTouchEvent',{type:'touchEnd',touchPoints:[]});await mp.waitForTimeout(90);assert.ok((await state(mp)).swipeCount>0);assert.equal((await state(mp)).swiping,false);await mp.screenshot({path:'artifacts/mobile-playing.png',fullPage:true});
for(const viewport of [{width:390,height:844},{width:320,height:568},{width:740,height:390}]){await mp.setViewportSize(viewport);await mp.waitForFunction(()=>{const r=document.querySelector('.controls').getBoundingClientRect();return r.bottom<=innerHeight+1;});const b=await mp.locator('.controls').boundingBox();assert.ok(b.y+b.height<=viewport.height+1,JSON.stringify(viewport)+' controls on screen');assert.ok(await mp.evaluate(()=>document.documentElement.scrollWidth<=innerWidth));const saved=await state(mp);assert.equal(saved.status,'playing');assert.ok(saved.scale>0);}
results.push('390/320窄屏及横屏:框体与三个触摸按钮同屏,无横向溢出,缩放保留局面');await mobile.close();
results.push('390/320窄屏及横屏:框体与圆形菜单按钮同屏,无横向溢出,缩放保留局面');await mobile.close();
const responsive=await browser.newContext({viewport:{width:320,height:568},isMobile:true,hasTouch:true});const rp=await responsive.newPage();watch(rp);await rp.goto('http://localhost:4173');await rp.waitForFunction(()=>window.shanheDebug);
for(const viewport of [{width:320,height:568},{width:375,height:667},{width:390,height:844},{width:740,height:390}]){await rp.setViewportSize(viewport);for(const chosen of ['province','city']){await rp.locator('[data-mode="'+chosen+'"]').click();await rp.waitForFunction(()=>document.getElementById('start').getBoundingClientRect().bottom<=innerHeight);const fit=await rp.evaluate(()=>({scroll:document.documentElement.scrollHeight,viewport:innerHeight,start:document.getElementById('start').getBoundingClientRect().bottom}));assert.ok(fit.scroll<=fit.viewport+1,JSON.stringify({viewport,chosen,fit}));}await rp.screenshot({path:'artifacts/entry-'+viewport.width+'x'+viewport.height+'.png'});}
await rp.setViewportSize({width:320,height:568});await rp.addStyleTag({content:':root{--safe-area-inset-top:44px;--safe-area-inset-bottom:34px}'});await rp.evaluate(()=>dispatchEvent(new Event('resize')));await rp.waitForFunction(()=>document.documentElement.scrollHeight<=innerHeight+1);await rp.locator('#province-picker').click();assert.equal(await rp.locator('.province-grid button').count(),27);assert.equal(await rp.locator('[data-province="710000"]').count(),0);const picker=await rp.locator('#modal').evaluate(e=>({scroll:e.scrollHeight,client:e.clientHeight}));assert.ok(picker.scroll<=picker.client+1);await rp.screenshot({path:'artifacts/province-picker-mobile.png'});await rp.locator('[data-province="330000"]').click();assert.equal((await state(rp)).level,'330000');results.push('入口省级/地级在320/375/390及横屏一屏显示;含44/34安全区;省区网格27项无需滚动');await responsive.close();
+22
View File
@@ -34,3 +34,25 @@ test('四档下落速度下,实测上晃分别为轻弹、正常和强弹,
test('左右晃动会缓存请求,碎片在两次150ms按键之间落地也能颠起',()=>{const l={id:'100000',name:'落地时序',width:1000,height:1000,regions:[square(0,0,0)],edges:[]};for(const delay of [0,25,60,100]){const g=new Game(l,320,590,0,()=>{},()=>.5,1);g.start();g.queue=[];g.clock=delay;const p=g.groups[0],b=p.body;M.Body.translate(b,{x:0,y:g.h-6-b.bounds.max.y});M.Body.setVelocity(b,{x:0,y:1});assert.ok(g.nudge(1));assert.equal(g.hopCount,0,'尚未接触时不在空中加速');for(let i=0;i<9;i++)g.tick(1000/60);assert.equal(g.hopCount,1,'下一次按键前已在落地时触发');assert.ok(b.velocity.y<0);g.destroy();}});
test('过期请求、空中长按和暂停不会凭空产生连续上抛',()=>{const l={id:'100000',name:'时序限制',width:1000,height:1000,regions:[square(0,0,0)],edges:[]},g=new Game(l,320,590,0,()=>{},()=>.5,1);g.start();g.queue=[];g.nudge(1);for(let i=0;i<180;i++)g.tick(1000/60);assert.equal(g.hopCount,0,'初始空中请求已过期');g.status='paused';assert.equal(g.nudge(1),false);const count=g.hopCount;g.tick(100);assert.equal(g.hopCount,count);g.destroy();});
test('容器滑动按位置分配力度:附近更强,远处仍动,没有瞬移或单片抓取',()=>{
const l={id:'100000',name:'位置力度',width:1000,height:1000,regions:[square(0,0,0),square(1,300,0)],edges:[]},g=new Game(l,420,560,0,()=>{},()=>.5,1);g.status='playing';g.queue=[];
const near=g.createGroup([0],{tx:0,ty:0,angle:0}),far=g.createGroup([1],{tx:0,ty:0,angle:0});M.Body.setPosition(near.body,{x:90,y:200});M.Body.setPosition(far.body,{x:330,y:420});const positions=g.groups.map(p=>({...p.body.position}));
assert.ok(g.swipe({x:90,y:200},{x:30,y:-10},32));assert.ok(near.body.velocity.x>far.body.velocity.x*3);assert.ok(far.body.velocity.x>0);assert.ok(near.body.velocity.y<far.body.velocity.y&&far.body.velocity.y<0);assert.deepEqual(g.groups.map(p=>({...p.body.position})),positions);assert.equal(g.swipeCount,1);g.tick(16.67);assert.ok(g.shake.offset>0);assert.ok(g.shake.y<0);g.destroy();
});
test('同样距离快速划动更有力;轻触、无效输入与暂停不触发晃动',()=>{
const run=elapsed=>{const g=game();g.start();g.queue=[];const body=g.groups[0].body,p={...body.position};g.swipe(p,{x:24,y:0},elapsed);const vx=body.velocity.x;g.destroy();return vx;};assert.ok(run(16)>run(64)*1.3);
const g=game();g.start();const p={x:200,y:200};assert.equal(g.swipe(p,{x:.1,y:.1},16),false);assert.equal(g.swipe(p,{x:NaN,y:0},16),false);assert.equal(g.swipe(p,{x:20,y:0},Infinity),false);g.status='paused';assert.equal(g.swipe(p,{x:20,y:0},16),false);assert.equal(g.swipeCount,0);g.destroy();
});
test('三档弹性连续任意方向滑动不超速、穿墙、旋转失控,落地滑动能颠起',()=>{
const l={id:'100000',name:'滑动边界',width:1000,height:1000,regions:[square(0,0,0)],edges:[]};for(let bounce=0;bounce<3;bounce++){
const g=new Game(l,320,590,0,()=>{},()=>.5,bounce);g.start();g.queue=[];const b=g.groups[0].body;M.Body.translate(b,{x:0,y:g.h-1-b.bounds.max.y});M.Sleeping.set(b,true);g.swipe({...b.position},{x:30,y:0},32);assert.ok(b.velocity.y<0,'落地碎片有上弹反馈');
for(let i=0;i<600;i++){g.swipe({x:160,y:450},{x:Math.sin(i*.13)*300,y:Math.cos(i*.17)*300},16.67);g.tick(16.67);const real=M.Bounds.create(b.vertices);assert.ok(Math.abs(b.velocity.x)<=g.bounce.maxX+.001);assert.ok(b.velocity.y<=9.001);assert.ok(Math.abs(b.angle)<=.1601);assert.ok(real.min.x>=-3&&real.max.x<=g.w+3&&real.max.y<=g.h+4);assert.ok(g.impacts.length<=20);}g.destroy();
}
});
test('每次划动只给一次冲量,短间隔限频,地块方向有分散且随后自由运动',()=>{
const l={id:'100000',name:'单次惯性',width:1000,height:1000,regions:[square(0,0,0),square(1,300,0)],edges:[]};let seq=0;const g=new Game(l,420,560,0,()=>{},()=>[.1,.9,.9,.1][seq++%4],1);g.status='playing';g.queue=[];
const a=g.createGroup([0],{tx:0,ty:100,angle:0}),b=g.createGroup([1],{tx:0,ty:100,angle:0});M.Body.setPosition(a.body,{x:120,y:200});M.Body.setPosition(b.body,{x:260,y:200});assert.ok(g.swipe({x:190,y:200},{x:70,y:0},100));assert.ok(a.body.velocity.x>0&&b.body.velocity.x>0);assert.ok(a.body.velocity.y*b.body.velocity.y<0,'相同大方向下有不同偏转');
const pos={...a.body.position};assert.equal(g.swipe({x:120,y:200},{x:-70,y:0},100),false);for(let i=0;i<15;i++)g.tick(16.67);assert.equal(g.swipeCount,1);assert.notDeepEqual(a.body.position,pos);assert.ok(g.swipe({x:120,y:200},{x:70,y:0},100));assert.equal(g.swipeCount,2);g.destroy();
});
+2 -2
View File
@@ -3,7 +3,7 @@ const browser=await chromium.launch({executablePath:'/Applications/Google Chrome
let tabs=await page.locator('.mode-tabs').boundingBox();await page.mouse.move(tabs.x+tabs.width-25,tabs.y+tabs.height/2);await page.mouse.down();await page.mouse.move(tabs.x+25,tabs.y+tabs.height/2,{steps:10});await page.mouse.up();assert.equal((await state()).level,'330000');assert.equal(await page.locator('[data-mode="city"]').getAttribute('aria-pressed'),'true');await page.waitForTimeout(400);const cityTrack=await page.locator('.mode-tabs').evaluate(e=>getComputedStyle(e,'::before').transform);assert.ok(!cityTrack.endsWith(', 0, 0)'),'滑块到达地级位置');
tabs=await page.locator('.mode-tabs').boundingBox();await page.mouse.move(tabs.x+25,tabs.y+tabs.height/2);await page.mouse.down();await page.mouse.move(tabs.x+tabs.width-25,tabs.y+tabs.height/2,{steps:10});await page.mouse.up();assert.equal((await state()).level,'100000');await page.waitForTimeout(400);await page.locator('[data-mode="city"]').tap();assert.equal((await state()).level,'330000');await page.locator('#province-picker').tap();assert.ok((await page.locator('#province-picker').getAttribute('class')).includes('expanded'));await page.locator('[data-province="440000"]').tap();assert.equal((await state()).level,'440000');
await page.locator('[data-bounce="2"]').tap();assert.equal((await state()).bounce,2);assert.ok((await page.locator('[data-bounce="2"]').getAttribute('class')).includes('bounce-pop'));await page.waitForTimeout(600);assert.ok(!(await page.locator('[data-bounce="2"]').getAttribute('class')).includes('bounce-pop'));assert.ok(await page.evaluate(()=>document.documentElement.scrollHeight<=innerHeight+1));await page.screenshot({path:'artifacts/animated-entry.png'});
await page.locator('[data-mode="province"]').tap();await page.locator('[data-speed="3"]').tap();await page.clock.install();await page.locator('#start').tap();await page.clock.runFor(7800);await page.locator('#up').tap();await page.clock.runFor(320);const strong=await state();assert.equal(strong.bounce,2);assert.ok(strong.shakeCount>0);await page.screenshot({path:'artifacts/strong-bounce.png'});
await page.locator('[data-mode="province"]').tap();await page.locator('[data-speed="3"]').tap();await page.clock.install();await page.locator('#start').tap();await page.clock.runFor(7800);await page.keyboard.press('ArrowUp');await page.clock.runFor(320);const strong=await state();assert.equal(strong.bounce,2);assert.ok(strong.shakeCount>0);await page.screenshot({path:'artifacts/strong-bounce.png'});
let seenContact=false;for(let i=0;i<70;i++){await page.clock.runFor(32);const s=await state();if(s.contactPulse>0){seenContact=true;await page.screenshot({path:'artifacts/contact-feedback.png'});break;}}assert.ok(seenContact,'真实碰撞触发短促反馈');
const reduced=await browser.newContext({viewport:{width:320,height:568},reducedMotion:'reduce'});const rp=await reduced.newPage();rp.on('pageerror',e=>errors.push(e.message));await rp.goto('http://localhost:4173');await rp.locator('[data-bounce="2"]').click();assert.ok(!(await rp.locator('[data-bounce="2"]').getAttribute('class')).includes('bounce-pop'));assert.equal(await rp.locator('.mode-tabs').evaluate(e=>getComputedStyle(e,'::before').transitionDuration),'0s');assert.equal(await rp.locator('[data-bounce="2"]').evaluate(e=>getComputedStyle(e).animationName),'none');await rp.locator('#start').click();await rp.locator('#up').click();assert.equal((await rp.evaluate(()=>shanheDebug.state())).shakeCount,1);assert.deepEqual(errors,[]);
const reduced=await browser.newContext({viewport:{width:320,height:568},reducedMotion:'reduce'});const rp=await reduced.newPage();rp.on('pageerror',e=>errors.push(e.message));await rp.goto('http://localhost:4173');await rp.locator('[data-bounce="2"]').click();assert.ok(!(await rp.locator('[data-bounce="2"]').getAttribute('class')).includes('bounce-pop'));assert.equal(await rp.locator('.mode-tabs').evaluate(e=>getComputedStyle(e,'::before').transitionDuration),'0s');assert.equal(await rp.locator('[data-bounce="2"]').evaluate(e=>getComputedStyle(e).animationName),'none');await rp.locator('#start').click();await rp.keyboard.press('ArrowUp');assert.equal((await rp.evaluate(()=>shanheDebug.state())).shakeCount,1);assert.deepEqual(errors,[]);
fs.writeFileSync('artifacts/interactions-report.json',JSON.stringify({passed:true,results:['默认推荐蹦蹦跳','模式左右滑动和点击均更新真实关卡,滑块到位','省区选择与弹性按钮回弹不破坏点击','三向晃动和真实碰撞短反馈','减少动态效果设置禁用装饰动画,游戏仍可操作'],errors},null,2));console.log('滑动选择、回弹点击、强弹试玩、真实碰撞反馈与减少动态效果通过');await browser.close();
+1 -1
View File
@@ -2,7 +2,7 @@ import {chromium} from 'playwright';import assert from 'node:assert/strict';impo
const browser=await chromium.launch({executablePath:'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',headless:true});
const context=await browser.newContext({viewport:{width:390,height:844},isMobile:true,hasTouch:true,deviceScaleFactor:2});const p=await context.newPage(),errors=[];p.on('pageerror',e=>errors.push(e.message));
await p.addInitScript(()=>{let seed=785;Math.random=()=>{seed=(seed*1664525+1013904223)>>>0;return seed/4294967296;};window.calls=[];window.xhs={miniTool:{writeTempFile:async args=>{window.exportData=args.data;window.calls.push('write');return {filePath:'test://fresh-card.png'};},postNote:async args=>{window.posted=args;window.calls.push('post');},saveImageToPhotosAlbum:async args=>{window.saved=args;window.calls.push('save');}}};});
await p.clock.install();await p.goto('http://localhost:4173');await p.waitForFunction(()=>window.shanheDebug);await p.locator('[data-speed="3"]').click();await p.locator('[data-bounce="2"]').click();await p.locator('#start').click();await p.clock.runFor(19500);const before=await p.evaluate(()=>shanheDebug.state());assert.equal(before.status,'playing');await p.locator('#up').tap();await p.clock.runFor(100);assert.ok((await p.evaluate(()=>shanheDebug.state())).shakeY<0);await p.locator('#pause').tap();const paused=await p.evaluate(()=>shanheDebug.state());await p.clock.runFor(60000);assert.equal((await p.evaluate(()=>shanheDebug.state())).elapsed,paused.elapsed);await p.getByRole('button',{name:'结束旅程',exact:true}).tap();const ended=await p.evaluate(()=>shanheDebug.state());assert.equal(ended.screen,'result');assert.equal(ended.status,'ended');assert.equal(ended.result.bounceName,'弹力全开');assert.equal(ended.result.speedName,'山河起飞');assert.equal(ended.result.score,paused.score);assert.equal(ended.result.elapsed,paused.elapsed);assert.equal(ended.result.history.at(-1).ms,paused.elapsed);assert.equal(ended.result.history.at(-1).score,paused.score);assert.ok(ended.result.history.every((v,i,a)=>!i||v.ms>=a[i-1].ms));assert.equal(ended.result.dropped,ended.dropped);assert.ok(ended.dropped<34,'结局截图保留未完成状态');await p.screenshot({path:'artifacts/result-mobile.png'});
await p.clock.install();await p.goto('http://localhost:4173');await p.waitForFunction(()=>window.shanheDebug);await p.locator('[data-speed="3"]').click();await p.locator('[data-bounce="2"]').click();await p.locator('#start').click();await p.clock.runFor(19500);const before=await p.evaluate(()=>shanheDebug.state());assert.equal(before.status,'playing');await p.keyboard.press('ArrowUp');await p.clock.runFor(100);assert.ok((await p.evaluate(()=>shanheDebug.state())).shakeY<0);await p.locator('#pause').tap();const paused=await p.evaluate(()=>shanheDebug.state());await p.clock.runFor(60000);assert.equal((await p.evaluate(()=>shanheDebug.state())).elapsed,paused.elapsed);await p.getByRole('button',{name:'结束旅程',exact:true}).tap();const ended=await p.evaluate(()=>shanheDebug.state());assert.equal(ended.screen,'result');assert.equal(ended.status,'ended');assert.equal(ended.result.bounceName,'弹力全开');assert.equal(ended.result.speedName,'山河起飞');assert.equal(ended.result.score,paused.score);assert.equal(ended.result.elapsed,paused.elapsed);assert.equal(ended.result.history.at(-1).ms,paused.elapsed);assert.equal(ended.result.history.at(-1).score,paused.score);assert.ok(ended.result.history.every((v,i,a)=>!i||v.ms>=a[i-1].ms));assert.equal(ended.result.dropped,ended.dropped);assert.ok(ended.dropped<34,'结局截图保留未完成状态');await p.screenshot({path:'artifacts/result-mobile.png'});
await p.locator('#share-note').tap();await p.waitForFunction(()=>window.posted);const posted=await p.evaluate(()=>window.posted);assert.equal(posted.pageType,'photo_publish');assert.equal(posted.mediaInfo.image_resources[0].url,'test://fresh-card.png');assert.ok(posted.content.includes('弹力全开')&&posted.content.includes('山河起飞'));assert.ok(posted.title.length<=20&&posted.content.length<=1000);const image=await p.evaluate(()=>window.exportData);fs.writeFileSync('artifacts/result-card.png',Buffer.from(image.split(',')[1],'base64'));await p.locator('#save-card').tap();await p.waitForFunction(()=>window.saved);assert.deepEqual(await p.evaluate(()=>window.calls),['write','post','write','save']);
// Failure/cancellation must leave the card usable; no-SDK must not throw.
await p.evaluate(()=>{window.xhs.miniTool.postNote=async()=>{throw Error('cancelled');};});await p.locator('#share-note').tap();await p.waitForFunction(()=>!document.querySelector('#share-note').disabled);assert.equal(await p.locator('#result-screen').isVisible(),true);await p.evaluate(()=>{window.xhs=null;});await p.locator('#share-note').tap();assert.ok((await p.locator('#toast').textContent()).includes('小红书小工具'));
+48
View File
@@ -0,0 +1,48 @@
import {chromium} from 'playwright';
import assert from 'node:assert/strict';
import fs from 'node:fs';
const browser=await chromium.launch({executablePath:'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',headless:true});
const context=await browser.newContext({viewport:{width:390,height:844},isMobile:true,hasTouch:true,deviceScaleFactor:2});
const p=await context.newPage(),errors=[],results=[];
p.on('pageerror',e=>errors.push(e.message));
await p.addInitScript(()=>{let seed=785;Math.random=()=>{seed=(seed*1664525+1013904223)>>>0;return seed/4294967296;};});
await p.goto('http://localhost:4173');await p.clock.install();
await p.locator('[data-speed="3"]').tap();await p.locator('#start').tap();await p.clock.runFor(12000);
const state=()=>p.evaluate(()=>shanheDebug.state()),cdp=await context.newCDPSession(p);
const touch=async(type,x,y)=>cdp.send('Input.dispatchTouchEvent',{type,touchPoints:x===undefined?[]:[{x,y,id:1}]});
let board=await p.locator('#board').boundingBox();
assert.equal(await p.locator('#board').evaluate(e=>getComputedStyle(e).touchAction),'none');
assert.deepEqual(await p.locator('.controls button').evaluateAll(buttons=>buttons.map(b=>b.id)),['pause']);
const row=await p.locator('.controls').boundingBox();
for(const id of ['pause']){const r=await p.locator('#'+id).boundingBox();assert.ok(r.y>=row.y&&r.y+r.height<=row.y+row.height+1);}
assert.equal(await p.locator('#board-name,.board-tag,#left,#right,#up,#back,.game-tools').count(),0);
const icon=await p.locator('#pause').evaluate(e=>({text:e.textContent.trim(),label:e.getAttribute('aria-label'),w:e.offsetWidth,h:e.offsetHeight,r:getComputedStyle(e).borderRadius}));assert.equal(icon.text,'');assert.equal(icon.w,icon.h);assert.equal(icon.r,'50%');assert.ok(icon.label.includes('暂停'));
const x=board.x+board.width*.35,y=board.y+board.height*.72;
const initial=await state();
await touch('touchStart',x,y);await touch('touchMove',x+2,y+1);await p.clock.runFor(32);await touch('touchEnd');
assert.equal((await state()).swipeCount,initial.swipeCount,'轻触和手抖不算滑动');
// No force is delivered while the finger moves or remains pressed.
await touch('touchStart',x,y);
for(let i=1;i<=6;i++){await touch('touchMove',x+i*16,y-i*8);await p.clock.runFor(24);}
const pending=await state();assert.ok(pending.swiping);assert.equal(pending.swipeCount,initial.swipeCount);assert.equal(pending.shakeCount,initial.shakeCount);
await touch('touchEnd');assert.equal((await state()).swipeCount,initial.swipeCount+1);assert.equal((await state()).swiping,false);
await p.clock.runFor(48);const released=await state();assert.ok(released.shakeOffset!==0||released.shakeY!==0);await p.screenshot({path:'artifacts/swipe-playing.png'});
await p.clock.runFor(600);assert.equal((await state()).swipeCount,released.swipeCount);assert.notDeepEqual((await state()).regions,released.regions,'松手后继续靠惯性和重力运动');
results.push('一次轻划仅在松手时触发一次晃动,移动中不施力,松手后自由运动');
// A long slow drag cannot steer pieces. Neither can a flick held before release.
board=await p.locator('#board').boundingBox();let count=(await state()).swipeCount;
await touch('touchStart',x,y);for(let i=1;i<=8;i++){await p.clock.runFor(100);await touch('touchMove',x+i*8,y);}await touch('touchEnd');assert.equal((await state()).swipeCount,count,'慢拖不触发');
await touch('touchStart',x,y);await touch('touchMove',x+90,y-20);await p.clock.runFor(600);assert.equal((await state()).swipeCount,count);await touch('touchEnd');assert.equal((await state()).swipeCount,count,'划后按住不能储存冲量');
results.push('慢拖、按住以及划后停住再松手均不施力,无持续牵引');
board=await p.locator('#board').boundingBox();
await touch('touchStart',board.x+80,board.y+board.height*.6);await touch('touchMove',board.x+140,board.y+board.height*.6-20);await p.clock.runFor(32);assert.ok((await state()).swiping);
await touch('touchCancel');assert.equal((await state()).swiping,false);const canceled=(await state()).swipeCount;await p.clock.runFor(300);assert.equal((await state()).swipeCount,canceled);
results.push('系统取消触摸释放指针捕获并清理待处理输入');
board=await p.locator('#board').boundingBox();
await touch('touchStart',board.x+80,board.y+board.height*.55);await touch('touchMove',board.x+125,board.y+board.height*.55-25);await p.clock.runFor(32);
// A keyboard pause while the finger is still down must discard pending movement.
await p.keyboard.press(' ');const paused=await state();assert.equal(paused.status,'paused');assert.equal(paused.swiping,false);await touch('touchMove',board.x+180,board.y+board.height*.5);await touch('touchEnd');await p.clock.runFor(1000);assert.equal((await state()).swipeCount,paused.swipeCount);assert.deepEqual((await state()).regions,paused.regions);
await p.getByRole('button',{name:'继续游戏',exact:true}).tap();await p.clock.runFor(100);assert.equal((await state()).swipeCount,paused.swipeCount);await p.locator('#pause').tap();await p.getByRole('button',{name:'结束旅程',exact:true}).tap();assert.equal((await state()).screen,'result');
results.push('滑动中暂停清空手势,暂停冻结局面,继续后不重放旧输入;底部旅程操作可结束并生成成绩');
assert.deepEqual(errors,[]);fs.writeFileSync('artifacts/swipe-report.json',JSON.stringify({scope:'Modern Chrome / CDP touch input, not native container acceptance',passed:true,results,errors},null,2));
console.log(results.join('\n'));await browser.close();