金铲铲S13双城之战自动拿牌助手

金铲铲S13双城之战自动拿牌助手

基于python,pyautogui和金铲铲自带备战助手实现

B站视频演示效果

shuangcheng.py

python 复制代码
import time

import pyautogui
import datetime

print('请关注您的分辨率,此程序需要配合thumbs_x_y.txt文件同时使用')
print('简介:thumbs_x_y.txt文件')
print('此文件为配置文件,内容一共6行')
print('前5行为金铲铲内置助手大拇指在你电脑上的x坐标')
print('第6行为y坐标,y坐标只有1个,因为5个大拇指都是在同一水平线上的')
print('注意:此文件放在和.exe文件同级目录下,没有此文件,程序无法正常运行')
# 获取屏幕分辨率(宽高) Size(width=1920, height=1080)
screen_width, screen_height = pyautogui.size()
welcome = 'Hello 双城之战!您当前屏幕像素宽度:' + str(screen_width) + '屏幕高度:' + str(screen_height)
pyautogui.alert(welcome)

time.sleep(1)
# 获取雷电模拟器
win = pyautogui.getWindowsWithTitle('雷电模拟器')

if len(win) > 0:
    print('找到雷电模拟器窗口了')
else:
    raise BaseException("没有找到雷电模拟器窗口")
# 将游戏窗口最大化,使窗口处于最前面
win[0].maximize()
win[0].activate()


# 校验坐标要有值 定义一个校验函数
def is_valid_number(value):
    # 检查是否为数字类型(int 或 float)且不是 None
    return isinstance(value, (int, float)) and value is not None


# 检查入参
def check_input_params(x1, x2, x3, x4, x5, y):
    # 校验所有 x 坐标和 y 坐标
    if not all(is_valid_number(x) for x in [x1, x2, x3, x4, x5]):
        raise ValueError("所有 x 坐标都必须是数字且不能为空")

    if not is_valid_number(y):
        raise ValueError("y 坐标必须是数字且不能为空")
    # 5个大拇指坐标,x坐标不同,y坐标一样,都是一条水平线上的
    thumbs_x_y = (
        (x1, y),
        (x2, y),
        (x3, y),
        (x4, y),
        (x5, y)
    )
    return thumbs_x_y


def start(thumbs_x_y):
    # 记录打印日志时间,设置打印等待日志间隔
    now = datetime.datetime.now()
    init_sec = now.second
    while True:
        for index, thumb in enumerate(thumbs_x_y):
            thumb_color = pyautogui.pixel(thumb[0], thumb[1])
            # print(thumb_color[0] > 240, thumb_color[1] > 240, thumb_color[2] > 200)
            # RGB三色
            red = 240 < thumb_color[0]
            green = 240 < thumb_color[1]
            blue = 210 < thumb_color[2]

            # not_white_color 白色背景会影响程序判断,对白色的处理
            if thumb_color[0] == 255 and thumb_color[1] == 255 and thumb_color[2] == 255:
                print('当前屏幕显示背景在5个大拇指的位置有白色,请使用ALT+Tab组合键切出此窗口或关闭程序')
                time.sleep(2)
                continue
            if thumb_color[0] == 245 and thumb_color[1] == 245 and thumb_color[2] == 245:
                print('当前屏幕显示背景在5个大拇指的位置有杂色,请使用ALT+Tab组合键切出此窗口或关闭程序')
                time.sleep(2)
                continue

            if red and green and blue:
                print(index, "真的有true,即将点击", thumb[0], thumb[1])
                # pyautogui.click(thumb[0], thumb[1])
                # 改为模拟键盘按钮
                if index == 0:
                    print('按键1')
                    pyautogui.press('1')
                if index == 1:
                    print('按键2')
                    pyautogui.press('2')
                if index == 2:
                    print('按键3')
                    pyautogui.press('3')
                if index == 3:
                    print('按键4')
                    pyautogui.press('4')
                if index == 4:
                    print('按键5')
                    pyautogui.press('5')

        # 获取当前时间
        now = datetime.datetime.now()
        # 格式化时间为"时:分:秒"
        formatted_time = now.strftime("%H:%M:%S")
        if abs(now.second - init_sec) >= 10:
            # print("当前时间(时:分:秒):", formatted_time)
            print("等待中", formatted_time)
            init_sec = now.second


# 用来遍历的
list_6 = [1, 2, 3, 4, 5, 6]
# x1 = 720
# x2 = 914
# x3 = 1107
# x4 = 1300
# x5 = 1493
# y坐标
# y = 970
x1 = -1
x2 = -1
x3 = -1
x4 = -1
x5 = -1
y = -1
# 打开文件并逐行读取
with open('thumbs_x_y.txt', 'r') as file:
    for i, item in enumerate(list_6):
        line = file.readline()
        # print(line, end='')  # `end=''`用于避免打印额外的换行符
        # print('序号:', i, '值:', item)
        if i == 0:
            x1 = int(line)
        if i == 1:
            x2 = int(line)
        if i == 2:
            x3 = int(line)
        if i == 3:
            x4 = int(line)
        if i == 4:
            x5 = int(line)
        if i == 5:
            y = int(line)

start(check_input_params(x1, x2, x3, x4, x5, y))

配置文件thumbs_x_y.txt,要求和.exe文件同层级目录

thumbs_x_y.txt

bash 复制代码
720
914
1107
1300
1493
970
相关推荐
Hgfdsaqwr1 天前
Django全栈开发入门:构建一个博客系统
jvm·数据库·python
开发者小天1 天前
python中For Loop的用法
java·服务器·python
老百姓懂点AI1 天前
[RAG实战] 向量数据库选型与优化:智能体来了(西南总部)AI agent指挥官的长短期记忆架构设计
python
喵手1 天前
Python爬虫零基础入门【第九章:实战项目教学·第15节】搜索页采集:关键词队列 + 结果去重 + 反爬友好策略!
爬虫·python·爬虫实战·python爬虫工程化实战·零基础python爬虫教学·搜索页采集·关键词队列
Suchadar1 天前
if判断语句——Python
开发语言·python
ʚB҉L҉A҉C҉K҉.҉基҉德҉^҉大1 天前
自动化机器学习(AutoML)库TPOT使用指南
jvm·数据库·python
喵手1 天前
Python爬虫零基础入门【第九章:实战项目教学·第14节】表格型页面采集:多列、多行、跨页(通用表格解析)!
爬虫·python·python爬虫实战·python爬虫工程化实战·python爬虫零基础入门·表格型页面采集·通用表格解析
0思必得01 天前
[Web自动化] 爬虫之API请求
前端·爬虫·python·selenium·自动化
莫问前路漫漫1 天前
WinMerge v2.16.41 中文绿色版深度解析:文件对比与合并的全能工具
java·开发语言·python·jdk·ai编程
木头左1 天前
Backtrader框架下的指数期权备兑策略资金管理实现与风险控制
python