跳一跳 手动 外挂 辅助 python

#coding:utf-8

import os
import subprocess
import random
import math
from time import sleep
from PIL import Image, ImageTk,ImageFile

try:
    # for Python2
    import Tkinter as tk   ## notice capitalized T in Tkinter
except ImportError:
    # for Python3
    import tkinter as tk   ## notice lowercase 't' in tkinter here



press_coefficient=0.24#按压时间参数
ImageFile.LOAD_TRUNCATED_IMAGES = True
isFirst=True#首次点击


def execute_command(cmd):
    #执行cmd命令行
    s = subprocess.run(cmd)
    return s.returncode


def jump(time):
    cmd = 'adb shell input swipe {x1} {y1} {x2} {y2} {duration}'.format(
        x1=int(random.uniform(170 - 50, 170 + 50)),
        y1=int(random.uniform(150 - 50, 150 + 50)),
        x2=int(random.uniform(160 - 50, 160 + 50)),
        y2=int(random.uniform(180 - 50, 180 + 50)),
        #计算起跳时长
        duration=int(random.uniform(time - 10, time + 10)))
    print("正在起跳...")
    execute_command(cmd)


def screen():
    print("正在截屏...")
    execute_command('adb shell screencap -p /sdcard/jump.png')
    print("正在上传图片...")
    execute_command('adb pull /sdcard/jump.png D:\\jump.png')


def calcDistance(x1, x2, y1, y2):
    return math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))


def callBack(event):
    '''''
    点击鼠标后续操作
    '''

    global isFirst,preX,preY,endX,endY,label,tk_image,pil_image,press_coefficient

    #判断是否是第一次点击
    if isFirst:
        #从点击事件获取起跳坐标
        preX = event.x_root
        preY = event.y_root
        isFirst= False
    else:
        #从点击事件获取终点坐标
        endX = event.x_root
        endY = event.y_root

        print("点击坐标:")
        print(endX, preX, endY, preY)
        distance = calcDistance(endX,preX,endY,preY)#计算距离
        time = (int)(distance /press_coefficient )#计算时间
        jump(time)#长按起跳


        isFirst = True
        print("跳跃距离:" + str(distance) + ",按压时长:" + str(time))

        #刷新图片
        try:
            sleep(1)
            screen()
            pil_image = get_screen()
            tk_image = tran_Pic(pil_image)
            label.configure(image=tk_image, width=w_box, height=h_box)
            print("请在窗口单击小人跳跃的起点和终点")
        except ():
            print()





def resize(w, h, w_box, h_box, pil_image):
    '''''
    对一个pil_image对象进行缩放,让它在一个矩形框内,还能保持比例
    '''

    f1 = 1.0 * w_box / w  # 1.0 forces float division in Python2
    f2 = 1.0 * h_box / h
    factor = min([f1, f2])
    # print(f1, f2, factor) # test
    # use best down-sizing filter
    width = int(w * factor)
    height = int(h * factor)
    return pil_image.resize((width, height), Image.ANTIALIAS)


def get_screen():
    global screen_pic
    filePath = "D:\\jump.png"
    if os.path.isfile(filePath):
        screen_pic = Image.open("D:\\jump.png")
        return screen_pic


def WeChatJump():
    global w_box, h_box, tk_image, label,pil_image
    print("欢迎使用跳一跳外挂,请打开跳一跳并点击开始游戏")
    print("使用方法:请在窗口单击小人跳跃的起点和终点")
    print("提示:如果跳跃不准确,请修改按压时间参数press_coefficient")
    root = tk.Tk()
    root.title("跳一跳手动外挂")
    screen()
    pil_image=get_screen()
    tran_Pic(pil_image)
    # Label: 这个小工具,就是个显示框,小窗口,把图像大小显示到指定的显示框
    label = tk.Label(root, image=tk_image, width=w_box, height=h_box)
    label.pack()  # 把标签放入窗口
    label.bind("<Button-1>", callBack)  # 绑定单击左键事件
    root.mainloop()  # 进入消息循环


def tran_Pic(pil_image):
    #w_box, h_box,图片长宽
    #要显示的图片tk_image 图片
    global w_box, h_box, tk_image
    w, h = pil_image.size
    # 缩小图片
    w_box = w / 3
    h_box = h / 3
    # 缩放图像让它保持比例,同时限制在一个矩形框范围内
    pil_image_resized = resize(w, h, w_box, h_box, pil_image)
    # 把PIL图像对象转变为Tkinter的PhotoImage对象
    tk_image = ImageTk.PhotoImage(pil_image_resized)
    return tk_image


WeChatJump()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值