前言:

哈喽~在连连看中满级大佬进新手村是一个什么样的体验?

连连看小游戏,新手必看之正确打开方式【高燃慎入】全是技巧 没有感情

【Python制作游戏外挂】满级大佬进新手村,连连看你看清楚了没?

需要连连看游戏脚本和更多python资料,安装包的小伙伴能点击这里哦~

正文:

运行环境:Win10/Python3.5。

主要模块:win32gui(识别窗口、窗口置顶等操作)、PIL(屏幕截图)、numpy(创建矩阵)、operator(比较值)、pymouse(模拟鼠标点击)。

代码:

import PIL.ImageGrab
import pyautogui
import win32api
import win32gui
import win32con
import time
import randomdef color_hash(color):value = ""for i in range(5):value += "%d,%d,%d," % (color[0], color[1], color[2])return hash(value)def image_hash(img):value = ""for i in range(5):c = img.getpixel((i * 3, i * 3))value += "%d,%d,%d," % (c[0], c[1], c[2])return hash(value)def game_area_image_to_matrix():pos_to_image = {}for row in range(ROW_NUM):pos_to_image[row] = {}for col in range(COL_NUM):grid_left = col * grid_widthgrid_top = row * grid_heightgrid_right = grid_left + grid_widthgrid_bottom = grid_top + grid_heightgrid_image = game_area_image.crop((grid_left, grid_top, grid_right, grid_bottom))pos_to_image[row][col] = grid_imagepos_to_type_id = {}image_map = {}empty_hash = color_hash((48, 76, 112))for row in range(ROW_NUM):pos_to_type_id[row] = {}for col in range(COL_NUM):this_image = pos_to_image[row][col]this_image_hash = image_hash(this_image)if this_image_hash == empty_hash:pos_to_type_id[row][col] = 0continueimage_map.setdefault(this_image_hash, len(image_map) + 1)pos_to_type_id[row][col] = image_map.get(this_image_hash)return pos_to_type_iddef solve_matrix_one_step():for key in map:arr = map[key]arr_len = len(arr)for index1 in range(arr_len - 1):point1 = arr[index1]x1 = point1[0]y1 = point1[1]for index2 in range(index1 + 1, arr_len):point2 = arr[index2]x2 = point2[0]y2 = point2[1]if verifying_connectivity(x1, y1, x2, y2):arr.remove(point1)arr.remove(point2)matrix[y1][x1] = 0matrix[y2][x2] = 0if arr_len == 2:map.pop(key)return y1, x1, y2, x2def verifying_connectivity(x1, y1, x2, y2):max_y1 = y1while max_y1 + 1 < ROW_NUM and matrix[max_y1 + 1][x1] == 0:max_y1 += 1min_y1 = y1while min_y1 - 1 >= 0 and matrix[min_y1 - 1][x1] == 0:min_y1 -= 1max_y2 = y2while max_y2 + 1 < ROW_NUM and matrix[max_y2 + 1][x2] == 0:max_y2 += 1min_y2 = y2while min_y2 - 1 >= 0 and matrix[min_y2 - 1][x2] == 0:min_y2 -= 1rg_min_y = max(min_y1, min_y2)rg_max_y = min(max_y1, max_y2)if rg_max_y >= rg_min_y:for index_y in range(rg_min_y, rg_max_y + 1):min_x = min(x1, x2)max_x = max(x1, x2)flag = Truefor index_x in range(min_x + 1, max_x):if matrix[index_y][index_x] != 0:flag = Falsebreakif flag:return Truemax_x1 = x1while max_x1 + 1 < COL_NUM and matrix[y1][max_x1 + 1] == 0:max_x1 += 1min_x1 = x1while min_x1 - 1 >= 0 and matrix[y1][min_x1 - 1] == 0:min_x1 -= 1max_x2 = x2while max_x2 + 1 < COL_NUM and matrix[y2][max_x2 + 1] == 0:max_x2 += 1min_x2 = x2while min_x2 - 1 >= 0 and matrix[y2][min_x2 - 1] == 0:min_x2 -= 1rg_min_x = max(min_x1, min_x2)rg_max_x = min(max_x1, max_x2)if rg_max_x >= rg_min_x:for index_x in range(rg_min_x, rg_max_x + 1):min_y = min(y1, y2)max_y = max(y1, y2)flag = Truefor index_y in range(min_y + 1, max_y):if matrix[index_y][index_x] != 0:flag = Falsebreakif flag:return Truereturn Falsedef execute_one_step(one_step):from_row, from_col, to_row, to_col = one_stepfrom_x = game_area_left + (from_col + 0.5) * grid_widthfrom_y = game_area_top + (from_row + 0.5) * grid_heightto_x = game_area_left + (to_col + 0.5) * grid_widthto_y = game_area_top + (to_row + 0.5) * grid_heightpyautogui.moveTo(from_x, from_y)pyautogui.click()pyautogui.moveTo(to_x, to_y)pyautogui.click()if __name__ == '__main__':COL_NUM = 19ROW_NUM = 11screen_width = win32api.GetSystemMetrics(0)screen_height = win32api.GetSystemMetrics(1)hwnd = win32gui.FindWindow(win32con.NULL, 'QQ游戏 - 连连看角色版')if hwnd == 0:exit(-1)win32gui.ShowWindow(hwnd, win32con.SW_RESTORE)win32gui.SetForegroundWindow(hwnd)window_left, window_top, window_right, window_bottom = win32gui.GetWindowRect(hwnd)if min(window_left, window_top) < 0 or window_right > screen_width or window_bottom > screen_height:exit(-1)window_width = window_right - window_leftwindow_height = window_bottom - window_topgame_area_left = window_left + 14.0 / 800.0 * window_widthgame_area_top = window_top + 181.0 / 600.0 * window_heightgame_area_right = window_left + 603 / 800.0 * window_widthgame_area_bottom = window_top + 566 / 600.0 * window_heightgame_area_width = game_area_right - game_area_leftgame_area_height = game_area_bottom - game_area_topgrid_width = game_area_width / COL_NUMgrid_height = game_area_height / ROW_NUMgame_area_image = PIL.ImageGrab.grab((game_area_left, game_area_top, game_area_right, game_area_bottom))matrix = game_area_image_to_matrix()map = {}for y in range(ROW_NUM):for x in range(COL_NUM):grid_id = matrix[y][x]if grid_id == 0:continuemap.setdefault(grid_id, [])arr = map[grid_id]arr.append([x, y])pyautogui.PAUSE = 0while True:one_step = solve_matrix_one_step()if not one_step:exit(0)execute_one_step(one_step)time.sleep(random.randint(0,0)/1000)

