⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 拿matlab的gui来扫个雷.txt

📁 用matlab 实现的扫雷程序
💻 TXT
📖 第 1 页 / 共 4 页
字号:
            end
        end
    end
end
UnionIndex = UnionIndex( ~isinf(UnionIndex) ) ;
setappdata( handles.ClearMine, 'SafeIndex', SafeIndex ) ;
setappdata( handles.ClearMine, 'UnionIndex', UnionIndex ) ;

% 保存剩余非雷格子序号
SolveArray = 1: numel(MineNumberArray) ;
SolveArray = setdiff(SolveArray, UsefulIndex) ;
setappdata( handles.ClearMine, 'SolveArray', SolveArray ) ;



% -----------------------------------------------------------------------
function BeginCalculate_Callback( h ) 

handles = guidata( h ) ;

CountSecond = getappdata( handles.ClearMine, 'CountSecond' ) ;
if isempty(CountSecond)
    CountSecond = 0 ;
end
while(1)    
    PassTime = sprintf('%d',ceil(CountSecond)) ;
    pause(1) ;
    if ishandle( handles.Time )
        GameOver = getappdata( handles.ClearMine, 'GameOver' ) ;
        if isempty(GameOver)
            setappdata( handles.ClearMine, 'GameOver', 0 ) ;
        end
        if GameOver == 1
            break ;
        end
        CountSecond = CountSecond + 1 ;
        set( handles.Time, 'String', PassTime ) ;        
        setappdata( handles.ClearMine, 'CountSecond', CountSecond ) ;
    else
        break
    end    
end



% -------------------------------------------------------------------------
function CustomMenu_Callback( h )

handles = guidata( h ) ;

GameInfo = getappdata( handles.ClearMine, 'GameInfo' ) ;

if isempty(GameInfo)
    GameInfo.RowNumber = 10 ;
    GameInfo.ColNumber = 10 ;
    GameInfo.MineNumber = 10 ;
end

RowNumber = GameInfo.RowNumber ;
ColNumber = GameInfo.ColNumber ;
MineNumber = GameInfo.MineNumber ;

FigureHandle = figure( 'Name', '自定义雷区', 'Menubar', 'none', 'WindowStyle', 'modal',...
    'NumberTitle', 'off', 'Position', [300 300 130 100], 'Resize', 'off', 'Visible', 'off' );

setappdata( FigureHandle, 'PassHandle', handles.ClearMine ) ;

uicontrol( 'sty', 'text', 'str', '高度', 'pos', [10 70 30 20] ) ;
uicontrol( 'sty', 'text', 'str', '宽度', 'pos', [10 40 30 20] ) ;
uicontrol( 'sty', 'text', 'str', '雷数', 'pos', [10 10 30 20] ) ;
uicontrol( 'sty', 'edit', 'tag', 'height', 'str', num2str(RowNumber), 'pos', [50 70 30 20] ) ;
uicontrol( 'sty', 'edit', 'tag', 'width', 'str', num2str(ColNumber), 'pos', [50 40 30 20] ) ;
uicontrol( 'sty', 'edit', 'tag', 'number', 'str', num2str(MineNumber), 'pos', [50 10 30 20] ) ;
uicontrol( 'str', '确定', 'pos', [90 70 30 20],...
    'cal', ['RowNumber = str2num(get(findobj(''tag'', ''height''), ''str''));',...
        'ColNumber = str2num(get(findobj(''tag'', ''width''), ''str''));',...
        'MineNumber = str2num(get(findobj(''tag'', ''number''), ''str''));',...
        '[Msg, status] = Game_ClearMine( ''CheckDefineValid'', RowNumber, ColNumber, MineNumber);',...
        'if status==0,warndlg(Msg),end;',...
        'PassHandle = getappdata( gcf, ''PassHandle'' );',...
        'GameInfo.RowNumber=RowNumber;GameInfo.ColNumber=ColNumber;GameInfo.MineNumber=MineNumber;',...
        'setappdata( PassHandle, ''GameInfo'', GameInfo);',...   
        'close(gcf);',...
        'Game_ClearMine( ''init_FigureContent'', PassHandle );'] ) ;
uicontrol( 'str', '取消', 'pos', [90 10 30 20], 'cal', 'close(gcf)' ) ;

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




% -------------------------------------------------------------------------
function  [Msg, status] = CheckDefineValid( RowNumber, ColNumber, MineNumber) 

status = 0 ;
Msg = '' ;
if isempty(RowNumber) | RowNumber <= 0 | length(RowNumber) > 1
    Msg = '无效的高度' ;
    return 
end

if isempty(ColNumber) | ColNumber <= 0 | length(ColNumber) > 1
    Msg = '无效的宽度' ;
    return 
end

if isempty(MineNumber) | MineNumber <= 0 | length(MineNumber) > 1 
    Msg = '无效的雷数' ;
    return 
end

if  RowNumber < 5 |  RowNumber > 20
    Msg = '高度必须在5到20间' ;
    return 
end

if  ColNumber < 5 |  ColNumber > 40 
    Msg = '宽度必须在5到40间' ;
    return 
end

if  MineNumber >= ColNumber*RowNumber
    Msg = '雷数大于等于格子总数' ;
    return 
end

status = 1 ;


% -------------------------------------------------------------------------
function Matrix = com_GetMineImage

Matrix = ones(21,21) * 0.75 ;
Matrix(6:15,6:15) = 0 ;
Matrix([5,16],8:13) = 0 ;
Matrix(8:13,[5,16]) = 0 ;
Matrix([4,17],10:11) = 0 ;
Matrix([10,11],4:17) = 0 ;
Matrix = repmat( Matrix, [1,1,3] ) ;


% -------------------------------------------------------------------------
function Matrix = com_GetFlagImage

Matrix = ones(21,21) * 0.75 ;
Matrix(4:18,9:10) = 1  ;
Matrix([5,9],11) = 1 ;
Matrix([6,8],[11:13]) = 1 ;
Matrix(7,10:15) = 1 ;

Matrix2 = Matrix ;
Matrix2(Matrix2 == 1) = 0 ;

Matrix(:,:,2) = Matrix2 ;
Matrix(:,:,3) = Matrix2 ;


% -------------------------------------------------------------------------
function Matrix = com_GetFaceImage( Type )

