打包exe文件https://pan.baidu.com/s/1LoFeTG7dO3g4tNXNqNsgpg
提取码:y0hp
更新时间:2021/9/30 20:56
更新内容:
21-9-30-1:加入匹配界面截图检测,优化pass点击
参考链接
用python实现对比两张图片的不同(可用于自动化测试用例中)
README
1.python自行配置: pip install pyautogui pip install pillow 2.使用新版mumu模拟器,默认大小位置 3.右键管理员运行TNT.bat 4.确认开始前屏幕留出开始游戏按钮 按键位置 1.开始键 1530 650 2.buff 700 750 3.攻击 1530 800 4.奖励 960 628 5.pass 960 300
TNT.py
# 安装python库命令 # pip install pyautogui # 浪速之星 qq2322739526 # 2021.9.30 import pyautogui import time from PIL import ImageGrab from PIL import Image import math import operator from functools import reduce def image_contrast(img1, img2): image1 = Image.open(img1) image2 = Image.open(img2) h1 = image1.histogram() h2 = image2.histogram() result = math.sqrt(reduce(operator.add, list(map(lambda a,b: (a-b)**2, h1, h2)))/len(h1)) return result def click(px,py): x = px y = py pyautogui.click( x, # x像素坐标 y, # y轴像素坐标 clicks=1, # 点击次数 interval=0.1, # 点击之间的间隔 button='left', # 'left', 'middle', 'right' 对应鼠标 左 中 右或者取值(1, 2, or 3) duration=0.0, tween=pyautogui.linear) def check(px,py): x, y = pyautogui.position() # 获取当前鼠标位置 if x != px or y != py: b = input("检测到鼠标移动,是否回到位置继续连点?(y/n)") if b == "y": click(1530,650) x = px y = py return 0 else: return 1 else: return 0 if __name__ == '__main__': print("-" * 30 + "nTNT挂机脚本,支持新版MuMu界面n刷镜片:推荐禁忌血杯,空装扮n刷经验:推荐荆棘斗篷,满装扮n" + "-" * 30) a = input("是否开始挂机(确保进入匹配界面)?n(1:镜片/2:经验/n:退出)") # 刷镜片 if a == "1": click(1530,800) n = 0 while True: # 4.奖励 960 628 click(960,628) print('4.领取奖励') time.sleep(1) n += check(960,628) if not n == 0: break # 界面比对 im = ImageGrab.grab() box = (600,105,1680,900) im = im.crop(box) im.save('1.png','png') df = image_contrast('1.png','s.png') print('界面比对:',df) if df < 100: # 1.开始键 1530 650 click(1530,650) print('1.开始匹配/等待15秒') time.sleep(15) n += check(1530,650) if not n == 0: break # 2.buff 700 750 click(700,750) print('2.加buff') time.sleep(0.5) n += check(700,750) if not n == 0: break click(700,750) print('2.加buff') time.sleep(1) n += check(700,750) if not n == 0: break # 3.攻击 1530 800 click(1530,800) print('3.攻击投弹') time.sleep(4) n += check(1530,800) if not n == 0: break # 刷经验 elif a == "2": click(1530,800) n = 0 while True: # 4.奖励 960 628(保留) click(960,628) print('4.领取奖励') time.sleep(1) n += check(960,628) if not n == 0: break # 界面比对 im = ImageGrab.grab() box = (600,105,1680,900) im = im.crop(box) im.save('1.png','png') df = image_contrast('1.png','s.png') print('界面比对:',df) if df > 500: # 5.pass 960 300 click(960,300) print('5.跳过回合') time.sleep(4) n += check(960,300) if not n == 0: break elif df < 100: # 1.开始键 1530 650 click(1530,650) print('1.开始匹配/等待15秒') time.sleep(15) n += check(1530,650) if not n == 0: break # 生成匹配界面截图(测试用) elif a == "s": click(1530,800) im = ImageGrab.grab() box = (600,105,1680,900) im = im.crop(box) im.save('s.png','png') print('生成对比图s.png') print("连点结束,回车退出") temps = input("")
TNT.bat(自己改脚本路径)
cd C:Usersdell桌面TNT python TNT.py pause