主要思路就是利用pywin32获取连连看游戏句柄, 获取游戏界面的图片, 对方块进行切割, 对每个方块取几个点的颜色进行比对, 均相同则认为是同一个方块,

然后模拟鼠标去消就行了, 代码的最后一行是每次点击的间隔。

结尾:

以上就是文章的全部内容了,Python用来实现连连看的小脚本, 温馨提示,此脚本仅用于学习, 请

在练习模式下使用, 请不要拿去伤害玩家们哦...

 欢迎点赞支持~大家需要完整的项目源码的可以私信我哟

【Python游戏外挂】满级小孩进新手村,实现连连看外挂秒杀相关推荐

  1. 一人之下手游显示服务器满员,一人之下手游满级多少 满级后攻略[多图]

    一人之下手游满级是多少呢?满级之后我们应该怎么玩呢? 那么现在就让我们一起来看看这款游戏在满级之后应该做些什么吧,希望可以在游戏中帮助到你们. 一人之下手游满级多少 一人之下手游小萌也玩了好几天了,今 ...

  2. 连连看外挂的制作.1 ----- 建立模型

    <script type="text/javascript"> </script> 前一段看Linux内核,看的头晕眼花,不得不承认,自己还没到那个层次,到 ...

  3. Android逆向 微信小游戏破解(一):我要当皇上满级修改

    1.我要当皇上的wx小游戏修改 首先游戏长这个样子, 我的长这个样子 1.首先需要用的到的工具,抓包工具,postman 抓包工具有很多,自己百度一下吧.我用的是charles,这个是mac版本的.W ...

  4. [游戏]_红眼满级了,后面的路会更长

    忙了一天,红眼终于满级了,啦啦啦.第一个目标完成,下一个目标,剑魂pk到尊10:路,会更长

  5. python游戏编程培训

    准备好了吗?我们即将开始激动人心的游戏编程之旅. 或许你之前学习过一点编程,但若是你从没接触过游戏编程,那么你仍然会对游戏程序的运行感到不解.游戏程序不像计算一个公式或谜题,得到答案之后程序就结束了, ...

  6. 侍魂胧月传说显示服务器满了,侍魂胧月传说满级玩法一览

    侍魂胧月传说满级玩法一览是很多小伙伴都不太懂的地方哦,那么安致小编今天就给大家来介绍一下侍魂胧月传说满级玩法介绍! 侍魂胧月传说满级玩法介绍 在侍魂胧月传说中,到了60级就已经满级了,玩家对游戏也基本 ...

  7. dnf小区最多的服务器,dnf最强服务器出炉, 深渊史诗百分百爆率, 一天直升满级...

    原标题:dnf最强服务器出炉, 深渊史诗百分百爆率, 一天直升满级 大家都知道DNF这游戏虽然说是个非常老的游戏了,从开服至今已经是有十个年头了,但是其热度现在依旧不低啊,可以说是目前最火的网游之一了 ...

  8. 我的世界修改等级上限服务器,我的世界:容易误导玩家的五个问题,满级之后将迎来新的开始?...

    感谢大家捧场,我是图酱,这里是Minecraft攻略.资讯.趣事的聚集地.喜欢就关注我,关注精彩万分的MC世界. <我的世界>中玩家可以通过获取经验值升级,等级越高所需经验值越多,所以大部 ...

  9. 200行Python实现效果逆天的连连看外挂

    本文内容转自我本人的知乎回答:你看过/写过哪些有意思的代码? - 三级狗的回答 - 知乎 https://www.zhihu.com/question/275611095/answer/4079841 ...

