记一次python小功能实现,以yys的“痴”,“巫女大蛇”为例,实现一定显示场景下的重复点击功能(识图)

周末闲暇,不想去玩,也不想太正式的敲代码,在和“蟹老板”的聊天中,发现重复点击的功能可以做一下,既然都是程序员了,为啥还要当“工具人”呢?(手动滑稽),说不定以后接单啥的,提前适应下下,哈哈哈—挂机yys偷个懒,顺便接点业务,欢迎骚扰,Q(532852033),添加时备注:“csdn”+“来意”

感谢:https://blog.csdn.net/qq_40125655/article/details/78996375?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase

该博主的思路,本次实现方式python的random,pyautogui库(胶水语言还是厉害的),目前打开方式ideal

功能需求,根据屏幕内不同的显示,有顺序的进行点击,在几次点击之后进行循环。(防止程序后台点击检测,我在点击区域截取了10个点,用随机数判断点击图片)

代码层次如下:
记一次python小功能实现,以yys的“痴”,“巫女大蛇”为例,实现一定显示场景下的重复点击功能(识图)_第1张图片
.py内容如下

import pyautogui,time
import random
import string

pyautogui.FAILSAFE = True
'''PyAutoGUI提供了一个保护措施。当pyautogui.FAILSAFE = True时,如果把鼠标光标在屏幕左上角,
PyAutoGUI函数就会产生pyautogui.FailSafeException异常,用于在程序失控时退出'''
time.sleep(2)
def get_point(picture):
    '''精确匹配某个按钮的位置;通过传入图片获取图片在屏幕上的定位,一旦获取到值则退出,否则继续尝试'''
    picture = './img/' + picture
    '''point = pyautogui.locateCenterOnScreen(picture)
    count = 1
    while count > 0:
        return point'''
    count = 1
    while count > 0:
        point = pyautogui.locateCenterOnScreen(picture)
        if point is not None:
            return point
        else:
            count -= 1
def get_range(picture):
    '''用模糊匹配得到某个按钮的大概位置,一般是在那种点击屏幕任意位置的情况,或只需要知道某个按钮在不在当前屏幕的情况使用
     要动的图片采用模糊匹配,否则精确匹配的话,图片一直在动像素也在变化,就不能定位到了'''
    picture = './img/' + picture
    '''range = pyautogui.locateCenterOnScreen(picture, grayscale=True, confidence=0.5)
    count = 1
    while count > 0 :
        return range'''
    count = 1
    while count > 0:
        range = pyautogui.locateCenterOnScreen(picture, grayscale=True, confidence=0.5)
        if range is not None:
            return range
        else:
            count -= 1
def click_button(picture,accurate=True):
    '''点击按钮的函数,默认精确度为True,即默认为精确点击,如果accurate=False,则为模糊点击,用于动态图形按钮'''
    if accurate==True:
        action = get_point(picture)
    else:
        action = get_range(picture)
    if action is not None:
        pyautogui.click(action,duration=0.5)

def cycle_fight():
    '''用户循环重复的战斗场景,如果刷觉醒材料,刷御魂'''
    while True:
        click_button('tiaozhan_chi.png')
        click_button('gou.png')
        click_button("tiaozhan_yuhun.png")
        click_button("yuhun_shengli.png")
        click_button("yuhun_shengli_baoxiang.png")

def cycle_chi():
    '''用户循环重复的战斗场景,如果刷觉醒材料,刷御魂'''
    while True:
        random_sj = str(random.randint(0,9))
        temp1 = 'tiaozhan_chi/tiaozhan_chi_'+random_sj+'.png'
        click_button(temp1)
        temp2 = "yuhun_shengli_baoxiang/yuhun_shengli_baoxiang_"+random_sj+".png"
        click_button(temp2)
def cycle_yuhun():
    '''用户循环重复的战斗场景,如果刷觉醒材料,刷御魂'''
    while True:
        random_sj = str(random.randint(0,9))
        temp1 = 'yuhun_tiaozhan/yuhun_tiaozhan_'+random_sj+'.png'
        click_button(temp1)
        temp2 = 'yuhun_shengli/'+random_sj+'.png'
        click_button(temp2)
        temp3 = 'yuhun_shengli_baoxiang/yuhun_shengli_baoxiang_'+random_sj+'.png'
        click_button(temp3)
        click_button(temp3)

def cycle_tupo():
    '''用户循环重复的战斗场景,如果刷觉醒材料,刷御魂'''
    while True:
        click_button("tupo_start.png")
        click_button("tupo_attack.png")
        click_button("tupo_chaji.png")
        click_button("tupo_baoxiang.png")
def hello():
    '''用户循环重复的战斗场景,如果刷觉醒材料,刷御魂'''
    print("test.is Success")

def dingzhi_yuhun():
    '''点击挑战'''
    random_sj = str(random.randint(0,9))
    temp1 = './img/yuhun_tiaozhan/yuhun_tiaozhan_'+random_sj+'.png'
    '''picture1 = pyautogui.locateCenterOnScreen(temp1)'''
    point = search_picture_return_point(temp1)
    if point is not None :
        pyautogui.click(point)

    '''点击胜利1'''
    temp2 = './img/yuhun_shengli/'+random_sj+'.png'
    '''picture2 = pyautogui.locateCenterOnScreen(temp2)'''
    point = search_picture_return_point(temp2)
    if point is not None :
        pyautogui.click(point)

    '''点击胜利2'''
    '''temp3 = './img/yuhun_shengli/'+random_sj+'.png'
    point3 = pyautogui.locateCenterOnScreen(temp3)
    pyautogui.click(point3)'''

    '''点击宝箱1'''
    temp4 = './img/yuhun_shengli_baoxiang/yuhun_shengli_baoxiang_'+random_sj+'.png'
    '''picture4 = pyautogui.locateCenterOnScreen(temp4)'''
    point = search_picture_return_point(temp4)
    if point is not None :
        pyautogui.click(point)

    '''点击宝箱2'''
    '''temp5 = './img/yuhun_shengli_baoxiang/yuhun_shengli_baoxiang_'+random_sj+'.png'
    point5 = pyautogui.locateCenterOnScreen(temp5)
    pyautogui.click(point5)'''
def click_dingzhi_yuhun() :
    while True :
        dingzhi_yuhun()

def dingzhi_chi() :
    '''点击挑战'''
    random_sj = str(random.randint(0,9))
    temp1 = './img/tiaozhan_chi/tiaozhan_chi_'+random_sj+'.png'
    if search_picture_return_point(temp1) is not None :
        pyautogui.click(search_picture_return_point(temp1))

    '''点击宝箱1'''
    temp4 = './img/yuhun_shengli_baoxiang/yuhun_shengli_baoxiang_'+random_sj+'.png'
    if search_picture_return_point(temp4) is not None :
        pyautogui.click(search_picture_return_point(temp4))
def click_dingzhi_chi():
    while True:
        dingzhi_chi()
def search_picture_return_point(picture):
    point = pyautogui.locateCenterOnScreen(picture)
    return point
'''
痴:click_dingzhi_chi
御魂:click_dingzhi_yuhun
hello()
'''

click_dingzhi_yuhun()

第一次发表csdn,第一次编写除了上班之外的需求,哈哈,精神小伙就是要不断的尝试,不断的探索,不然枉费青春年华(滑稽)

你可能感兴趣的:(yys)