前言
昨天下午,微信小程序开放了游戏接口,朋友圈瞬间炸开了锅,尤其是“跳一跳”这款游戏的成绩单,在朋友圈刷了一波又一波。
下面就来给大家介绍了关于Kotlin破解Android版的微信小游戏跳一跳的相关内容,让大家可以好好炫耀一番。
成果
跳一跳
微信小程序可以玩游戏了,我们来破解一下《跳一跳》这个官方出品的小游戏吧。
思路
用usb调试安卓手机,用adb截图并用鼠标测量距离,然后计算按压时间后模拟按压。
$ adb shell input swipe <x1> <y1> <x2> <y2> [duration(ms)] (Default: touchscreen) # 模拟长按$ adb shell screencap <filename> # 保存截屏到手机$ adb pull /sdcard/screen.png # 下载截屏文件到本地
源码
开发环境: Kotlin, IetelliJ IDEA
https://github.com/iOSDevLog/JumpJump
主要源码
fun main(args: Array<String>) { val jumpjump = JumpJump() var isFirst = true var firstPoint: Point? = null var secondPoint: Point? val jPanel = object : JPanel() { override fun paintComponent(g: Graphics) { super.paintComponent(g) try { var bufferedImage = ImageIO.read(File(SCREENSHOT_LOCATION)) val newImage = BufferedImage(675, 1200, bufferedImage.getType()) val gTemp = newImage.graphics gTemp.drawImage(bufferedImage, 0, 0, 675, 1200, null) gTemp.dispose() bufferedImage = newImage g.drawImage(bufferedImage, 0, 0, null) } catch (e: IOException) { e.printStackTrace() } } } jPanel.addMouseListener(object : MouseListener { override fun mouseReleased(e: MouseEvent?) { } override fun mouseEntered(e: MouseEvent?) { } override fun mouseClicked(e: MouseEvent?) { } override fun mouseExited(e: MouseEvent?) { } override fun mousePressed(e: MouseEvent?) { println("mousePressed") e.let { if (isFirst) { println("first {pomt" + e!!.x + " " + e.y) firstPoint = e.point isFirst = false } else { secondPoint = e!!.point val distance = distance(firstPoint!!, secondPoint!!) println("distance:" + distance) isFirst = true //magic number call(distance * 2.2) try { // wait for screen cap Thread.sleep(2500) } catch (e1: InterruptedException) { e1.printStackTrace() } printScreen() jPanel.validate() jPanel.repaint() } } } }) jumpjump.isVisible = true jumpjump.contentPane.add(jPanel) printScreen() jumpjump.repaint() jumpjump.validate()}fun distance(a: Point, b: Point): Int { return Math.sqrt((a.x - b.getX()) * (a.x - b.getX()) + (a.y - b.getY()) * (a.y - b.getY())).toInt()}
使用方法
参考
https://github.com/easyworld/PlayJumpJumpWithMouse
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对VeVb武林网的支持。
新闻热点
疑难解答