最新文章

  1. 提速20倍!谷歌AI发布TensorFlow 3D
  2. java编写代码时易出错_归纳:编写Java程序最容易犯的21种错误
  3. 计算机缺少php5.dll,php5isapi.dll 64位
  4. malloc 不能返回动态内存
  5. 青春环游记 | 雪中悍刀行之卡尔曼的鱼【回顾 2021,展望 2022】
  6. 解决ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
  7. 过了双十一之后的你。。| 今日最佳
  8. 下载OpenCV神经网络模型及pycharm中 argparse的参数设置
  9. ubuntu 安装Pangolin 过程
  10. 18个小实例入门SQLServer XML查询
  11. html+css 登录界面
  12. 这是你了解的P2P 么?
  13. matlab差值后求斜率,用三次样条插值求离散点斜率 matlab程序
  14. bootstrap框架 基础样式
  15. java的jna电脑桌面背景_获取bing图片并自动设置为电脑桌面背景(使用 URLDownloadToFile API函数)...
  16. python量化策略——大类资产配置模型(最小方差模型)
  17. 互联网创新创业大赛优秀范例_第五十九期创业沙龙——“互联网+”大学生创新创业大赛实践案例...
  18. matlab 画折线图,matlab 双坐标折线图画法
  19. 黑客攻防与网络安全-N-0
  20. discuz帖子最后编辑时间如何取消显示

热门文章

  1. PySide6中QlineEdit设置自动所有字母大写以及首字母大写的案例
  2. ubuntu22.10使用显卡驱动nvidia-driver-525-testd报错
  3. 《我的第一本算法书》阅读笔记 1-8 二叉查找树
  4. 双目是个词吗_四字成语什么双目
  5. 阿里云ONS / RocketMQ的定时消息 / 延时消息
  6. Communication-Efficient Learning of Deep Networks from Decentralized Data
  7. 如何提高Assignment写作效率?
  8. 如何快讲清楚一件事和它的价值(STAR原则)
  9. 前端wx-jssdk的使用及企微和微信下分享等功能自定义处理
  10. 【译】GraalVM—下一代JVM介绍