# MATLAB製作GUI—掃雷遊戲的實現②

``````function SaoLeiGaming(tmp)

%This is the SaoLei game,that we used to played in our childhood.
%Author：等等登登-ande
%Email：[email protected]

if nargin==0
tmp = 'inital';
NumButton = 12;
end
switch(tmp)
case 'inital'
fullsizescreen = get(0,'ScreenSize');%獲取屏幕的大小以及右下角座標
H = figure('name','掃雷_zd',...
'position',[fullsizescreen(3)/3,fullsizescreen(4)/3,80+35*NumButton,80+35*NumButton],...
'CallBack',[mfilename,'(''quit'');',mfilename]);%在菜單Game下創建子菜單NewGame
'CallBack',[mfilename,'(''quit'')']);%在菜單Game下創建子菜單Quit
HBOX = zeros(NumButton);
for i = 1:NumButton
for j = 1:NumButton
HBOX(i,j) = uicontrol(H,'Style','pushbutton',...
'FontWeight','bold','FontSize',10,...
'position',[40+35*(i-1),40+35*(NumButton-j),35,35],...
'tooltipstring','This is not boom!',...
'ButtondownFcn','RightKey',...
'CallBack','LeftKey');%創建NumBotton*NumBotton個格子
end
end
case 'quit'
closereq
end
``````

``````function LeftKey
%左鍵觸發函數
content = get(gco,'Value')
if isequal(content,'0')
set(gco,'Value','0');
else
set(gco,'Value',1);
end``````