借鉴了很多人扫雷的版本 这个扫雷程序第一步不会碰到雷,而且掀开方块的速度比较快 程序
function XPBOMBS2
clear
row=15;col=20;mines=45;
total=mines;times=1;
remine=row*col;
flags=0;
hf=figure('NumberTitle','off','Name','扫雷','menubar','none','position',[370,130,600,500]);
uh1=uimenu('label','帮助');
uimenu(uh1,'label','游戏规则','callback',['msgbox(''和windows自带的扫雷一个样,嗯哒'')'])
colormap([1 0 0;0 0 0;.65 .65 .65;1 1 1]);
axis off
hold on;
C=uicontrol(gcf,'style','text','unit','normalized',...
'position',[0.45,0.86,0.09,0.078],'fontsize',17,...
'BackgroundColor',0.85*[1 1 1],...
'string','o');
H=uicontrol(gcf,'style','text','unit','normalized',...
'position',[0.58,0.86,0.3,0.078],'fontsize',12,...
'BackgroundColor',0.85*[1 1 1],...
'string',['total:' num2str(total)]);
F=uicontrol(gcf,'style','text','unit','normalized',...
'position',[0.1,0.86,0.3,0.078],'fontsize',12,...
'BackgroundColor',0.85*[1 1 1],...
'string',['flag:' num2str(flags)]);
for m=1:row
for n=1:col
h(m,n)=uicontrol(gcf,'style','push',...
'foregroundColor',0.7*[1 1 1],...
'BackgroundColor',0.7*[1 1 1],...
'fontsize',15,'fontname','time new roman',...
'Unit','normalized','position',[0.013+0.045*n,0.86-0.054*m,0.043,0.052],...
'Visible','on',...
'callback',@pushcallback,'ButtonDownFcn',@buttoncallback);
end
end
function first_time(place)
mine=rand(row,col);
A=ones(row,col);
[x,y]=find(A==1);
postions=[x,y];
places=[place;place+[1,0];place+[-1,0];place+[1,1];place+[0,1];
place+[-1,1];place+[1,-1];place+[0,-1];place+[-1,-1]];
places=intersect(postions,places,'rows');
pos=places(:,1)+(places(:,2)-1).*row;
mine(pos)=1;
[~,index]=sort(mine(:));
mine=(mine
关注
打赏