<pre>#euraxluo 5.15
#obj_1
#跳一跳的外挂
from PIL import Image
import subprocess
import time
import random
import os
def jump(distance):
press_time = distance*2.353
press_time = max(press_time,200)
press_time = int(press_time)
point = (random.randint(500,600),random.randint(1000,1200))
cmd = 'adb shell input swipe {x1} {y1} {x2} {y2} {time}'.format(
x1=point[0],
y1=point[1],
x2=point[0]+random.randint(1,5),
y2=point[1]+random.randint(1,5),
time = press_time
)
os.system(cmd)
return press_time
def get_screenshot():
#jietu,baocun jump.png
#调用os模块
process=subprocess.Popen('adb shell screencap -p',shell=True,stdout=subprocess.PIPE)
screenshot = process.stdout.read()#读取图片信息
screenshot = screenshot.replace(b'\r\n',b'\n')#去除干扰信息
with open('jump.png','wb') as f:#保存为图片
f.write(screenshot)
def find_a_and_b(img_path):#寻找起点和终点
img = Image.open(img_path)
w,h = img.size #图片尺寸
img_pixel = img.load() #图片的像素矩阵
start_p = None
for i in range(int(h/5),int(h*2/3),50): #以50为步长扫描
first_pixel = img_pixel[0,i]
for j in range(1,w):#循环查找,如果遇到非纯色。为棋盘
pixel = img_pixel[j,i]
if pixel[0] != first_pixel[0] or pixel[1] !=first_pixel[1] or pixel[2] !=first_pixel[2]:#确定棋盘
start_p = i - 50
break
if start_p:
break
#找到棋子
left = 0
right = 0
a_point_y_max = 0
bz = True
for i in range(start_p,int(h*2/3)):#限制棋子的扫描范围
for j in range(int(w/9),int(w*8/9),10):#限制棋子的扫描范围 去掉边界1/9
pixel = img_pixel[j,i]
if (50<pixel[0]<60)and(53<pixel[1]<63)and(95<pixel[2]<110):
print(pixel[0],pixel[1],pixel[2])
if bz:
left = j
bz = False
right = j
a_point_y_max = max(i,a_point_y_max)#a_point 的纵坐标
a_point_x = (left + right) // 2 #a_point 的横坐标
a_point_y = a_point_y_max - 10 #根据不同分辨路确定
#找棋盘
#限制棋盘的扫描范围
if a_point_x < w/2: #棋子在左边
b_start_x = a_point_x + 50
b_end_x = 690
else:
b_start_x = 30
b_end_x = a_point_x - 50
#找棋盘的顶点
for i in range(start_p,start_p+200):#y轴大致位置循环至下200px
first_pixel = img_pixel[0,i]#背景色的rgb
for j in range(b_start_x,b_end_x,5):#棋子的边界坐标循环至边界
pixel = img_pixel[j,i]
if abs(pixel[0] - first_pixel[0])+abs(pixel[1] - first_pixel[1])+abs(pixel[2] - first_pixel[2])>15:
if bz:
left = j
right = j
bz = False
else:
right = j
if not bz:
break
b_x = (720-(right+left)//2)
b_top = img_pixel[b_x,i+30]
#从定点往下找
for k in range(i+250,i,-1):
pixel = img_pixel[b_x,k]
if abs(pixel[0] - first_pixel[0]) + abs(pixel[1] - first_pixel[1]) + abs(pixel[2] - first_pixel[2]) < 12:
break
b_y=(i+k)//2+80
return (a_point_x,a_point_y),(b_x+20,b_y)
def run():
oper = input('请连接手机,确定开始?y/n')
if oper != 'y':
exit('结束')
while True:
# screenshout
get_screenshot() # 获取截图
a,b=find_a_and_b('jump.png')
distance = ((a[0]-b[0])**2+(a[1]-b[1])**2)**0.5#计算距离
jump(distance)#按压
time.sleep(random.randrange(1,2))#随机休眠
if __name__ == '__main__':
run()
# find_a_and_b('jump.png')</pre>