用matlab编写的俄罗斯方块小游戏
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
用matlab编写的俄罗斯方块小游戏
?function RussiaBlock( varargin )
if nargin == 0
OldHandle = findobj( 'Type', 'figure', 'Tag', 'RussiaBlock' ) ;
if ishandle( OldHandle )
delete( OldHandle ) ;
end
FigureHandle = figure( 'Name', '俄罗斯方块MATLAB版', 'Tag', 'RussiaBlock', 'NumberTitle', 'off',...
'Menubar', 'none', 'DoubleBuffer', 'on', 'Resize', 'off', 'visible', 'on',...
'KeyPressFcn', 'RussiaBlock( ''KeyPress_Callback'', gcbo )',...
'HelpFcn', 'helpdlg(''帮不了你- -!'',''不好意思'')',...
'CloseRequestFcn', 'RussiaBlock( ''CloseFigure_Callback'', gcbo )' ) ;
generate_FigureContent( FigureHandle ) ;
init_FigureContent( FigureHandle ) ;
set( FigureHandle, 'Visible', 'on' ) ;
elseif ischar( varargin{1} )
feval( varargin{:} ) ;
end
% -------------------------------------------------------------------------
function generate_FigureContent( FigureHandle )
TabSpace = 30 ;
BlockWidth = 20 ;
BlockHeight = 20 ;
FigureWidth = BlockWidth * (12 + 1) + TabSpace * 7;
FigureHeight = 500 ;
set( FigureHandle, 'Position', [0 0 FigureWidth FigureHeight] ) ;
movegui( FigureHandle, 'center' ) ;
% 创建菜单
BeginMenu = uimenu( FigureHandle, 'Label', '开始' ) ;
StartMenu = uimenu( BeginMenu, 'Label', '开始新游戏', 'Accelerator', 'N',...
-
'Callback', 'RussiaBlock( ''StartNewGame_Callback'', gcbo )');
SaveMenu = uimenu( BeginMenu, 'Label', '保存', 'Accelerator', 'S', 'Enable', 'off',...
'Separator', 'on', 'Cal', 'RussiaBlock( ''SaveGame_Callback'', gcbo )' );
LoadMenu = uimenu( BeginMenu, 'Label', '读取', 'Accelerator', 'L', 'Enable', 'off',...
'Cal', 'RussiaBlock( ''LoadGame_Callback'', gcbo )' );
QuitMenu = uimenu( BeginMenu, 'Label', '退出', 'Accelerator', 'Q', 'Separator', 'on', 'Cal',
'close(gcf)');
OperationMenu = uimenu( FigureHandle, 'Label', '功能' );
BoardConfigMenu = uimenu( OperationMenu, 'label', '键盘设置', 'Enable', 'off',...
'Cal', 'RussiaBlock( ''BoardConfig_Callback'', gcbo )' );
FigureConfigMenu = uimenu( OperationMenu, 'label', '界面设置', 'Enable', 'off',...
'Cal', 'RussiaBlock( ''FigureConfig_Callback'', gcbo )' );
HighScoreMenu = uimenu( OperationMenu, 'label', '最高记录', 'Separator', 'on',...
'Cal', 'RussiaBlock( ''HighScore_Callback'', gcbo )', 'Enable', 'off' );
GameLevelMenu = uimenu( OperationMenu, 'Label', '游戏难度',...
'Cal','RussiaBlock( ''GameLevel_Callback'', gcbo )' );
HelpMenu = uimenu( FigureHandle, 'Label', '帮助' );
AboutMenu = uimenu( HelpMenu, 'Label', '关于此软件', 'Cal', 'helpdlg(''俄罗斯方块MATLAB版'',''关于此软件…………'')');
HelpDlgMenu = uimenu( HelpMenu, 'Label', '游戏帮助', 'Separator', 'on', 'Cal', 'helpdlg(''帮不了你- -!'',''不好意思'')' );
% 创建工具条,图标可以用imread从图片读取,但图片不要太大
BeginTool = uipushtool( 'ToolTipString', '开始', 'CData', rand(16,16,3), 'Tag', 'BeginTool',...
'ClickedCallback', 'RussiaBlock( ''StartNewGame_Callback'', gcbo )' ) ;
PauseTool = uitoggletool( 'ToolTipString', '暂停', 'Tag', 'PauseTool', 'Tag', 'PauseTool',...
'CData', reshape( repmat( [1 1 0], 16, 16), [16,16,3] ),...
'ClickedCallback', 'RussiaBlock( ''PauseGame_Callback'', gcbo )' ) ;
% 创建游戏窗口
MainWindowXPos = TabSpace;
MainWindowYPos = TabSpace;
MainWindowWidth = BlockWidth * 12 ;
MainWindowHeight = BlockHeight * 22 ;
MainWindowPosition = [MainWindowXPos MainWindowYPos MainWindowWidth MainWindowHeight] ;
% 定义游戏窗口的右键菜单
AxesContextMenu = uicontextmenu( 'Tag', 'uicontextmenu' ) ;
uimenu( AxesContextMenu, 'Label', '设置窗口颜色', 'Cal',
'RussiaBlock( ''WindowColor_Callback'', gcbo )' )
uimenu( AxesContextMenu, 'Label', '设置背景图片', 'Cal',
'RussiaBlock( ''WindowPicture_Callback'', gcbo )' )
uimenu( AxesContextMenu, 'Label', '设置方块颜色', 'Cal',
'RussiaBlock( ''BlockColor_Callback'', gcbo )' )
uimenu( AxesContextMenu, 'Label', '恢复默认', 'Cal', 'RussiaBlock( ''Default_Callback'',