if strcmp( Type, 'Smile' )
    Matrix(:,:,1) = [[
            255   255   255   255   255   255   255   255   255   255   255   255   255
            255   255   255   255   255   255   255   255   255   255   255   255   255
            255   255   192   192   192   192   192   192   192   192   192   192   192
            255   255   192   192   192   192   192   192   192   192   192   192   192
            255   255   192   192   192   192   192   192   192   192     0     0     0
            255   255   192   192   192   192   192   192     0     0   255   255   255
            255   255   192   192   192   192   192     0   255   255   255   255   255
            255   255   192   192   192   192     0   255   255   255   255   255   255
            255   255   192   192   192     0   255   255   255   255   255   255   255
            255   255   192   192   192     0   255   255   255     0     0   255   255
            255   255   192   192     0   255   255   255   255     0     0   255   255
            255   255   192   192     0   255   255   255   255   255   255   255   255
            255   255   192   192     0   255   255   255   255   255   255   255   255
            255   255   192   192     0   255   255   255   255   255   255   255   255
            255   255   192   192     0   255   255   255     0   255   255   255   255
            255   255   192   192   192     0   255   255   255     0   255   255   255
            255   255   192   192   192     0   255   255   255   255     0     0     0
            255   255   192   192   192   192     0   255   255   255   255   255   255
            255   255   192   192   192   192   192     0   255   255   255   255   255
            255   255   192   192   192   192   192   192     0     0   255   255   255
            255   255   192   192   192   192   192   192   192   192     0     0     0
            255   255   192   192   192   192   192   192   192   192   192   192   192
            255   192   128   128   128   128   128   128   128   128   128   128   128
        ],  [
            255   255   255   255   255   255   255   255   255   255
            255   255   255   255   255   255   255   255   255   192
            192   192   192   192   192   192   192   192   192   128
            192   192   192   192   192   192   192   192   192   128
            0     0   192   192   192   192   192   192   192   128
            255   255     0     0   192   192   192   192   192   128
            255   255   255   255     0   192   192   192   192   128
            255   255   255   255   255     0   192   192   192   128
            255   255   255   255   255   255     0   192   192   128
            255     0     0   255   255   255     0   192   192   128
            255     0     0   255   255   255   255     0   192   128
            255   255   255   255   255   255   255     0   192   128
            255   255   255   255   255   255   255     0   192   128
            255   255   255   255   255   255   255     0   192   128
            255   255   255     0   255   255   255     0   192   128
            255   255     0   255   255   255     0   192   192   128
            0     0   255   255   255   255     0   192   192   128
            255   255   255   255   255     0   192   192   192   128
            255   255   255   255     0   192   192   192   192   128
            255   255     0     0   192   192   192   192   192   128
            0     0   192   192   192   192   192   192   192   128
            192   192   192   192   192   192   192   192   192   128
            128   128   128   128   128   128   128   128   128   128]];
    
    Matrix(:,:,2) = [[
            255   255   255   255   255   255   255   255   255   255   255   255   255
            255   255   255   255   255   255   255   255   255   255   255   255   255
            255   255   192   192   192   192   192   192   192   192   192   192   192
            255   255   192   192   192   192   192   192   192   192   192   192   192
            255   255   192   192   192   192   192   192   192   192     0     0     0
            255   255   192   192   192   192   192   192     0     0   255   255   255
            255   255   192   192   192   192   192     0   255   255   255   255   255
            255   255   192   192   192   192     0   255   255   255   255   255   255
            255   255   192   192   192     0   255   255   255   255   255   255   255
            255   255   192   192   192     0   255   255   255     0     0   255   255
            255   255   192   192     0   255   255   255   255     0     0   255   255
            255   255   192   192     0   255   255   255   255   255   255   255   255
            255   255   192   192     0   255   255   255   255   255   255   255   255
            255   255   192   192     0   255   255   255   255   255   255   255   255
            255   255   192   192     0   255   255   255     0   255   255   255   255
            255   255   192   192   192     0   255   255   255     0   255   255   255
            255   255   192   192   192     0   255   255   255   255     0     0     0
            255   255   192   192   192   192     0   255   255   255   255   255   255
            255   255   192   192   192   192   192     0   255   255   255   255   255
            255   255   192   192   192   192   192   192     0     0   255   255   255
            255   255   192   192   192   192   192   192   192   192     0     0     0
            255   255   192   192   192   192   192   192   192   192   192   192   192
            255   192   128   128   128   128   128   128   128   128   128   128   128
        ],[
            255   255   255   255   255   255   255   255   255   255
            255   255   255   255   255   255   255   255   255   192
            192   192   192   192   192   192   192   192   192   128
            192   192   192   192   192   192   192   192   192   128
            0     0   192   192   192   192   192   192   192   128
            255   255     0     0   192   192   192   192   192   128
            255   255   255   255     0   192   192   192   192   128
            255   255   255   255   255     0   192   192   192   128
            255   255   255   255   255   255     0   192   192   128
            255     0     0   255   255   255     0   192   192   128
            255     0     0   255   255   255   255     0   192   128
            255   255   255   255   255   255   255     0   192   128
            255   255   255   255   255   255   255     0   192   128
            255   255   255   255   255   255   255     0   192   128
            255   255   255     0   255   255   255     0   192   128
            255   255     0   255   255   255     0   192   192   128

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -