MATLAB製作GUI—掃雷遊戲的實現②

今天完成掃雷遊戲的第二小步,實現了關閉遊戲,重新開始遊戲,右鍵點擊進行標記的功能:

 

function SaoLeiGaming(tmp)

%This is the SaoLei game,that we used to played in our childhood.
%Author:等等登登-ande
%Email:[email protected]

if nargin==0
    tmp = 'inital';
    NumButton = 12;
end
switch(tmp)
    case 'inital'
        fullsizescreen = get(0,'ScreenSize');%獲取屏幕的大小以及右下角座標
        H = figure('name','掃雷_zd',...
            'position',[fullsizescreen(3)/3,fullsizescreen(4)/3,80+35*NumButton,80+35*NumButton],...
            'Menubar','none');%創建函數句柄H
        menu1 = uimenu(H,'Text','&Game');%在H函數句柄上創建菜單Game
        uimenu(menu1,'Text','&NewGame','Accelerator','M',...
            'CallBack',[mfilename,'(''quit'');',mfilename]);%在菜單Game下創建子菜單NewGame
        uimenu(menu1,'Text','&Quit','Accelerator','Q',...
            'CallBack',[mfilename,'(''quit'')']);%在菜單Game下創建子菜單Quit
        HBOX = zeros(NumButton);
        for i = 1:NumButton
            for j = 1:NumButton
                HBOX(i,j) = uicontrol(H,'Style','pushbutton',...
                    'FontWeight','bold','FontSize',10,...
                    'position',[40+35*(i-1),40+35*(NumButton-j),35,35],...
                    'tooltipstring','This is not boom!',...
                    'ButtondownFcn','RightKey',...
                    'CallBack','LeftKey');%創建NumBotton*NumBotton個格子
            end 
        end
    case 'quit'
        closereq
end

 

function LeftKey
%左鍵觸發函數
content = get(gco,'Value')
if isequal(content,'0')
    set(gco,'Value','0');
else
    set(gco,'Value',1);
end

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章