function varargout = saolei( varargin )
if nargin == 0
OldHandle = findobj( 'Type', 'figure', 'Tag', 'NewClearMine' ) ;
if ishandle( OldHandle )
close( OldHandle ) ;
end
FigureHandle = figure('Visible', 'off') ;
init_FigureContent( FigureHandle ) ;
elseif ischar( varargin{1} )
if nargout > 0
[varargout{1:nargout}] = feval(varargin{:}) ;
else
feval(varargin{:}) ;
end
end
% ------------------------------------------------------------------------
function generate_FigureContent( FigureHandle, ButtonNumber ) ;
TabSpace = 10 ;
MidSpace = 1 ;
ButtonColNumber = ButtonNumber(2) ;
ButtonRowNumber = ButtonNumber(1) ;
TextHeight = 25 ;
FigureWidth = ButtonColNumber * (21 + MidSpace) + TabSpace * 4 ;
FigureHeight = ButtonRowNumber * (21 + MidSpace) + TabSpace * 5 + TextHeight ;
set( FigureHandle, 'Position', [100, 100, FigureWidth, FigureHeight], 'Menubar', 'none',...
'Visible', 'off', 'Name', '扫雷', 'Tag', 'NewClearMine', 'NumberTitle', 'off',...
'DoubleBuffer', 'on', 'Units', 'pixel', 'Color', [0.85 0.85 0.85], 'Resize', 'off',...
'KeyPressFcn', 'saolei(''Keypress_fcn'', gcbf)' ) ;
AxesHandle = axes( 'Position', [0, 0, 1, 1], 'Units', 'pixel', 'Tag', 'MainAxes',...
'XLim', [0, FigureWidth], 'YLim', [0, FigureHeight], 'Visible', 'off' ) ;
LineXArray = [TabSpace, FigureWidth-TabSpace, FigureWidth-TabSpace, TabSpace, TabSpace] ;
LineYArray = [TabSpace, TabSpace, FigureHeight-TabSpace, FigureHeight-TabSpace, TabSpace] ;
line( LineXArray, LineYArray, 'Color', 'k' , 'Tag', 'MainFrame') ;
MenuHandle = uimenu( FigureHandle, 'Label', '游戏', 'Tag', 'MainMenu' ) ;
SubMenuTag = {'Begin', 'Easy', 'Normal', 'Hard', 'Custom', 'Exit' } ;
SubMenuString = {'开始(&B)', '低级(&E)', '中级(&N)', '高级(&H)', '自定义(&C)', '退出(&Q)'};
SubMenuCallback = {'saolei( ''BeginMenu_Callback'', gcbo)',...
'saolei( ''EasyMenu_Callback'', gcbo)',...
'saolei( ''NormalMenu_Callback'', gcbo)',...
'saolei( ''HardMenu_Callback'', gcbo)' ,...
'saolei( ''CustomMenu_Callback'', gcbo)',...
'close(gcf)'} ;
SubMenuSeparator = {'off', 'on', 'off','off','off','on'} ;
for num = 1: length( SubMenuTag )
SubMenuHandle(num) = uimenu( MenuHandle ) ;
set( SubMenuHandle(num), 'Tag', SubMenuTag{num},...
'Label', SubMenuString{num},...
'Separator', SubMenuSeparator{num},...
'Callback', SubMenuCallback{num} ) ;
end
MenuHandle = uimenu( FigureHandle, 'Label', '帮助', 'Tag', 'MenuHelp' ) ;
uimenu( MenuHandle, 'Label', '帮助', 'Tag', 'Help',...
'Callback', 'helpdlg(''游戏开始(至少点开一个格子)后,按Ctrl+Enter可以直接过关。'', ''最终秘技'')' ) ;
if ButtonColNumber < 8
TextWidth = (FigureWidth - TabSpace * 2 - TabSpace * 2 - TabSpace * 2 * 2) / 3 ;
else
TextWidth = (FigureWidth - TabSpace * 2 - TabSpace * 2 - TabSpace * 4 * 2) / 3 ;
end
TextPosition = [TabSpace*2 FigureHeight-2*TabSpace-TextHeight TextWidth TextHeight] ;
if ButtonColNumber < 8
TextFontSize = 12 ;
else
TextFontSize = 16 ;
end
TextTag = {'MineNumber', 'Face', 'Time'} ;
TextString = {'', '', '0'} ;
TextStyle = {'text', 'pushbutton', 'text'} ;
TextCallback = {'', 'saolei(''BeginMenu_Callback'', gcbo)', ''} ;
for num = 1: length(TextTag)
TempTextPosition = TextPosition ;
if ButtonColNumber < 8
TempTextPosition(1) = TempTextPosition(1) + (num-1) * (TextWidth + 2 * TabSpace) ;
else
TempTextPosition(1) = TempTextPosition(1) + (num-1) * (TextWidth + 4 * TabSpace) ;
end
UicontrolHandle = uicontrol( 'Style', TextStyle{num}, 'Position', TempTextPosition, 'Tag', TextTag{num},...
'BackgroundColor', [0.7 0.7 0.7], 'FontSize', TextFontSize, 'HorizontalAlignment', 'center',...
'String', TextString{num}, 'Callback', TextCallback{num} ) ;
if num == 2
TempTextPosition(1) = TempTextPosition(1) + (TempTextPosition(3) - 23) / 2 ;
TempTextPosition(3) = 23 ;
set( UicontrolHandle, 'Position', TempTextPosition) ;
end
end
ButtonXPos = TabSpace * 2 ;
ButtonWidth = 21 ;
ButtonHeight = 21 ;
ButtonYPos = TabSpace * 3 + ButtonHeight * ButtonRowNumber ;
ButtonPosition = [ButtonXPos ButtonYPos ButtonWidth ButtonHeight] ;
setappdata( FigureHandle, 'ButtonPosition', ButtonPosition ) ;
setappdata( FigureHandle, 'ButtonWidth', 21 + MidSpace ) ;
if ButtonColNumber == 16
x = (0: ButtonColNumber) * (21 + MidSpace) + ButtonXPos - 1 ;
else
x = (0: ButtonColNumber) * (21 + MidSpace) + ButtonXPos - 2 ;
end
y = (-ButtonRowNumber:0) * (21 + MidSpace) + ButtonYPos - 1 ;
[X, Y] = meshgrid(x, y) ;
LineRowNum = ButtonRowNumber + 1 ;
LineColNum = ButtonColNumber + 1 ;
vert = [X(:), Y(:)] ;
AreaMatrix = repmat( [1 2 2+LineRowNum 1+LineRowNum 1], LineRowNum - 1, 1 ) ;
LineAreaMatrix = AreaMatrix + repmat((LineRowNum-2:-1:0)', 1, size(AreaMatrix, 2)) ;
LineAreaMatrix = repmat(LineAreaMatrix, LineColNum - 1, 1) ;
AreaMatrix = repmat((0:LineColNum-2)*LineRowNum,(LineRowNum - 1)*5, 1) ;
AreaMatrix = AreaMatrix(:) ;
AreaMatrix = reshape(AreaMatrix, 5, []) ;
fac = LineAreaMatrix + AreaMatrix' ;
tcolor = ones(size(fac,1),3) * 0.75 ;
patch( 'Faces', fac, 'Vertices', vert,'FaceVertexCData', tcolor, 'FaceColor','flat', 'Tag', 'MainPatch',...
'ButtonDownFcn', 'saolei( ''ButtonDown_Callback'', gcbo )' );
% ------------------------------------------------------------------------
function init_FigureContent( FigureHandle ) ;
handles = guidata( FigureHandle ) ;
GameInfo = getappdata( FigureHandle, 'GameInfo' ) ;
if isempty( GameInfo )
GameInfo.RowNumber = 9 ;
GameInfo.ColNumber = 9 ;
GameInfo.MineNumber = 10 ;
end
ButtonNumber = [GameInfo.RowNumber GameInfo.ColNumber] ;
close(FigureHandle) ;
FigureHandle = figure('Visible', 'off') ;
generate_FigureContent( FigureHandle, ButtonNumber ) ;
setappdata( FigureHandle, 'GameInfo', GameInfo ) ;
movegui( FigureHandle, 'center' ) ;
set( FigureHandle, 'Visible', 'on' ) ;
handles = guihandles( FigureHandle ) ;
guidata( FigureHandle, handles) ;
set( handles.MineNumber, 'String', num2str(GameInfo.MineNumber) ) ;
BeginMenu_Callback( FigureHandle ) ;
% -------------------------------------------------------------------------
function BeginMenu_Callback( h )
handles = guidata( h ) ;
setappdata( handles.NewClearMine, 'GameIsBegin', 0 ) ;
setappdata( handles.NewClearMine, 'GameOver', 1 ) ;
setappdata( handles.NewClearMine, 'CountSecond', 1 ) ;
setappdata( handles.NewClearMine, 'MineNumberArray', [] ) ;
Matrix = com_GetFaceImage( 'Smile' ) ;
set( handles.Face, 'CData', Matrix/255 ) ;
GameInfo = getappdata( handles.NewClearMine, 'GameInfo' ) ;
set( handles.MineNumber, 'String', num2str(GameInfo.MineNumber) ) ;
cla( [handles.MainPatch, handles.MainFrame] ) ;
CData = get( handles.MainPatch, 'FaceVertexCData' ) ;
CData(:,:) = 0.75 ;
set( handles.MainPatch, 'FaceVertexCData', CData ) ;
setappdata( handles.NewClearMine, 'TextHandle', [] ) ;
% ------------------------------------------------------------------------
function EasyMenu_Callback( h )
handles = guidata( h ) ;
GameInfo.RowNumber = 9 ;
GameInfo.ColNumber = 9 ;
GameInfo.MineNumber = 10 ;
setappdata( handles.NewClearMine, 'GameInfo', GameInfo ) ;
init_FigureContent( handles.NewClearMine ) ;
% ------------------------------------------------------------------------
function NormalMenu_Callback( h )
handles = guidata( h ) ;
GameInfo.RowNumber = 16 ;
GameInfo.ColNumber = 16 ;
GameInfo.MineNumber = 40 ;
setappdata( handles.NewClearMine, 'GameInfo', GameInfo ) ;
init_FigureContent( handles.NewClearMine ) ;
% ------------------------------------------------------------------------
function HardMenu_Callback( h )
handles = guidata( h ) ;
GameInfo.RowNumber =
局外狗
- 粉丝: 78
- 资源: 1万+
最新资源
- 【肺癌检测】人工神经网络ANN肺癌检测与分割(含数据集)【含Matlab仿真 3940期】.zip
- 基于pytest框架的pytestDemo自动化测试设计源码
- MSP430常见模块应用文档和讲解资料
- 在Linux 环境下在VScode中用于调试或者测试的Code base
- 基于SSM架构的樱花诊所管理系统设计源码
- 【虹膜提取】粗精双重定位眼睛图像虹膜区域提取【含Matlab仿真 3951期】.zip
- 【虹膜检测】虹膜检测和胆固醇分析【含GUI Matlab仿真 3953期】.zip
- 【肺癌诊断】Gabor滤波器和分水岭算法肺癌诊断【含Matlab仿真 3941期】.zip
- 【裂纹识别】机器视觉玉米粒表面裂纹识别与检测(含计数)系统【含Matlab仿真 3957期】.zip
- 【图像分割】分水岭算法肺癌图像分割诊断【含Matlab仿真 3924期】.zip
- 【图像分割】极限学习机ELM道路分割【含Matlab仿真 3936期】.zip
- 【图像分割】脉冲耦合神经网络图像分割【含Matlab仿真 3925期】.zip
- 【图像拼接】ORB特征匹配+RANSAC滤除离群点图像拼接【含Matlab仿真 3761期】.zip
- 【图像隐写】混沌加密的奇异值分解SVD灰色图像信息隐写(水印嵌入提取 含NC)【含Matlab仿真 3896期】.zip
- 【图像隐写】空间域LSB数字图像水印隐写(含PSNR MSE)【含Matlab仿真 3938期】.zip
- 【图像隐写】离散余弦变换DCT彩色图像信息隐写(文本信息嵌入提取)【含Matlab仿真 3885期】.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0