• 大小: 12.95MB
    文件类型: .zip
    金币: 2
    下载: 0 次
    发布日期: 2024-02-04
  • 语言: Python
  • 标签: Python  

资源简介

来源于微博,版权归原著。教你用Python来玩微信跳一跳 | 神奇的战士 | 这个不辣~ http://thinkhard.tech/2017/12/29/教你用Python来玩微信跳一跳/

资源截图

代码片段和文件信息

from __future__ import print_function

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import math
import time
import os
import cv2
import datetime

scale = 0.25

template = cv2.imread(‘character.png‘)
template = cv2.resize(template (0 0) fx=scale fy=scale)
template_size = template.shape[:2]


def search(img):
    result = cv2.matchTemplate(img template cv2.TM_SQDIFF)
    min_val max_val min_loc max_loc = cv2.minMaxLoc(result)

    cv2.rectangle(img (min_loc[0] min_loc[1]) (min_loc[0] + template_size[1] min_loc[1] + template_size[0]) (255 0 0) 4)

    return img min_loc[0] + template_size[1] / 2 min_loc[1] +  template_size[0]

def pull_screenshot():
    filename = datetime.datetime.now().strftime(“%H%M%S“) + ‘.png‘
    os.system(‘mv autojump.png {}‘.format(filename))
    os.system(‘adb shell screencap -p /sdcard/autojump.png‘)
    os.system(‘adb pull /sdcard/autojump.png .‘)

def jump(distance):
    press_time = distance * 1.35
    press_time = int(press_time)
    cmd = ‘adb shell input swipe 320 410 320 410 ‘ + str(press_time)
    print(cmd)
    os.system(cmd)

def update_data():
    global src_x src_y

    img = cv2.imread(‘autojump.png‘)
    img = cv2.resize(img (0 0) fx=scale fy=scale)

    img src_x src_y = search(img)
    return img


fig = plt.figure()
index = 0

# pull_screenshot()
img = update_data()

update = True 
im = plt.imshow(img animated=True)


def updatefig(*args):
    global update

    if update:
        time.sleep(1)
        pull_screenshot()
        im.set_array(update_data())
        update = False
    return im

def onclick(event):      
    global update    
    global src_x src_y
    
    dst_x dst_y = event.xdata event.ydata

    distance = (dst_x - src_x)**2 + (dst_y - src_y)**2 
    distance = (distance ** 0.5) / scale
    print(‘distance = ‘ distance)
    jump(distance)
    update = True


fig.canvas.mpl_connect(‘button_press_event‘ onclick)
ani = animation.FuncAnimation(fig updatefig interval=5 blit=True)
plt.show()

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-01-01 03:40  wechat_jump_game-master\
     文件          44  2018-01-01 03:40  wechat_jump_game-master\.gitignore
     文件           1  2018-01-01 03:40  wechat_jump_game-master\CONTRIBUTING.md
     文件        1065  2018-01-01 03:40  wechat_jump_game-master\LICENSE
     文件        6827  2018-01-01 03:40  wechat_jump_game-master\README.md
     目录           0  2018-01-01 03:40  wechat_jump_game-master\config\
     目录           0  2018-01-01 03:40  wechat_jump_game-master\config\1280x720\
     文件         219  2018-01-01 03:40  wechat_jump_game-master\config\1280x720\config.json
     目录           0  2018-01-01 03:40  wechat_jump_game-master\config\1920x1080\
     文件         219  2018-01-01 03:40  wechat_jump_game-master\config\1920x1080\config.json
     目录           0  2018-01-01 03:40  wechat_jump_game-master\config\2160x1080\
     文件         127  2018-01-01 03:40  wechat_jump_game-master\config\2160x1080\config.json
     目录           0  2018-01-01 03:40  wechat_jump_game-master\config\2560x1440\
     文件         218  2018-01-01 03:40  wechat_jump_game-master\config\2560x1440\config.json
     文件         130  2018-01-01 03:40  wechat_jump_game-master\config\default.json
     目录           0  2018-01-01 03:40  wechat_jump_game-master\config\huawei\
     文件         219  2018-01-01 03:40  wechat_jump_game-master\config\huawei\honor_note8_config.json
     目录           0  2018-01-01 03:40  wechat_jump_game-master\config\iPhone\
     文件         226  2018-01-01 03:40  wechat_jump_game-master\config\iPhone\6_config.json
     文件         215  2018-01-01 03:40  wechat_jump_game-master\config\iPhone\8P_7P_6sP_6P_config.json
     目录           0  2018-01-01 03:40  wechat_jump_game-master\config\mi\
     文件         220  2018-01-01 03:40  wechat_jump_game-master\config\mi\mi5_config.json
     文件         224  2018-01-01 03:40  wechat_jump_game-master\config\mi\mi5x_config.json
     文件         217  2018-01-01 03:40  wechat_jump_game-master\config\mi\mi6_config.json
     文件         220  2018-01-01 03:40  wechat_jump_game-master\config\mi\note2_config.json
     目录           0  2018-01-01 03:40  wechat_jump_game-master\config\samsung\
     文件         124  2018-01-01 03:40  wechat_jump_game-master\config\samsung\s7edge_config.json
     文件         127  2018-01-01 03:40  wechat_jump_game-master\config\samsung\s8.json
     文件           0  2018-01-01 03:40  wechat_jump_game-master\config\samsung\s8在设置里关闭曲面侧屏
     目录           0  2018-01-01 03:40  wechat_jump_game-master\config\smartisan\
     文件         217  2018-01-01 03:40  wechat_jump_game-master\config\smartisan\pro2_config.json
............此处省略118个文件信息

评论

共有 条评论