欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

基于与yautogui 多进程 刷关

程序员文章站 2022-03-15 15:01:14
# -*- coding: utf-8 -*-"""Created on 12 9 4 07:46:57 2020@author: 孤王WSJ"""import win32gui,time,pyautogui,cv2import win32com.clientfrom PyQt5.QtWidgets import QApplicationimport sys,osfrom PIL import Imageimport numpy as npfrom multiprocessing...
# -*- coding: utf-8 -*-
"""
Created on 12 9  4 07:46:57 2020

@author: 孤王WSJ
"""

import win32gui,time,pyautogui,cv2
import win32com.client
from PyQt5.QtWidgets import QApplication
import sys,os
from PIL import Image
import numpy as np
from multiprocessing import Process,Queue,Manager
from multiprocessing.sharedctypes import Value

# 自动关机
def shutdown():
    os.system('shutdown -s -f -t 30')
    time.sleep(5)

# 保存数据
def save_data(L):
    s = ''
    for i in L:
        s += ' '+str(i)+' '
    with open('每日刷关数据.txt','a+') as w:
        w.write(s+'\n')
        w.close()


class GameAssist:
    
    def __init__(self,classname,wdname):
        """初始化"""
        
        self.shell = win32com.client.Dispatch("WScript.Shell")
        
        # 获取窗口句柄
        self.hwnd = win32gui.FindWindow(classname,wdname)
            
        if not self.hwnd:
            print("窗口找不到,请确认窗口句柄名称:【%s】" % wdname)
            exit()
            
        #窗口显示最前化
        self.SetAsForegroundWindow()
        win32gui.SetActiveWindow(self.hwnd)
        
        # 使得分辨率为1980x1080
        self.get_screen()


        
    def SetAsForegroundWindow(self):
        #发送ALT键,ALT键使用&号表示
        self.shell.SendKeys('&')
        win32gui.SetForegroundWindow(self.hwnd)

                                   
    # 向左上跳
    def aw(self,t=0.2):
        pyautogui.keyDown('w')
        pyautogui.keyUp('w')
        pyautogui.keyDown('a')
        time.sleep(t)
        pyautogui.keyUp('a')

   
    # 回到主页面
    def back(self,M=True,data=None):
        """
        M 为True,表示为过关,默认
        """
        time.sleep(0.2)
        B = self.get_position('G_jm/xitong.jpg',img2='back_i.jpg')
        pyautogui.leftClick(B[0], B[1])
        
        time.sleep(0.2)
        B = self.get_position('G_jm/tuichu.jpg',img2='back_i.jpg')
        pyautogui.leftClick(B[0], B[1])
        time.sleep(0.2)
        B = self.get_position('G_jm/queding.jpg',img2='back_i.jpg')
        pyautogui.leftClick(B[0], B[1])
        time.sleep(0.2)
        B = self.get_position('P_xtjm/tuichu.jpg',img2='back_i.jpg')
        if M is True:
            time.sleep(2.5)
        pyautogui.leftClick(B[0], B[1])
        time.sleep(0.6)
        pyautogui.leftClick(B[0], B[1])
        if type(data)==type(None):
            pass
        else:
            data['is_F'] = 'True'
        return True
        
   
    def click(self,img='',img2='123.jpg',t_=0):
        '''
        点击图像
        '''
        A = self.get_position(img1=img,img2=img2)
        x = A[0]
        y = A[1]
        pyautogui.moveTo(x,y)
        time.sleep(t_)
        pyautogui.click(x,y,)
  
                      
    # 判断是否死亡
    def death(self):
        if self.is_sim('G_jm/siwang.jpg',img2='120.jpg') is not True:
            return False
        time.sleep(3)
        self.click('G_jm/quxiao.jpg',img2='120.jpg')
        time.sleep(0.2)
        return True

    def death_dy(self, list_=['bg','xy','zsh'],data=None):
        """
        list_ 接受要检查过关时是否有亲密度大于9000的队友死亡,若有则复活
        list_ = ['bg','xy'] 默认不包括藏师
        """
        for i in list_:
            i = 'G_jm/death_'+i+'.jpg'
            d_is_dead = self.search_rgb(i)

            if d_is_dead>0.6:
                self.keydown('v',0.5)
                print(i,'已死亡',d_is_dead)
                print('已复活')
                return None
        data['is_D'] = 'True'



    # 向右上跳
    def dw(self,t=0.2):
        pyautogui.keyDown('w')
        pyautogui.keyUp('w')
        pyautogui.keyDown('d')
        time.sleep(t)
        pyautogui.keyUp('d')
 
    
    # 无尽模式,为42关,不进行清包处理
    def endless(self):
        if time.ctime()[0] == 'S':
            m = 6
        else:
            m = 3
        while m>0:            
            self.get_in('G_42.jpg','M_wj.jpg')
            i = 1  
            while True:
                while self.is_sim('G_jm/yi_jr.jpg') is not True:
                    continue
                time.sleep(0.4)
                self.keydown('d',13)
                if self.death() is True:
                    break
                # 每三关点击一次
                if i%3==0:
                    while self.is_sim('G_jm/queding.jpg') is not True:
                        continue
                    pyautogui.click(500,500)
                    time.sleep(0.5)
                    pyautogui.click(500,500)
                    time.sleep(0.5)
                
                while self.is_sim('G_jm/wj_tg.jpg') is not True:
                    continue
                if i==18:
                    self.back(M=False)
                    break
                self.keydown('f',0.4)
                
                i = i+1                        
            m = m-1
        exit()
    
    def finish(self,G_n='',q1=Queue(),q2=Queue(),
               death_dy=['bg','xy'],data=None,t=1e10):
        '''
        判断是否完成关卡
        ----------
        G_n : 关卡名. The default is ''.
        q1 : 队列,用来停止相关进程. The default is Queue().
        q2 : 队列,用来停止相关进程. The default is Queue().
        '''
        t0 = time.time()
        if G_n=='G_90_2.jpg':
            G_n = 'G_jm/jt_90_2.jpg'
            while self.is_sim(G_n,img2='back_i.jpg') is not True:
                if q1.empty() is False:
                    return None
                pyautogui.keyDown('a')
                if t<time.time()-t0 : break
            q2.put('finish')
            pyautogui.keyUp('a')
            self.keydown('d',15)                    
        
        elif G_n=='G_88.jpg':
            G_n = 'G_jm/jt_88.jpg'
            while self.is_sim(G_n,img2='back_i.jpg') is not True:
                if q1.empty() is False:
                    return None
                if t<time.time()-t0 : break
            q2.put('finish')
            time.sleep(1)
            self.keydown('a',3)
            time.sleep(1)
            self.keydown('d',12)
        
        elif G_n=='G_89.jpg':
            G_n = 'G_jm/jt_89.jpg'
            while self.is_sim(G_n,img2='back_i.jpg') is not True:
                if q1.empty() is False:
                    return None
                if t<time.time()-t0 : break
            q2.put('finish')
            time.sleep(3)
            self.keydown('d',10)
        
        elif G_n=='G_90.jpg':
            G_n = 'G_jm/jt_90.jpg'
            while self.is_sim(G_n,img2='back_i.jpg') is not True:
                if q1.empty() is False:
                    return None
                if t<time.time()-t0 : break
            q2.put('finish')
            time.sleep(3)
            self.keydown('d',3)
            time.sleep(1)
            self.dw()
            time.sleep(1)
            self.keydown('d',0.44)
            time.sleep(0.5)
            self.aw()
            time.sleep(0.2)
            self.keydown('a',1.45)
            time.sleep(0.2)
            self.keydown('d',1.41)
            self.dw()
            time.sleep(0.2)
            self.dw()
            time.sleep(0.2)
            self.keydown('d',2.62)
            self.keydown('a',2.22)
            self.keydown('d',5)
        
        elif G_n=='G_91.jpg':
            G_n = 'G_jm/jt_91.jpg'
            while self.is_sim(G_n,img2='back_i.jpg') is not True:
                if self.is_sim('G_jm/chj_shl_91.jpg',img2='96_2.jpg',s=0.95)\
                    is True:
                    print('遇到超级首领')
                    q2.put('finish')
                    self.keydown('d',4.8)
                    time.sleep(0.2)
                    pyautogui.moveTo(572,580)
                    self.keydown('f',0.2)
                    self.keydown('d',2)
                    time.sleep(0.15)
                    self.keydown('a',2.3)
                    self.keydown('d',6.5)
                    self.death_dy(death_dy,data)
                    data['is_F'] = 'True'
                    self.back(False,data)
                    
                    return True
                if q1.empty() is False:
                    
                    return None
                if t<time.time()-t0 : break
            q2.put('finish')
            time.sleep(3)
            self.keydown('d',4.8)
            self.keydown('d',3.3)

        elif G_n=='G_92.jpg':
            G_n = 'G_jm/jt_92.jpg'
            while self.is_sim(G_n,img2='back_i.jpg',s=0.91) is not True:
                if q1.empty() is False:
                    return None
                if t<time.time()-t0 : break
            q2.put('finish')
            self.keydown('a',10)
            pyautogui.moveTo(337,779)
            self.keydown('f',0.1)
            self.keydown('a',3)
            self.keydown('d',2)
            self.dw()
            self.keydown('d',10)
            
        elif G_n=='G_93.jpg':
            G_n = 'G_jm/jt_93.jpg'
            while self.is_sim(G_n,img2='back_i.jpg',s=0.85) is not True:
                if q1.empty() is False:
                    return None
                if t<time.time()-t0 : break
            q2.put('finish')
            time.sleep(1)
            pyautogui.moveTo(1423,430)
            self.keydown('f',0.1)
            self.keydown('d',7)
            self.keydown('a', 11)
        
        elif G_n=='G_94.jpg':
            G_n = 'G_jm/jt_94.jpg'
            
            while self.is_sim(G_n,img2='back_i.jpg') is not True:
                if q1.empty() is False:
                    return None
                if t<time.time()-t0 : break
            
            q2.put('finish')
            self.keydown('e',0.2)
            self.keydown('e',0.2)
            time.sleep(0.3)
            self.keydown('d',3.1)
            time.sleep(0.3)
            self.dw()
            time.sleep(0.2)
            self.keydown('d',2.5)
            self.keydown('a',4.5)
            self.keydown('d',8)
            
        elif G_n=='G_95.jpg':
            G_n = 'G_jm/jt_95.jpg'
            while self.is_sim(G_n,img2='back_i.jpg') is not True:
                if q1.empty() is False:
                    return None
                if t<time.time()-t0 : break
            q2.put('finish')
            time.sleep(3.3)
            self.dw()

            self.keydown('d',10)
            self.keydown('a',13)
        
        elif G_n=='G_96.jpg':
            G_n = 'G_jm/jt_96.jpg'
            while self.is_sim(G_n,img2='back_i.jpg') is not True:
                if self.is_sim('G_jm/chj_shl.jpg',img2='96_2.jpg',s=0.8)\
                    is True:
                    print('遇到超级首领')
                    
                    q2.put('finish')
                    pyautogui.moveTo(1600,1000)
                    self.keydown('f',0.2)
                    self.keydown('a',4)
                    self.back(M=False,data=data)
                    return True
                if q1.empty() is False:
                    return None
                if t<time.time()-t0 : break
            q2.put('finish')
            
            pyautogui.moveTo(1600,1000)
            self.keydown('f',0.2)
            self.keydown('a',4)
            
        elif G_n=='G_97.jpg':
            G_n = 'G_jm/jt_97.jpg'
            while self.is_sim(G_n,img2='back_i.jpg') is not True:
                if q1.empty() is False:
                    return None
                if t<time.time()-t0 : break
            q2.put('finish')
            time.sleep(2)
            self.keydown('d',7)
            
        elif G_n=='G_98_2.jpg':
            G_n = 'G_jm/jt_98_2.jpg'
            while self.is_sim(G_n,img2='back_i.jpg') is not True:
                if q1.empty() is False:
                    return None
                if t<time.time()-t0 : break
            q2.put('finish')
            time.sleep(2)
            self.keydown('a',8)
            time.sleep(0.2)
            pyautogui.moveTo(1429,322)
            self.keydown('f',0.2)
            self.keydown('d',8)
            self.keydown('a',5)
            
            
        elif G_n=='G_98.jpg':
            G_n = 'G_jm/jt_98.jpg'
            while self.is_sim(G_n,img2='back_i.jpg') is not True:
                if q1.empty() is False:
                    return None
                if t<time.time()-t0 : break
            q2.put('finish')
            time.sleep(1)
            self.keydown('d',5)
            self.keydown('w',0.2)
            self.keydown('a',5)

        else:
            print('请增加 %s函数'%G_n)
            
        self.death_dy(death_dy,data)
        data['is_F'] = 'True'
        time.sleep(1)
        self.back()
        return True

    # 判断背包是否满
    def full(self,J=False, K='chj'):
        '''
        ----------
        J : Bool, 
            是否对基因体操作. The default is True.
        K : 'chj' or 'mch'
            对应拆解 / 卖出
        '''
        time.sleep(5)
        self.click('P_xtjm/beibao.jpg')
        L_chj = ['P_xtjm/chj.jpg','G_jm/queding.jpg','G_jm/queding.jpg']
        L_mch = ['P_xtjm/mch.jpg','G_jm/queding.jpg']
        D = {'chj':L_chj,'mch':L_mch}
        # 武器
        time.sleep(1)
        self.click('P_xtjm/wuqi.jpg')
        time.sleep(1)
        for i in D[K]:
            self.click(i)
            time.sleep(1)
        
        # 装备
        self.click('P_xtjm/zhb.jpg')
        time.sleep(1)
        for i in D[K]:
            self.click(i)
            time.sleep(1)
        if J is True:
            # 基因体
            time.sleep(0.5)
            self.click('P_xtjm/jyt.jpg')
            time.sleep(1)
            self.click('P_xtjm/fj.jpg')
            time.sleep(1)
            self.click('G_jm/queding.jpg')
            time.sleep(1)
        time.sleep(1)
        self.click('P_xtjm/beibao.jpg')
            
   
    def get_in(self,G_n='',M_n='',N_n='',G=True,q1=Queue()):
        '''
        G_n : str,关卡名,G_90.jpg
        M_n : str,模式名,M_zhch.jpg,
        N_n : str,难度,N_ly.jpg,仅M_n为M_wj.jpg时不需此参数
        G_n : Bool,是否需要召唤队友
        '''
        G_n = 'P_xtjm/%s'%G_n
        M_n = 'P_xtjm/%s'%M_n
        if self.is_sim('P_xtjm/G_jr.jpg') is True:
            self.click('P_xtjm/tuichu.jpg')
        time.sleep(5)
        self.click(G_n)
        time.sleep(1.5)
        self.click(M_n) 
        
        if M_n!='P_xtjm/M_wj.jpg':
            N_n = 'P_xtjm/%s'%N_n
            time.sleep(1.5)
            self.click(N_n)
        else:
            self.click('G_jm/queding.jpg')
            G = False
        while self.is_sim('G_jm/yi_jr.jpg') is not True:
            continue
        
        if G is True:
            time.sleep(0.5)
            self.keydown('g')
        
        
        if G_n=='':
            pass
        
        elif G_n=='P_xtjm/G_89.jpg':
            self.keydown('a',3)
        elif G_n=='P_xtjm/G_90.jpg':
            self.keydown('a',3)
        elif G_n=='P_xtjm/G_91.jpg':
            pass
        elif G_n=='P_xtjm/G_92.jpg':
            self.keydown('d',10)
            pass
        elif G_n=='P_xtjm/G_93.jpg':
            self.keydown('d', 3)
            pass
            
        elif G_n=='P_xtjm/G_94.jpg':
            time.sleep(7)
            self.keydown('e',0.2)
            self.keydown('a',0.3)
            self.keydown('d',1.3)
            self.keydown('a',2)
        elif G_n=='P_xtjm/G_95.jpg':
            time.sleep(7)
            self.keydown('a',0.3)

        elif G_n=='P_xtjm/G_96.jpg':
            pyautogui.keyDown('a')
            time.sleep(6)
            self.keydown('e',t=0.2)
            pyautogui.keyDown('s')
            time.sleep(4)
            pyautogui.keyUp('a')
            pyautogui.keyDown('d')
            time.sleep(8)
            pyautogui.keyUp('d')
            pyautogui.keyUp('s')
            self.keydown('d',6)
            self.keydown('e',t=0.2)
            self.keydown('e',t=0.2)
            
            pyautogui.click(1200,500)
            t = time.time()
            while True:
                if self.is_sim('G_jm/96_tch.jpg',s=0.8) is True:
                    break
                elif time.time()-t<2:
                    continue
                else:
                    print('未遁地')
                    q1.put(None)
                    self.back(M=False,data=None)
                    break
            pass
        
        elif G_n=='P_xtjm/G_97.jpg':
            # self.keydown('e',0.2)
            self.keydown('d',1)
        
        elif G_n=='P_xtjm/G_98_2.jpg':
            pass
        else:
            pass
        

        

    def get_position(self, img1, img2='123.jpg', s=0.75, M=True, K=False):
        '''
        当K为True时,用于返回进行rgb判断的数组
        ----------
        img1 : 路径名,需要在屏幕上查找的图片
            DESCRIPTION.
        img2 : 截图时临时存放位置. The default is '123.jpg'.
        s : 不大于1的正数,传递给is_sim函数.
        M : BOOL, optional
            为False时,未查找到返回(100,100)点. The default is True.
        K : 是否用于进行rgb搜索.
            The default is False.

        Returns
        -------
        (X,Y) 图像中心点坐标
        '''
        while self.is_sim(img1=img1,img2=img2,s=s) is not True:
            if M is True and K is not True:
                continue
            else:
                return (100,100)
        self.get_screen(img2)
        d = Image.open(img1).size

        im = cv2.imread(img1,0)
        im2 = cv2.imread(img2,0)
        res = cv2.matchTemplate(im2,im,cv2.TM_CCOEFF_NORMED)
        loc = np.where(res==res.max())
        X = int(loc[1][-1]+d[0]/2)
        Y = int(loc[0][-1]+d[1]/2)
        if K is True:
            im = cv2.imread('F:\Python/fuzhu/%s'%img2)
            im = im[max(0,int(loc[0])):min(1980,int(loc[0]+d[1])),
                    max(0,int(loc[1])):min(1980,int(loc[1]+d[0])),
                    :]
            return im
        else:
            return (X,Y)
        
            
    # 获得矩形位置截屏
    def get_screen(self,img2='123.jpg'):
        '''
        Parameters
        ----------
        img2 : 图片存储路径. The default is '123.jpg'.
        '''
        app = QApplication(sys.argv)
        screen = QApplication.primaryScreen()
        img = screen.grabWindow(QApplication.desktop().winId()).toImage()
        img.save('{:s}'.format(img2))

    
                
    def is_sim(self,img1='',img2='123.jpg',s=0.75,T_=False):
        '''

        判断img2里是否有img1
        ----------
        img1 :  The default is ''.
        img2 :  The default is '123.jpg'.
        s : 匹配最小值. The default is 0.75.
        T_ : 为True,打开调用模式
        '''
        img1 = cv2.imread(img1,0)
        self.get_screen(img2)
        img2 = cv2.imread(img2,0)
        res = cv2.matchTemplate(img2,img1,cv2.TM_CCOEFF_NORMED)
        if T_:print(res.max())
        if res.max()<s:
            if s>0.8:
                if res.max()>0.92:
                    pass
            return False
        return True
        
    def jd(self):
        time.sleep(5)
        self.click('P_xtjm/jundui.jpg')
        time.sleep(3)
        self.click('P_xtjm/jundui_lqjl.jpg')
        time.sleep(3)
        self.click('G_jm/queding.jpg')
        time.sleep(3)
        self.click('P_xtjm/jundui_ybjx.jpg')
        time.sleep(3)
        self.click('G_jm/queding.jpg')
        time.sleep(10)

        self.click('P_xtjm/jundui_jzh.jpg')
        time.sleep(3)
        self.click('P_xtjm/jundui_lbdx.jpg')
        time.sleep(2)
        self.click('P_xtjm/jundui_kshpqrw.jpg')
        time.sleep(3)
        pyautogui.moveTo(1597,725)
        time.sleep(0.5)
        pyautogui.click(1597,725)
        time.sleep(1)

        self.shch()
        time.sleep(3)
        self.endless()
        time.sleep(3)


    
    def jineng(self):
        '''
        直接按下键盘
        '''
        K = ['1','2','3','4','5','6','7','0']
        for i in K:
            self.keydown(i,0.3)
            time.sleep(0.1)
        

    def keydown(self,J='',t=1):
        pyautogui.keyDown(J)
        time.sleep(t)
        pyautogui.keyUp(J)
       

    def need_c(self):
        if self.is_sim('c.jpg',s=0.88) is True:
            self.keydown('c',0.2)


    def quit_(self):
        time.sleep(1)
        pyautogui.hotkey('Ctrl','W')

    def search_rgb(self,img1='',size=(256,256)):
        '''

        Parameters
        ----------
        img1 : 传递给get_position.是屏幕上的该图片,同时是对比彩色图片. 
        The default is ''.

        size : 进行比较时统一大小. The default is (256,256).

        Returns
        -------
        n : 相似值
        '''
        # 计算单通道的直方图的相似值
        def calculate(image1, image2):
            hist1 = cv2.calcHist([image1], [0], None, [64], [0.0, 63.0])
            hist2 = cv2.calcHist([image2], [0], None, [64], [0.0, 63.0])
            # 计算直方图的重合度
            degree = 0
            for i in range(len(hist1)):
                if hist1[i] != hist2[i]:
                    degree = degree + (1 - abs(hist1[i] - hist2[i]) / max(hist1[i], hist2[i]))
                else:
                    degree = degree + 1
            degree = degree / len(hist1)
            return degree
        
        def classify_hist_with_split(image1, image2, size=size):
            # 将图像resize后,分离为RGB三个通道,再计算每个通道的相似值
            image1 = cv2.resize(image1, size)
            image2 = cv2.resize(image2, size)
            sub_image1 = cv2.split(image1)
            sub_image2 = cv2.split(image2)
            sub_data = 0
            for im1, im2 in zip(sub_image1, sub_image2):
                sub_data += calculate(im1, im2)
            sub_data = sub_data / 3
            return sub_data

        im1 = self.get_position(img1,'color.jpg',s=0.5,K=True)
        if type(im1) is tuple:
            return 0
        im2 = cv2.imread(img1)
        n = classify_hist_with_split(im1,im2,size=size)
        return n
    
    def shch(self):
        time.sleep(3)
        self.click('P_xtjm/shichong.jpg')
        time.sleep(3)
        self.click('P_xtjm/shichong_pq.jpg')
        time.sleep(3)
        self.click('P_xtjm/lqjl.jpg')
        time.sleep(3)
        self.click('P_xtjm/shichong.jpg')
        time.sleep(3)
        self.click('P_xtjm/shichong.jpg')
        time.sleep(3)
        self.click('P_xtjm/shichong_pq.jpg')
        time.sleep(3)
        self.click('P_xtjm/shichong_kshpq.jpg')
        time.sleep(3)
        self.click('P_xtjm/shichong.jpg')
        

