Loading... # 小恐龙の得分秘籍  前几天看到有群友在群里晒他玩 `chrome://dino/`的战绩,我微微一笑: ## 法一:让小恐龙自动浪 先上代码 ``` function TrexRunnerBot() { const makeKeyArgs = (keyCode) => { const preventDefault = () => void 0; return {keyCode, preventDefault}; }; const upKeyArgs = makeKeyArgs(38); const downKeyArgs = makeKeyArgs(40); const startArgs = makeKeyArgs(32); if (!Runner().playing) { Runner().onKeyDown(startArgs); setTimeout(() => { Runner().onKeyUp(startArgs); }, 500); } function conquerTheGame() { if (!Runner || !Runner().horizon.obstacles[0]) return; const obstacle = Runner().horizon.obstacles[0]; if (obstacle.typeConfig && obstacle.typeConfig.type === 'SNACK') return; if (needsToTackle(obstacle) && closeEnoughToTackle(obstacle)) tackle(obstacle); } function needsToTackle(obstacle) { return obstacle.yPos !== 50; } function closeEnoughToTackle(obstacle) { return obstacle.xPos <= Runner().currentSpeed * 18; } function tackle(obstacle) { if (isDuckable(obstacle)) { duck(); } else { jumpOver(obstacle); } } function isDuckable(obstacle) { return obstacle.yPos === 50; } function duck() { Runner().onKeyDown(downKeyArgs); setTimeout(() => { Runner().onKeyUp(downKeyArgs); }, 500); } function jumpOver(obstacle) { if (isNextObstacleCloseTo(obstacle)) jumpFast(); else Runner().onKeyDown(upKeyArgs); } function isNextObstacleCloseTo(currentObstacle) { const nextObstacle = Runner().horizon.obstacles[1]; return nextObstacle && nextObstacle.xPos - currentObstacle.xPos <= Runner().currentSpeed * 42; } function jumpFast() { Runner().onKeyDown(upKeyArgs); Runner().onKeyUp(upKeyArgs); } return {conquerTheGame: conquerTheGame}; } let bot = TrexRunnerBot(); let botInterval = setInterval(bot.conquerTheGame, 2); ``` 复制便捷版 ``` function TrexRunnerBot(){function f(){Runner().onKeyDown(d);setTimeout(function(){Runner().onKeyUp(d)},500)}var b=function(a){return{keyCode:a,preventDefault:function(){}}},c=b(38),d=b(40),e=b(32);Runner().playing||(Runner().onKeyDown(e),setTimeout(function(){Runner().onKeyUp(e)},500));return{conquerTheGame:function(){if(Runner&&Runner().horizon.obstacles[0]){var a=Runner().horizon.obstacles[0];if((!a.typeConfig||"SNACK"!==a.typeConfig.type)&&50!==a.yPos&&a.xPos<=18*Runner().currentSpeed)if(50=== a.yPos)f();else{var b=Runner().horizon.obstacles[1];if(b&&b.xPos-a.xPos<=42*Runner().currentSpeed)Runner().onKeyDown(c),Runner().onKeyUp(c);else Runner().onKeyDown(c)}}}}}var bot=TrexRunnerBot(),botInterval=setInterval(bot.conquerTheGame,2); ``` ## 法二:在分数上动点手脚 代码拿走 ``` let hackScore = 0; Object.defineProperty(Runner.instance_, 'distanceRan', { get: () => hackScore, set: (value) => hackScore = value + Math.floor(Math.random() * 1000),//1000是分数的倍数 configurable: true, enumerable: true, }); ``` 复制便捷版 ``` var hackScore=0;Object.defineProperty(Runner.instance_,"distanceRan",{get:function(){return hackScore},set:function(a){return hackScore=a+Math.floor(1E3*Math.random())},configurable:!0,enumerable:!0}); ``` 将上面代码执行之后,再次运行程序,你会发现你获取分数的速度提升了一千倍。 如果你将第一个方案和这个方案的代码结合,会获得一个能够自动奔跑获得高分的“智能小恐龙”。 不过因为我们的“外挂”是基于计时器进行距离计算并模拟用户操作的,当你获得很高很高的分数之后,障碍物推进速度过快,一旦你进行窗口的来回切换,游戏进行暂停和游玩的状态切换,很大概率上“外挂”操作会延时,导致 `GAME OVER`。 如何能避免这个事情呢,我们来讲讲第三个套路。 ## 法三:直·接·开·挂~话说前两个不算开挂吗~ 诺,代码 ``` Runner.instance_.gameOver=function(){}; ``` 上面代码在执行之后,会清空游戏的中断逻辑,配合第二个方案的快速获得分数的代码,你可以得到一只拥有穿越障碍物能力的小恐龙:勇往无前,永不停歇,分数不停的增长,直到报错。 ## 最重要的:食用方法 在 `chrome://dino`中按下 `F12`,调到 `console`,在里面输入你想要的代码就好啦! <hr class="content-copyright" style="margin-top:50px" /><blockquote class="content-copyright" style="font-style:normal"><p class="content-copyright">版权属于:ZC.TigerRoot</p><p class="content-copyright">本文链接:<a class="content-copyright" href="https://blog.tigerroot.cn/archives/59/">https://blog.tigerroot.cn/archives/59/</a></p><p class="content-copyright">转载时须注明出处及本声明</p></blockquote> Last modification:December 20th, 2020 at 10:34 pm © 允许规范转载 Support 如果觉得我的文章对你有用,请随意赞赏 Appreciate the author 支付宝微信