⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 matlab写的扫雷小游戏.txt

📁 这是我自己用MATLAB编的一个扫雷小游戏,程序比较经典,希望和大家一起分享.
💻 TXT
字号:
% simulate a clear-landmine; 
close all;clc;clear; 
m=9;n=9; % the size of land; 
g=10;    % the number of landmine; 
handles=zeros(m,n); 
w=0.06;h=0.08; 
for x=1:m; 
   for y=1:n; 
       handles(x,y)=uicontrol(gcf,'style','push',... 
           'unit','normalized','position',[0.02+w*x,... 
               0.03+h*(y-1),w,h],'BackgroundColor',... 
           [0.9 0.9 0.9],'ForegroundColor','k',... 
           'fontsize',10); 
   end 
end 
set(gcf,'name','clear-landmine game'); 
set(gcf,'NumberTitle','off'); 
q=randperm((m*n));q(g+1:end)=[]; 
ma=zeros(m,n);ma(q)=1; 
dm=zeros(m+2,n+2);dm(2:end-1,2:end-1)=ma; 
dmm=dm(1:end-2,2:end-1)+dm(3:end,2:end-1)+... 
   dm(2:end-1,1:end-2)+dm(2:end-1,3:end)+... 
   dm(1:end-2,1:end-2)+dm(3:end,3:end)+... 
   dm(1:end-2,3:end)+  dm(3:end,1:end-2); 
for x=1:m; 
   for y=1:n; 
       set(handles(x,y),'callback',... 
           ['set(gcbo,''string'',',... 
               num2str(dmm(x,y)),');']); 
       if ma(x,y)==1; 
           set(handles(x,y),'callback',... 
               ['set(gcbo,''string'',',... 
                   num2str(dmm(x,y)),');',... 
               'set(gcbo,''BackgroundColor'',''r'');']); 
       end 
   end 
end 
s=['    ']; 
axes('position',[0.63,0.3,0.3,0.4]); 
text(0.1,0.7,'\copyrightcopyright: zjliu',... 
   'fontsize',16,'color','y'); 
text(0.1,0.5,'Author''s email:',... 
   'fontsize',16,'color','y'); 
text(0.1,0.3,'zjliu2001@163.com',... 
   'fontsize',14,'color','y'); 
axis off; 
uicontrol(gcf,'style','text',... 
   'unit','normalized','position',... 
   [0.13,0.76,0.78,0.16],... 
   'BackgroundColor',[0.9 0.9 0.9],... 
   'ForegroundColor','b',... 
   'fontsize',10,'string',[s,... 
       'Note: When you have knock on pushbuttons, ',... 
       'the number of landmine about this',... 
       ' pushbutton will be showed. ',... 
       'Moreover, if a landmine exist',... 
       ' under this pushbutton, then',... 
       ' this pushbutton is changed to',... 
       ' "red" color. You also strike',... 
       'that gray bull, whereafter you',... 
       ' can enjoy a cartoon.'],... 
   'HorizontalAlignment','left'); 
axes('position',[0.67,0.03,0.3,0.3]); 
[u,v]=meshgrid(linspace(-1,1,200)); 
gg=imshow(abs(sinc(u.^2+v.^2)),[]); 
tz=0; 
set(gg,'ButtonDownFcn',['while tz<20;',... 
       't=sin(tz*pi*2)+2;',... 
       '[u,v]=meshgrid(linspace(-t,t,200));',... 
       'set(gg,''cdata'',abs(abs(sinc(u.^2+v.^2))));',... 
       'pause(0.1);tz=tz+0.05;end;']); 
set(gcf,'DoubleBuffer','on'); 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -