今天完成扫雷游戏的第二小步,实现了关闭游戏,重新开始游戏,右键点击进行标记的功能:
function SaoLeiGaming(tmp)
%This is the SaoLei game,that we used to played in our childhood.
%Author:等等登登-ande
%Email:18356768364@163.com
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],...
'Menubar','none');%创建函数句柄H
menu1 = uimenu(H,'Text','&Game');%在H函数句柄上创建菜单Game
uimenu(menu1,'Text','&NewGame','Accelerator','M',...
'CallBack',[mfilename,'(''quit'');',mfilename]);%在菜单Game下创建子菜单NewGame
uimenu(menu1,'Text','&Quit','Accelerator','Q',...
'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