用matlab编写的俄罗斯方块小游戏

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

用matlab编写的俄罗斯方块小游戏

fun ctio n RussiaBlock( varargin )

if nargin == 0

OldHandle = findobj( 'Type', 'figure', 'Tag', 'RussiaBlock');

if ishandle( OldHandle )

delete( OldHa ndle );

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 )');

gen erate_FigureC ontent( FigureHa ndle );

ini t_FigureC ontent( FigureHa ndle );

set( FigureHandle, 'Visible', 'on');

elseif ischar( varargi n{1})

feval( vararg in {:});

end

% ------------------------------------------------------------------------

fun ctio n gen erate_FigureC ontent( FigureHa ndle )

TabSpace = 30 ;

BlockWidth = 20 ;

BlockHeight = 20 ;

FigureWidth = BlockWidth * (12 + 1) + TabSpace * 7;

FigureHeight = 500 ;

set( FigureHa ndle, 'Positio n', [0 0 FigureWidth FigureHeight]);

movegui( FigureHa ndle, 'cen ter');

%创建菜单

BeginMenu = uimenu( FigureHandle, 'Label',' 开始');

StartMenu = uimenu( BeginMenu, 'Label',' 开始新游戏','Accelerator', 'N',...

'Callback',

'RussiaBlock( "StartNewGame_Callback", gcbo )');

SaveMe nu = uime nu( Beg inMenu, 'Label', 'Separator', 'on', 'Cal',

'RussiaBlock( "SaveGame_Callback", gcbo )'); LoadMe nu = uime nu( Begi nMenu, 'Label',

'Cal', 'RussiaBlock( ''LoadGame_Callback'',

gcbo )');

QuitMenu = uimenu( BeginMenu, 'Label', 'close(gcf)');

Operati onMenu = uime nu( FigureHa ndle, 'Label',' BoardConfigMenu = uimenu( OperationMenu, 'label',' 'Cal', 'RussiaBlock( ''BoardConfig_Callback'', gcbo )');

FigureConfigMenu = uimenu( OperationMenu, 'label','

'Cal', 'RussiaBlock( ''FigureCo nfig_Callback", gcbo )'); HighScoreMe nu = uime nu( Operati onMenu, 'label','

'Cal', 'RussiaBlock( ''HighScore_Callback'',

gcbo )', 'Enable', 'off ); GameLevelMe nu = uime

nu( Operati onMenu, 'Label',' 'Cal','RussiaBlock( ''GameLevel_Callback'',

gcbo )'); HelpMe nu = uime nu( FigureHa ndle, 'Label', AboutMenu = uimenu( HelpMenu, 'Label','

MATLAB 版'',''关于此软件 ............ '')'); HelpDlgMenu = uimenu( HelpMenu, 'Label',

不了你--!'',''不好意思”)');

%创建工具条,图标可以用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 )');

%创建游戏窗口

Mai nWin dowXPos = TabSpace;

Mai nWin dowYPos = TabSpace;

Mai nWin dowWidth = BlockWidth * 12 ;

Mai nWin dowHeight = BlockHeight * 22 ;

Mai nWin dowPositio n = [Mai nWin dowXPos Mai nWin dowYPos Mai nWin dowWidth

Mai nWin dowHeight];

%定义游戏窗口的右键菜单

AxesContextMenu = uicontextmenu( 'Tag', 'uicontextmenu');

保存','Accelerator', 'S', 'Enable', 'off,...

读取','Accelerator', 'L', 'Enable', 'off,...

退出','Accelerator', Q, 'Separator', 'on: 'Cal', 功能');

键盘设置','Enable', 'off,...

界面设置','Enable', 'off,...

最高记录','Separator', 'on',...

游戏难度',...

帮助');

关于此软件','Cal', 'helpdlg(''俄罗斯方块

游戏帮助','Separator', 'on', 'Cal', 'helpdig (” 帮

相关文档
最新文档