当前位置:   article > 正文

python3 游戏挂机脚本_python ip代理游戏挂机

python ip代理游戏挂机
import pyautogui
import numpy as np
import PIL
import pytesseract
from PIL import Image
import time
import cv2
import os
import keyboard

# find_list = ['img/wait.jpg', 'img/end.jpg']
genting_list = ['img/Genting/start.bmp', 'img/Genting/commit.bmp', 'img/Genting/exit.bmp', 'img/Genting/next.bmp']
equip_list = ['img/Genting/equip1.bmp', 'img/Genting/equip2.bmp']


def find_on_template(target, template):
    theight, twidth = target.shape[:2]

    result = cv2.matchTemplate(target, template, cv2.TM_SQDIFF_NORMED)

    min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)
    # 如果匹配度小于99%,就认为没有找到。
    if min_val > 0.1:
        return None
    strmin_val = str(min_val)
    # print(strmin_val)

    x = min_loc[0] + twidth // 2
    y = min_loc[1] + theight // 2
    return x, y


def get_position(image):
    # target = cv2.imread("target.jpg")
    target = pyautogui.screenshot()
    target = np.array(target)

    template = cv2.imread(image, dtype=np.uint8)

    # 获得模板图片的高宽尺寸
    theight, twidth = template.shape[:2]
    # 执行模板匹配,采用的匹配方式cv2.TM_SQDIFF_NORMED
    result = cv2.matchTemplate(target, template, cv2.TM_SQDIFF_NORMED)
    # 归一化处理
    cv2.normalize(result, result, 0, 1, cv2.NORM_MINMAX, -1)
    # 寻找矩阵(一维数组当做向量,用Mat定义)中的最大值和最小值的匹配结果及其位置

    min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result)

    return min_loc[0] + twidth / 2, min_loc[1] + theight / 2


def find_and_click(target_dir, left_or_right):
    screen_img = pyautogui.screenshot()

    screen_img = cv2.cvtColor(np.asarray(screen_img), cv2.COLOR_RGB2BGR)

    target = cv2.imread(target_dir)

    position = find_on_template(target, screen_img)

    if position is not None:
        if left_or_right:
            pyautogui.moveTo(position[0], position[1])
            pyautogui.mouseDown()
            time.sleep(0.1)
            pyautogui.mouseUp()
        else:
            pyautogui.rightClick(x=position[0], y=position[1])

        # pyautogui.moveTo(position[0], position[1])
        # pyautogui.click()
        return True

    return False


def auto_genting():
    switch_on = False

    cards_list = make_img_list('img/Genting/cards')

    screenWidth, screenHeight = pyautogui.size()

    while True:
        if keyboard.is_pressed('f5'):
            print('开始!')
            switch_on = True
        elif keyboard.is_pressed('f6'):
            print('结束!')
            switch_on = False
        if switch_on:
            pyautogui.moveTo(screenWidth/2, screenHeight/2)
            # 开始or结束
            for each in genting_list:
                find_and_click(each, True)
            # 装备
            for each in equip_list:
                find_and_click(each, False)
            # 搜牌
            for each in cards_list:
                find_and_click(each, True)
            # 时间节点


def make_img_list(img_dir):
    res = []
    for root, dirs, files in os.walk(img_dir):
        for file in files:
            res.append(os.path.join(root, file))
    return res


if __name__ == '__main__':

    auto_genting()

    # main()

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/105391
推荐阅读
相关标签
  

闽ICP备14008679号