function Lock_Puzzle(action)
global fig LPG hands vdata hdata;
clc
%--------------------------------------------------------------------------
if nargin < 1,
LPG=mod(fix(10*rand(4,4)),2);
fig=figure('Name','Lock Puzzle','NumberTitle','off','Visible','off',...
'units','centimeters','position',[5 5 12 12]);
axis off;
%assigning the positions of Links
vdata=imread('Vert.tif');
hdata=imread('Hori.tif');
for ii=1:4,
for jj=1:4,
if LPG(ii,jj)==0, cdata=vdata; end
if LPG(ii,jj)==1, cdata=hdata; end
hands(ii,jj)=uicontrol('style','pushbutton','units','centimeters','CData',cdata,...
'position',[ii jj 1 1]*2,'callback',{@board,ii,jj});
end
end
%creating default buttons
uicontrol('units','centimeters',...
'position',[3 1 0.8 0.6],'string','Intro',...
'callback','Lock_Puzzle(''Intro'')',...
'interruptible','on','BackgroundColor','w');
uicontrol('units','centimeters',...
'position',[5 1 0.8 0.6],'string','New',...
'callback','Lock_Puzzle(''New'')',...
'interruptible','on','BackgroundColor','w');
uicontrol('units','centimeters',...
'position',[7 1 0.8 0.6],'string','Soln',...
'callback','Lock_Puzzle(''Soln'')',...
'interruptible','on','BackgroundColor','w');
uicontrol('units','centimeters',...
'position',[9 1 0.8 0.6],'string','Exit',...
'callback','delete(gcf)',...
'interruptible','on','BackgroundColor','w');
figure(fig);
action='Intro';
end
%--------------------------------------------------------------------------
if strcmp(action,'Intro')
msg={'Description of GAME: ',...
' ',...
'Objective: Align all the individual holders to similar position.',...
' ',...
'Move: Flip the position by clicking on the individual holders. ',...
' ',...
'Note: Both the row and column states are flipped simultaneously.'};
msgbox(msg,'Grid Lock Puzzle','help');
end
%--------------------------------------------------------------------------
if strcmp(action,'New')
LPG=mod(fix(10*rand(4,4)),2);
for ii=1:4,
for jj=1:4,
if LPG(ii,jj)==0, cdata=vdata; end
if LPG(ii,jj)==1, cdata=hdata; end
hands(ii,jj)=uicontrol('style','pushbutton','units','centimeters','CData',cdata,...
'position',[ii jj 1 1]*2,'callback',{@board,ii,jj});
end
end
end
%--------------------------------------------------------------------------
if strcmp(action,'Soln')
msg={'The problem is very similar to "Lights Out" Puzzle.',...
'"Light chasing" is best method with the possibility of many redundant steps.',...
'Start with top row till end toggling to a particular state recursively.'};
msgbox(msg,'Grid Lock Puzzle Solution','help');
end
%--------------------------------------------------------------------------