Javascript is required
跳一跳脚本

获取截屏

Version-1

# 截取手机的屏幕
os.system('adb shell screencap -p /sdcard/01.png')
# 把模拟器里面的文件或文件夹传到电脑上
os.system('adb pull /sdcard/01.png /project_base/')

Version-2

import uiautomator2 as u2


input_filename = 'monitor-1.png'
d = u2.connect("b8477fa8")
d.screenshot(input_filename)

Version-3

Python-mss模块是截图最快的模块

from mss.darwin import MSS

mode = "pc"

def get_screenshot():
    if mode == 'pc':
        monitor = {"top": 160, "left": 20, "width": 360, "height": 700}
        with MSS() as sct:
            screenshot = np.array(sct.grab(monitor))
            # screenshot = cv2.cvtColor(screenshot, cv2.COLOR_RGB2BGR)
            cv2.imwrite(input_filename, screenshot)

图片对比

模板图片,为脚部分。通过模板匹配,该函数返回脚坐标值 图像模板匹配(Match Template)

def start(target):
    template = cv2.imread("images/h.png")
    theight, twidth = template.shape[:2]
    result = cv2.matchTemplate(target, template, cv2.TM_SQDIFF_NORMED)
    min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
    return (min_loc[0] + twidth // 2, min_loc[1] + theight // 2)

模拟滑动

def jump(distance):
    # 设置按压时间
    press_time = int(distance * 2.59)

    # 生成随机手机屏幕模拟触摸点,防止成绩无效
    # 生成随机整数(0-9),最终数值为(0-90)
    rand = random.randint(0, 9) * 10

    # adb长按操作,即在手机屏幕上((320-410),(410-500))坐标处长按press_time毫秒
    cmd = ('adb shell input swipe %i %i %i %i ' + str(press_time)) % (320 + rand, 410 + rand, 320 + rand, 410 + rand)

    # 输出adb命令
    print(cmd)

    # 执行adb命令
    os.system(cmd)