zoukankan      html  css  js  c++  java
  • None

    # _*_ coding:utf-8 _*_
    
    
    from pymouse import *
    from pykeyboard import *
    from PIL import ImageGrab
    import numpy as np
    import threading
    import win32gui
    import pyaudio
    import time
    import wave
    import cv2
    
    # 获取游戏句柄
    def get_all_hwnd(hwnd, mouse):
        global Jub
        if win32gui.IsWindow(hwnd) and win32gui.IsWindowEnabled(hwnd) and win32gui.IsWindowVisible(hwnd):
            if win32gui.GetWindowText(hwnd) == 'xxxx':
                Jub = hwnd
    win32gui.EnumWindows(get_all_hwnd, 0)
    
    def counter():
        number = 0
        while True:
            time.sleep(1)
            number += 1
    
    class AutoTools(object):
    
        def __init__(self):
            pass
    
        def ShowTheGame(self):
            win32gui.SetForegroundWindow(Jub)
    
        def ScreenshotOfGame(self, name):
            pic = ImageGrab.grab()
            pic.save(name)
    
        def MatchThePicture(self, A, B):
            target = cv2.imread(A)
            template = cv2.imread(B)
            result = cv2.matchTemplate(target, template, cv2.TM_SQDIFF_NORMED)
            cv2.normalize(result, result, 0, 1, cv2.NORM_MINMAX, -1)
            min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
            x = min_loc[0] + 30
            y = min_loc[1] + 30
            return x, y
    
    
        def StartRecording(self, x, y):
            CHUNK = 512
            FORMAT = pyaudio.paInt16
            CHANNELS = 1
            RATE = 48000
            p = pyaudio.PyAudio()
            stream = p.open(format=FORMAT,
                            channels=CHANNELS,
                            rate=RATE,
                            input=True,
                            frames_per_buffer=CHUNK)
            fishtime = int(time.time())
            while (True):
                if int(time.time()) - fishtime >= 30:
                    k.press_key(' ')
                    k.release_key(' ')
                    break
                for i in range(0, 10):
                    data = stream.read(CHUNK)
                audio_data = np.frombuffer(data, dtype=np.short)
                temp = np.max(audio_data)
                if temp > 300:
                    print('钓到鱼了!!!')
                    break
            stream.stop_stream()
            stream.close()
            time.sleep(0.1)
            m.click(x, y, 2)
    
    class Script(object):
    
        def Eat(self):
            time.sleep(2)
            #ao.ShowTheGame()
            k.press_key('0')
            k.release_key('0')
            k.press_key('=')
            k.release_key('=')
            time.sleep(5.1)
    
    
        def Fishing(self):
            #ao.ShowTheGame()
            k.press_key('9')
            k.release_key('9')
            time.sleep(2)
            ao.ScreenshotOfGame('b.png')
            x, y = ao.MatchThePicture('b.png', './gouzi.png')
            m.move(x, y)
            ao.StartRecording(x, y)
    
    
    def run():
        sc.Eat()
        starttime = int(time.time())
        while True:
            time.sleep(2)
            if int(time.time()) - starttime >= 600:
                sc.Eat()
                starttime = int(time.time())
            time.sleep(1)
            sc.Fishing()
    
    
    if __name__ == '__main__':
        ao = AutoTools()
        sc = Script()
        m = PyMouse()
        k = PyKeyboard()
        run()
    
  • 相关阅读:
    Delphi实现在数据库中存取图像
    c#后台修改前台DOM的css属性示例代码
    jQuery编程中的一些核心方法简介
    jquery用ajax方式从后台获取json数据后如何将内容填充到下拉列表
    jQuery实现淡入淡出二级下拉导航菜单的方法
    jQuery实现瀑布流布局详解(PC和移动端)
    jQuery实用技巧必备
    jQuery链式操作实例分析
    谈谈Jquery ajax中success和complete有哪些不同点
    jquery密码强度校验
  • 原文地址:https://www.cnblogs.com/liuhedong/p/12454362.html
Copyright © 2011-2022 走看看