用户:
tq_xyy查看:1 回复:2 评论:1 创建时间:2022-01-29T11:52:28
今天逆向编程猫首页时,发现了一个奇怪的全局变量:
恭喜少年,你找到了编程猫的第一颗彩蛋,输入 start(); \n后即可开始《编程猫躲车车》游戏!
555555,真是神奇
按照上面的说明,敲入
start();
你猜怎么着,成了:

本着刨根问底的精神,经过一番反混淆,我们得到了它的源代码
;(function () {
if (window.console) {
let pos = 19
function Car() {
this.x = 0
this.y = 0
this.speed = 1
}
let score = 0
// 处理键盘输入
window.onkeydown = function (event) {
// 左键
if (event.keyCode === 37) {
pos -= 1
if (pos < 0) {
pos = 0
}
}
// 右键
if (event.keyCode === 39) {
pos += 1
if (pos > 38) {
pos = 38
}
}
}
let generateCarTimer,
carMoveTimer,
difficultyTimer,
frameCount = 0
function gameOver() {
clearInterval(generateCarTimer)
clearInterval(carMoveTimer)
clearInterval(difficultyTimer)
setTimeout(() => {
console.log(
'游戏结束,您的得分: ' + score + ',分享到QQ空间: %o'喵cgi' + '-bin/qzshare/cgi_qzshare_onekey?url=https:' + '//www.codemao.cn&showcount=1&desc=&summary=' +
'我发现了编程猫的console小游戏《编程猫躲车车》,得了' +
score +
'分哦~' +
'&pics=https://static.codemao.cn/whitepaw/static/codemao-game.png&style=203&width=98&height=22'
)
}, 100)
}
let cars = [],
difficulty = 1
function startGame() {
// 生成汽车
generateCarTimer = setInterval(() => {
var newCarCount = Math.floor(5 * Math.random() * difficulty)
for (let i = 0; i < newCarCount; i++) {
var car = new Car()
car.x = Math.floor(40 * Math.random())
car.y = 0
car.speed = Math.random() * difficulty
cars.push(car)
}
}, 1000)
// 汽车运动&渲染
carMoveTimer = setInterval(() => {
cars.forEach((car, index) => {
car.y += car.speed
if (car.y >= 31) {
cars.splice(index, 1)
score++
}
})
// 渲染
console.log(
(() => {
let str = ''
for (let row = 0; row < 20; row++) {
str += '\n'
for (var column = 0; column < 40; column++) {
let char = '--'
if (19 == row && column == pos) {
char = '🐱'
}
cars.forEach((car) => {
const x = Math.floor(car.x),
y = Math.floor(car.y)
if (x == column && y == row) {
if (
Math.abs(car.y - 19) < 1 &&
column == pos
) {
gameOver()
}
char = '🚘'
}
})
str += char
}
}
return (str +=
' 《编程猫躲车车》得分: ' + score)
})()
)
// 防止内存爆炸
frameCount += 1
if (frameCount > 300) {
console.clear()
frameCount = 0
}
}, 100)
// 难度
difficultyTimer = setInterval(function () {
difficulty *= 1.1
}, 3000)
}
window.codemao =
'恭喜少年,你找到了编程猫的第一颗彩蛋,输入 start(); \n后即可开始《编程猫躲车车》游戏! '
window.start = function start() {
difficulty = 1.1
starts = []
score = 0
pos = 19
frameCount = 0
console.log(
'%c请先用鼠标点击一下网页区域,游戏需要捕捉网页 上的键盘事件(你应该懂吧)!',
'font-size:16px;color:#ff6700;'
)
console.log(
'使用键盘左右键移动最下方的小猫"🐱",躲开所有的汽车"🚘",汽车数量和速度会一直增加,看看谁坚持的最久吧!'
)
var count = 6
return (
setTimeout(function () {
count--
if (count <= 1) {
startGame()
} else {
console.log(count)
setTimeout(arguments.callee, 1000)
}
}, 1000),
'倒计时!'
)
}
} else
window.console = {
log: function () {},
}
})()
剩下的只有各位的想象力了。复制到控制台就可以运行了,和官网的一模一样。
tips: 编程猫的网站是一个单页应用程序,所以在编程猫任何一个界面打开都有哦
imgsrc="https://static.codemao.cn/emoji/codemao/%E7%BC%96%E7%A8%8B%E7%8C%AB_%E5%8E%89%E5%AE%B3%E4%BA%86.gif"alt="emotion_编程猫_厉害了" 好活
点赞0
评论