5

Python游戏开发,pyautogui模块,Python自动玩"别再踩白块了"小游戏

 2 years ago
source link: https://segmentfault.com/a/1190000040624294
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Python游戏开发,pyautogui模块,Python自动玩"别再踩白块了"小游戏

发布于 25 分钟前

利用Python自动玩"别再踩白块了"这个小游戏,让我们愉快地开始吧~

Python版本: 3.6.4

相关模块:

numpy模块;

cv2模块;

pyautogui模块;

pyscreenshot模块;

以及一些Python自带的模块。

安装Python并添加到环境变量,pip安装需要的相关模块即可。

游戏规则:

原理介绍:

原理其实挺简单的,主循环的代码如下图所示:
图片

首先是截取游戏界面:
图片

二值化游戏界面:
图片

形态学处理:
图片

实现轮廓检测:
图片

文章到这里就结束了,感谢你的观看,Python自动玩小游戏系列,下篇文章分享Python实现AI版贪吃蛇

在这里插入图片描述


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK