资深会员
- UID
- 4351408
- 积分
- 3193
- 可用积分
- 点
- 威望
- 个
- 水滴
- 滴
- 存在感
- 点
- NB
- 点
- 豆币
- 点
- 帖子
- 主题
- 好友
- 精华
- APP积分
- 点
|
本帖最后由 suifeng0917 于 2024-11-14 22:28 编辑
自11.06更新之后DNF他会改变游戏的颜色,有很多自动拼图用不了了,我自己用python重做了一个
操作步骤:先打上补丁,上游戏,打开街机中心192片拼图,管理员启动软件,等一两秒钟时间按F10,如果第一轮没有反应,等他跑完192次循环就正常了
软件是通过PyInstaller打包的,
下载地址:https://share.weiyun.com/rSzYgrea 密码:e9snrp
游戏设置:
屏幕分辨率 1920 x 1080
游戏分辨率 16:9 1067x600
颜色设置 全0
下面是代码部分(通过GPT写的,有问题大佬请轻点喷)
—————————————————————————————————————————————
{window.title} 激活成功!")
def capture_color_coordinates(region=(218, 46, 857, 405)):
"""截取区域截图,提取颜色坐标,返回颜色字典"""
screenshot = ImageGrab.grab(bbox=region)
pixels = screenshot.load()
color_coords = {}
# 遍历截图区域内的每个像素并存储颜色和坐标
for y in range(screenshot.height):
for x in range(screenshot.width):
color = pixels[x, y]
hex_color = "#{:02x}{:02x}{:02x}".format(color[0], color[1], color[2])
if hex_color not in color_coords:
color_coords[hex_color] = (x + region[0], y + region[1])
return color_coords
def execute_color_match_and_click(color_coords, target_coords=[(270, 490), (290, 500)]):
"""根据提供的颜色字典,匹配颜色并执行点击操作"""
# 1. 获取目标坐标的颜色
target_colors = []
for coord in target_coords:
x, y = coord
try:
color = pyautogui.screenshot(region=(x, y, 1, 1)).getpixel((0, 0))
hex_color = "#{:02x}{:02x}{:02x}".format(color[0], color[1], color[2])
target_colors.append((coord, hex_color))
except Exception as e:
pass
# 2. 颜色匹配
matched_coords = {}
for coord, color in target_colors:
if color in color_coords:
matched_coords[coord] = color_coords[color]
# 3. 检查是否有匹配坐标
matched_x = matched_coords.get(target_coords[0])
matched_y = matched_coords.get(target_coords[1])
if matched_x is None or matched_y is None:
return
# 执行鼠标点击操作
fixed_target_coords = (270, 488)
pyautogui.moveTo(*fixed_target_coords)
time.sleep(0.005)
mouse = Controller()
mouse.press(Button.left)
time.sleep(0.005)
mouse.release(Button.left)
time.sleep(0.005)
# 增加5的偏移量
offset_x = 5
offset_y = 5
pyautogui.moveTo(matched_x[0] + offset_x, matched_y[1] + offset_y)
time.sleep(0.005)
mouse.press(Button.left)
time.sleep(0.005)
mouse.release(Button.left)
time.sleep(0.005) # 每次循环的等待时间
def main_loop():
"""主循环,用于启动和停止任务"""
# 手动调用窗口激活函数
activate_game_window()
iterations = 192
running = False # 初始时任务为未运行状态
# 只截取一次区域截图并提取颜色坐标
color_coords = capture_color_coordinates()
while True:
if keyboard.is_pressed("F10") and not running: # F10 键按下时开始运行
running = True
for i in range(iterations):
if keyboard.is_pressed("F12"): # 如果按下 F12 键则停止程序
print("程序结束")
sys.exit() # 退出整个程序
start_time = time.time() # 记录循环开始时间
execute_color_match_and_click(color_coords) # 去掉 iterations 参数
end_time = time.time() # 记录循环结束时间
elapsed_time = end_time - start_time # 计算耗时
print(f"第 {i + 1} 次循环,运行时间: {elapsed_time:.4f} 秒")
# 循环 192 次后执行额外的点击操作
fixed_target_coords1 = (535, 540)
pyautogui.moveTo(*fixed_target_coords1)
time.sleep(0.005)
mouse = Controller()
mouse.press(Button.left)
time.sleep(0.005)
mouse.release(Button.left)
time.sleep(0.005)
# 再次点击
pyautogui.moveTo(*fixed_target_coords1)
time.sleep(0.005)
mouse.press(Button.left)
time.sleep(0.005)
mouse.release(Button.left)
print(f"点击了固定坐标: {fixed_target_coords1}")
# 完成后重新调用 capture_color_coordinates 继续开始下一轮
print("重新开始新一轮颜色捕捉...")
color_coords = capture_color_coordinates()
# 任务已在运行时,不再等待 F10
elif running:
# 当任务在运行时,程序继续执行新的循环
for i in range(iterations):
if keyboard.is_pressed("F12"): # 如果按下 F12 键则停止程序
print("程序结束")
sys.exit() # 退出整个程序
start_time = time.time() # 记录循环开始时间
execute_color_match_and_click(color_coords) # 去掉 iterations 参数
end_time = time.time() # 记录循环结束时间
elapsed_time = end_time - start_time # 计算耗时
print(f"第 {i + 1} 次循环,运行时间: {elapsed_time:.4f} 秒")
# 循环 192 次后执行额外的点击操作
fixed_target_coords1 = (535, 540)
pyautogui.moveTo(*fixed_target_coords1)
time.sleep(0.005)
mouse = Controller()
mouse.press(Button.left)
time.sleep(0.005)
mouse.release(Button.left)
time.sleep(0.005)
# 再次点击
pyautogui.moveTo(*fixed_target_coords1)
time.sleep(0.005)
mouse.press(Button.left)
time.sleep(0.005)
mouse.release(Button.left)
print(f"点击了固定坐标: {fixed_target_coords1}")
# 完成后重新调用 capture_color_coordinates 继续开始下一轮
print("重新开始新一轮颜色捕捉...")
color_coords = capture_color_coordinates()
time.sleep(0.1) # 减少CPU占用
if __name__ == "__main__":
main_loop() |
|