[Python]50行代码造一个微信跳一跳游戏辅助

最近微信跳一跳小游戏非常火,小东最近也比较忙,就直接上Python版跳一跳辅助刷分代码,其中有注释,希望对大家程序开发有所启迪!

0x01 实现原理

计算两点距离,反算出需要按压时间,使用adb模拟手机的按压,即可实现微信跳一跳的辅助!


0x02 Python版代码

# name: have a jump  
# author: DYBOY  
# time: 2017-01-06  
# charset: utf-8  


import os  
import PIL  
import numpy  
import matplotlib.pyplot as plt  
from matplotlib.animation import FuncAnimation  
import time  

#全局变量  
need_update = True  


#功能区  

#获取截图  
def get_screen_image():  
    os.system('adb shell screencap -p /sdcard/1.png')#获取当前界面的手机截图并保存到根目录  
    os.system('adb pull /sdcard/1.png')  #获取手机中的截图  
    return numpy.array(PIL.Image.open('1.png'))  #二维数组展示图片  

#跳转  
def jump_to_next(point1, point2):  
    x1, y1 = point1; x2, y2 = point2  
    distance = ((x2-x1)**2 + (y2-y1)**2)**0.5  
    os.system('adb shell input swipe 320 410 320 410 {}'.format(int(distance*2.1)))  

#绑定的鼠标单击事件  
def on_click(event, coor=[]):  
    global need_update  
    coor.append((event.xdata, event.ydata))  
    if len(coor) == 2:  
        jump_to_next(coor.pop(), coor.pop())  
    need_update = True  

#更新图片  
def update_screen(frame):  
    global need_update  
    if need_update:  
        time.sleep(1)  
        axes_image.set_array(get_screen_image())  
        need_update = False  
    return axes_image,  

figure = plt.figure()#创建图片对象  
axes_image = plt.imshow(get_screen_image(), animated=True)#把获取的图片话在坐标轴上面  
figure.canvas.mpl_connect('button_press_event', on_click)  
ani = FuncAnimation(figure, update_screen, interval=50, blit=True)  
plt.show()

0x03 运行结果

运行结果

值得一提的是,Github上最近传得比较火的一款辅跳一跳助确实写得很厉害,可以自动识别,并且打包成了EXE可执行文件,兼容IOS与Android,还有很多可以学习的地方,以上只是小东个人的理解所写,望多多建议!

整个需要的工具都打包在压缩包了,感兴趣的朋友可以下载尝试!

下载地址:jump2018.zip

发表评论 / Comment

用心评论~


Warning: Cannot modify header information - headers already sent by (output started at /www/wwwroot/blog.dyboy.cn/content/templates/dyblog/footer.php:56) in /www/wwwroot/blog.dyboy.cn/include/lib/view.php on line 23