完美国际自动斗兽
import time import pyautogui import cv2 def get_xy(img_model_path): """ 用来判定游戏画面的点击坐标 :param img_model_path:用来检测的图片 :return:以元组形式返回检测到的区域中心的坐标 """ # 将图片截图并且保存 pyautogui.screenshot().save("d:/wan_mei/screenshot.png") # 待读取图像 img = cv2.imread("d:/wan_mei/screenshot.png") # 图像模板 img_terminal = cv2.imread(img_model_path) # 读取模板的高度宽度和通道数 height, width, channel = img_terminal.shape # 使用matchTemplate进行模板匹配(标准平方差匹配) result = cv2.matchTemplate(img, img_terminal, cv2.TM_SQDIFF_NORMED) # 解析出匹配区域的左上角图标 upper_left = cv2.minMaxLoc(result)[2] # 计算出匹配区域右下角图标(左上角坐标加上模板的长宽即可得到) lower_right = (upper_left[0] + width, upper_left[1] + height) # 计算坐标的平均值并将其返回 avg = (int((upper_left[0] + lower_right[0]) / 2), int((upper_left[1] + lower_right[1]) / 2)) return avg def auto_Click(var_avg): pyautogui.click(var_avg[0], var_avg[1], button='left') time.sleep(2) def routine(img_model_path, name): avg = get_xy(img_model_path) print(f"正在点击{name}") time.sleep(1) auto_Click(avg) """押镖""" times=1 def dou_shou_begin(): """到达位置对话""" time.sleep(4) # pyautogui.hotkey('F') routine('d:/wan_mei/start.PNG','开始匹配') time.sleep(0.5) """选择敌方主将""" routine('d:/wan_mei/choose_gernal.PNG','选择敌方主将') time.sleep(0.5) """再次确定""" routine('d:/wan_mei/my_gernal.PNG','选择我的主将') time.sleep(0.5) routine('d:/wan_mei/click_gernal.PNG','点击主将') time.sleep(0.5) routine('d:/wan_mei/choose_1.PNG','选择左') time.sleep(0.5) routine('d:/wan_mei/click_1.PNG','点击左将') time.sleep(0.5) routine('d:/wan_mei/choose_2.PNG','选择右') time.sleep(0.5) routine('d:/wan_mei/click_2.PNG','点击右') time.sleep(0.5) routine('d:/wan_mei/fight.PNG','开始竞技') time.sleep(1) routine('d:/wan_mei/fast.PNG','加速') time.sleep(4) routine('d:/wan_mei/award.PNG', '领取奖励') time.sleep(3) pyautogui.click() time.sleep(3)
随便写着玩的 不一定好用哦