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 =
局外狗
- 粉丝: 82
- 资源: 1万+
最新资源
- 暖暖自营号卡公司介绍说明
- 基于PLC控制密码锁.doc
- AI Agent 在业务增长中的落地实践(51talk 2024)PPT(33页).pptx
- 计算机组成原理课程设计任务书 2021-3-1修订版1
- AI如何赋能职场人:大模型落地企业方法论(2024)PPT(60页).pptx
- ChatGPT课件分享PPT(37页).pptx
- 百度大模型原生安全构建之路(2024)PPT(36页).pptx
- LLM助推十倍效能提升-百度Comate赋能开发者最佳实践(2024)PPT(39页).pptx
- 订单管理(管服装加工管理)+Java+任务书
- 电商应用系统 源码+数据库+论文(JAVA+SpringBoot+Vue.JS+MySQL).zip
- 蛇年祝福生成器.exe
- InstantID:高保真人像风格化的秒级生成(小红书2024)PPT(56页).pptx
- 大模型时代推荐系统的发展路径及未来趋势(2024-10)PPT(43页).pptx
- VTK User's Guide第四版(最新的)-中文翻译版PDF
- 基于Halcon的机器视觉试验平台的设计与研究 20181126
- 大模型在办公方向的实践与思考(钉钉2024)PPT(38页).pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0