前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >MATLAB自动扫雷(3)——整体运行

MATLAB自动扫雷(3)——整体运行

作者头像
万木逢春
发布2019-04-30 18:07:35
8290
发布2019-04-30 18:07:35
举报
文章被收录于专栏:帮你学MatLab帮你学MatLab

整体运行扫雷

close

clear

clc

global gameover

global rect_in

global map

global blocks_x

global blocks_y

global block_width

global block_height

global left

global top

%% 扫雷游戏窗口

class_name = "TMain";

title_name = "Minesweeper Arbiter ";

rect = win.getWindowRect(class_name, title_name);

% 窗口坐标

left = rect(1);

top = rect(2);

right = rect(3)+rect(1);

bottom = rect(4)+rect(2);

if rect

disp("找到窗口")

disp("窗口坐标:")

disp([num2str(left) , ' ' , num2str(right) , ' ' ,...

num2str(top) , ' ' , num2str(bottom)])

else

disp("未找到窗口")

end

%% 锁定雷区坐标

left = left + 15;

top = top + 101;

right = right - 15;

bottom = bottom - 43;

% 抓取雷区图像

rect_in = [left, top, right-left, bottom-top];

img = win.screenCapture(rect_in);

% img = img/255;

% 每个方块16*16

block_width = 16;

block_height = 16;

% 横向有blocks_x个方块

blocks_x = floor((right - left) / block_width);

% 纵向有blocks_y个方块

blocks_y = floor((bottom - top) / block_height);

map = zeros(blocks_x,blocks_y);

% 是否游戏结束的标记

gameover = 0;

%%

win.setMouse(left+5, top+5);

win.leftClick;%开局点一下

showmap();

start = datetime('now');

%设定一个时间、如果一直没成功就自然结束

while (datetime('now')-start<duration(0,0,600))

if (gameover == 0)

banner();

banner();

click_blank();

else

gameover = 0;%点到雷重来

win.setMouse(left+5, top+5);

win.leftClick;

win.key(113)

win.leftClick;

showmap();

end

if all(all(map~=0)) && gameover==0

break%成功扫雷

end

end

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-03-12,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 帮你学MatLab 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档