classname = 'Chrome_WidgetWin_1'
wdname = u'爆枪英雄,4399爆枪英雄,爆枪英雄小游戏,4399小游戏 - 个人 - Microsoft​ Edge'
demo = GameAssist(classname,wdname)
   

def Break(q1=Queue(),q2=Queue()):
    '''
        True 表示可以break
    '''
    order = q2.get()
    q2.put(order)
    if q1.empty() is False:
        return True
    elif order=='finish':
        return True
    

def shot(q1=Queue(),q2=Queue(),G=''):
    """
    已支持 关卡 [96/89/91/98]
    
    """

    if G=='G_96':
        while True:
            K = False
            A = demo.get_position('G_jm/96_3.jpg','sj_i0.jpg',s=0.75,M=False)
            while A[0]<900 or A[0]>1000 or A[1]<350 or A[1]>450:
                A = demo.get_position('G_jm/96_3.jpg','sj_i0.jpg',s=0.75,M=False)
                if Break(q1,q2) is True:
                    pyautogui.mouseUp(500,500)
                    pyautogui.click(500,500)
                    K = True
                    break
            if K is True:
                pyautogui.click(500,500)
                break
            demo.need_c()
            pyautogui.mouseDown(A)
        pyautogui.click(500,500,2)

    elif G=='G_89':
        pyautogui.mouseDown(1553,461)
        while Break(q1,q2) is not True:
            
            pyautogui.mouseDown(1553,461)
            demo.need_c()
            time.sleep(1)
        pyautogui.mouseUp(1553,461)

    elif G=='G_91':
        pyautogui.mouseDown(1250,477)
        while Break(q1,q2) is not True:
            
            pyautogui.mouseDown(1250,477)
            demo.keydown('a',1)
            time.sleep(1)
        pyautogui.mouseUp(1250,477)

    elif G=='G_92':
        pyautogui.mouseDown(770,813)
        while Break(q1,q2) is not True:
            
            pyautogui.mouseDown(770,813)
            demo.keydown('d',1)
            time.sleep(1)
            demo.need_c()
        pyautogui.mouseUp(770,813)
        
    elif G=='G_93':
        while Break(q1,q2) is not True:
            
            pyautogui.mouseDown(1120,547)
            demo.keydown('a',1)
            time.sleep(1)
            demo.need_c()
        pyautogui.mouseUp(1120,547)
        pass
        
    elif G=='G_94':
        
        pyautogui.mouseDown(906,566)
        while Break(q1,q2) is not True:
            
            pyautogui.mouseDown(906,566)
            demo.need_c()
            time.sleep(1)
        pyautogui.mouseUp(906,566)
        
    elif G=='G_95':
        
        pass
    
    elif G=='G_97':
        while Break(q1,q2) is not True:
            pyautogui.keyDown('a')
            pyautogui.mouseDown(1366,715)
            pyautogui.keyDown('s')
            demo.need_c()
            time.sleep(1)
        pyautogui.mouseUp(1366,715)
        pyautogui.keyUp('a')
        pyautogui.keyUp('s')
        
    elif G=='G_98':
        pyautogui.mouseDown(1000,540)
        while Break(q1,q2) is not True:
            pyautogui.mouseDown(1000,540)
            time.sleep(3)
        pyautogui.mouseUp(1000,540)
    else:
        pass
def process_job(name,q1,q2,x=[]):
    '''
    Parameters
    ----------
    name : TYPE
        DESCRIPTION.
    q1 : TYPE
        当获得None值时,该函数退出,None由死亡或过关写入.
    q2 : TYPE
        'in'表示已进入关内,'main'表示开始可进入关,'finishi'已完成关卡.
    x : TYPE, optional
        DESCRIPTION. The default is [].

    Returns
    -------
    None.

    '''

    while True:
        if name=='death':
            if demo.death() is True:
                q1.put(None)
                print('已死亡')
                break
            if q1.empty() is False:
                break
            
        elif name=='finish':
            if q2.empty() is not True:

                A = demo.finish(G_n=x[0],q1=q1,q2=q2,data=x[1],t=x[2])
                if A is True:
                    q1.put(None)
                    break
                elif A is None:
                    break
                
        elif name=='in_guan':
            if q2.empty() is not True:
                while True:
                    demo.jineng()
                    if Break(q1,q2) is True:
                        break
                break
        elif name=='shot':
            if q2.empty() is not True:
                shot(q1,q2,G=x[0])
                break

        else:
            print('未设置该',name,'函数')



# 拆箱子
def ChJ_XZ(L=[]):
    while True:
        demo.click('P_xtjm/wuping.jpg')
        demo.click(L[0])
        demo.click('P_xtjm/syqb.jpg')
        demo.click('G_jm/queding.jpg')
        time.sleep(4)
        demo.click(L[1])
        demo.click('P_xtjm/syqb.jpg')
        demo.click('G_jm/queding.jpg')
        time.sleep(4)
        
        demo.click('P_xtjm/wuqi.jpg')
        time.sleep(1)
        demo.click('P_xtjm/chj.jpg')
        time.sleep(1)
        demo.click('G_jm/queding.jpg')
        time.sleep(1)
        demo.click('G_jm/queding.jpg')
        time.sleep(1)
        
        # 装备
        demo.click('P_xtjm/zhb.jpg')
        time.sleep(1)
        demo.click('P_xtjm/chj.jpg')
        time.sleep(1)
        demo.click('G_jm/queding.jpg')
        time.sleep(1)
        demo.click('G_jm/queding.jpg')
        time.sleep(1)
        pass
# ChJ_XZ(['P_xtjm/XZ_1.jpg','P_xtjm/XZ_3.jpg'])

def main(G_n='',i=41,D_=True, T_=0,t_=1e10):
    '''G_n 关名  i 刷关数   D_队友存活用于记录
    t_ 限制每关时间  T_限制刷到几点(24小时制)
    '''
    
    if G_n=='G_96':
        G = 'G_96.jpg'
        M = 'M_zhch.jpg'
        N = 'N_kn.jpg'
        
    elif G_n=='G_92':
        G = 'G_92.jpg'
        M = 'M_zhch.jpg'
        N = 'N_shn.jpg'
        
    elif G_n=='G_93':
        G = 'G_93.jpg'
        M = 'M_zhch.jpg'
        N = 'N_kn.jpg'
    
    elif G_n=='G_94':
        G = 'G_94.jpg'
        M = 'M_zhch.jpg'
        N = 'N_chn.jpg'
    
    elif G_n=='G_95':
        G = 'G_95.jpg'
        M = 'M_zhch.jpg'
        N = 'N_chn.jpg'
        
    elif G_n=='G_97':
        G = 'G_97.jpg'
        M = 'M_zhch.jpg'
        N = 'N_jd.jpg'
    
    elif G_n=='G_98_2':
        G = 'G_98_2.jpg'
        M = 'M_zhch.jpg'
        N = 'N_pt.jpg'
    
    elif G_n=='G_98':
        G = 'G_98.jpg'
        M = 'M_zhch.jpg'
        N = 'N_pt.jpg'

    else:
        G = G_n+'.jpg'
        M = 'M_zhch.jpg'
        N = 'N_ly.jpg'
    print('准备',G,M,N,i)
    for j in range(1,i):
        if T_ == 0:
            pass
        else:
            if int(time.ctime()[11:13])>=T_:
                break
        data = Manager().dict({'is_D':'False','is_F':'False'})
        if j%2==0:
            demo.full(K='mch')
        q1,q2 = Queue(),Queue()
        t0 = time.time()
        demo.get_in(G,M,N,D_,q1=q1)
        q2.put('in')
        p2 = Process(target=process_job, args=('in_guan',q1,q2))
        p4 = Process(target=process_job,args=('death',q1,q2,))
        p1 = Process(target=process_job,args=('finish',q1,q2,[G,data,t_],))
        p0 = Process(target=process_job,args=('shot',q1,q2,[G_n]))
        

        p0.start()
        p2.start()
        p4.start()
        p1.start()

        p0.join()
        p4.join()
        p2.join()
        p1.join()
        t = int(time.time()-t0)
        L_data = [F"{t//60}m {t%60}s",data['is_D'],
                  data['is_F'],G_n,N[:-4],time.ctime()[4:-5]]
        if int(L_data[0][0])>0:
            save_data(L_data)
    print('完成',G,M,N,j-1)

def trial(self=demo):
   
    pass

        
def MAIN():
    
    main('G_95',70,T_=13,t_=280)
    # main('G_96',50,T_=13,t_=570)
    main('G_97',40,T_=15,t_=460)
    main('G_94',T_=17)
    # time.sleep(8)
    main('G_92',100,T_=23,t_=370)  
    # main('G_93',T_=23,t_=290)
    
    # main('G_98_2',81,T_=23,t_=512) 
    demo.quit_()
    shutdown()
    quit()
    
    # main('G_96',800,False)
    


if __name__=='__main__' and 1==1:
    MAIN()
    
    
    




    

本文地址:https://blog.csdn.net/qq_44990714/article/details/110933915

相关标签: python 多进程