栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

微信小游戏颜色风暴自动化

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

微信小游戏颜色风暴自动化

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

微信小游戏颜色风暴自动化

提示:以下是本篇文章正文内容,下面案例可供参考

一、环境

python
opencv
pyautogui

二、代码

代码如下:

'''

Descripttion: 
version: 
Author: 肖发博
Date: 2022-05-16 18:59:35
LastEditors: 肖发博
LastEditTime: 2022-05-16 22:31:36
'''
from unicodedata import name
import pyautogui
import time,math
import cv2

def get_centers(lp_pos,box_nums):
    """get_centers 返回所有颜色方块的中心
    [(x1,y1),(x2,y2),(x3,y3),...]

    :param lp_pos: 颜色显示区域的左上角坐标
    :type lp_pos: (x,y)
    :param box_nums: 颜色区域每行的方块数量
    :type box_nums: int
    """
    step=int(color_region[2]/box_nums)
    centers=[]
    for i in range(box_nums):
        for j in range(box_nums):
            x=lp_pos[0]+step/2+i*step
            y=lp_pos[1]+step/2+j*step
            centers.append((int(x),int(y)))
    return centers
def find_diffrent(lp_pos,box_nums):
    '''
    返回颜色不同点的坐标
    '''

    all_pos=get_centers(lp_pos,box_nums)
    all_colors=[]
    confirmd_color=None
    for pos in all_pos:
        rgb = pyautogui.pixel(pos[0],pos[1])
        all_colors.append(rgb)
    if all_colors[0]==all_colors[1]:
        confirmd_color=all_colors[0]
    else:
        if all_colors[0]==all_colors[2]:
            confirmd_color=all_colors[0]
        else:
            confirmd_color=all_colors[1]
    #print(confirmd_color)
    for i in range(len(all_colors)):
        if all_colors[i]!=confirmd_color:
            return all_pos[i]

def main():
    lp_pos=(color_region[0],color_region[1])#颜色区域左上角坐标需要手动测量
    box_size=481#颜色显示区域的边长
    while True:
        #确定每行的颜色快数量
        img = pyautogui.screenshot('temp.png',region=(lp_pos[0]-8,lp_pos[1]-8, color_region[2]+16, color_region[3]+16))
        img = cv2.imread('temp.png', -1)
        gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        ret, th = cv2.threshold(gray_img, 10, 255, cv2.THRESH_BINARY)
        ret, labels, stats, centroid = cv2.connectedComponentsWithStats(th)
        box_nums=int(math.sqrt(len(stats)-1))#颜色快数量
        
        pos=find_diffrent(lp_pos,box_nums)#找到颜色不同的坐标
        print(pos)
        #自动点击
        pyautogui.moveTo(pos[0],pos[1])
        time.sleep(0.03)
        pyautogui.click()
        time.sleep(0.02)

if __name__=="__main__":
    color_region=(719,223,481,481)#手动确定颜色方框(left,up,wifth,hight)
    main()
三、使用方法

在电脑上进入小游戏颜色风暴

首先确定颜色区域的位置


使用微信截图(Alt+a)或者qq截图(Ctrl+shift+A)确定颜色区域的方框,左上角坐标为前两项,宽度和高度为后两项

修改代码中的color_region

if __name__=="__main__":
    color_region=(719,223,481,481)#手动确定颜色方框(left,up,wifth,hight)
    main()

启动脚本即可

注意

1、脚本路径一定不能含有中文否则opencv不能正常使用会产生报错
2、如果想停止,直接win+D返回桌面程序会自动报错退出

效果展示

在正常模式下满分好像只有50

无尽模式满分没有上限,比较坑的是到300多的时候,位置就确定了,不会改变,所以就能看到鼠标在同一个位置点击。试了一下,感觉没意思到400多就退出了。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/889879.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号