Code covered by the BSD License  

Highlights from
Sliding Tile Board Game

Sliding Tile Board Game

by

 

this game is prepared by Neda' Ahmad "me" and it was the matlab project

MyProject(varargin)
function varargout = MyProject(varargin)
% MYPROJECT M-file for MyProject.fig
%      MYPROJECT, by Neda' M. Khalil, creates a new MYPROJECT or raises the existing
%      singleton*.
%
%      H = MYPROJECT returns the handle to a new MYPROJECT or the handle to
%      the existing singleton*.
%
%      MYPROJECT('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in MYPROJECT.M with the given input arguments.
%
%      MYPROJECT('Property','Value',...) creates a new MYPROJECT or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before MyProject_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to MyProject_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help MyProject

% Last Modified by GUIDE v2.5 06-Aug-2010 14:12:23

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @MyProject_OpeningFcn, ...
                   'gui_OutputFcn',  @MyProject_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before MyProject is made visible.
function MyProject_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to MyProject (see VARARGIN)

% Choose default command line output for MyProject
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);
set (handles.a,'string',' ');
set (handles.b,'string' ,' ');
set (handles.c ,'string' ,' ');
set (handles.d ,'string' ,' ');
set (handles.e ,'string' ,' ');
set (handles.g ,'string' ,' ');
set (handles.f ,'string' ,' ');
set (handles.h ,'string' ,' ');
set (handles.i ,'string' ,' ');
set (handles.j ,'string' ,' ');
set (handles.k ,'string' ,' ');
set (handles.l ,'string' ,' ');
set (handles.m ,'string' ,' ');
set (handles.n ,'string' ,' ');
set (handles.o ,'string' ,' ');
set (handles.p ,'string' ,' ');

set (handles.Won,'string');
set (handles.Lose,'string');

set (handles.History,'visible','off');
set (handles.View,'visible','off');


% UIWAIT makes MyProject wait for user response (see UIRESUME)
% uiwait(handles.figure1);

handles.output = hObject;

% Update handles structure
guidata(hObject, handles);



% --- Outputs from this function are returned to the command line.
function varargout = MyProject_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


function edit_Result_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double

  
% --- Executes during object creation, after setting all properties.

function edit_Result_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
    else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


function shuffle_Callback(hObject, eventdata, handles)
 N=randperm(15);
 M= randperm(8);
 str = get(handles.choose,'string');
val = get(handles.choose,'value');
switch str{val}
    
    case 'FIFTEEN'
        
 set (handles.d,'visible','on');
 set (handles.h,'visible','on');
 set (handles.l,'visible','on');
 set (handles.p,'visible','on');
 set (handles.m,'visible','on');
 set (handles.n,'visible','on');
 set (handles.o,'visible','on');
        
 set (handles.a,'string',num2str(N(1)));
 set (handles.b,'string',num2str(N(2)));
 set (handles.c,'string',num2str(N(3)));
 set (handles.d,'string',num2str(N(4)));
 set (handles.e,'string',num2str(N(5)));
 set (handles.f,'string',num2str(N(6)));
 set (handles.g,'string',num2str(N(7)));
 set (handles.h,'string',num2str(N(8)));
 set (handles.i,'string',num2str(N(9)));
 set (handles.j,'string',num2str(N(10)));
 set (handles.k,'string',num2str(N(11)));
 set (handles.l,'string',num2str(N(12)));
 set (handles.m,'string',num2str(N(13)));
 set (handles.n,'string',num2str(N(14)));
 set (handles.o,'string',num2str(N(15)));
 set (handles.p,'string',' ');
 
 
    case 'EIGHT'
        set (handles.d,'visible','off');
        set (handles.h,'visible','off');
        set (handles.l,'visible','off');
        set (handles.p,'visible','off');
        set (handles.m,'visible','off');
        set (handles.n,'visible','off');
        set (handles.o,'visible','off');
        set (handles.a,'string',num2str(M(1)));
        set (handles.b,'string',num2str(M(2)));
        set (handles.c,'string',num2str(M(3)));
        set (handles.e,'string',num2str(M(4)));
        set (handles.f,'string',num2str(M(5)));
        set (handles.g,'string',num2str(M(6)));
        set (handles.i,'string',num2str(M(7)));
        set (handles.j,'string',num2str(M(8)));
        set (handles.k,'string',' ');
end
 


function HistoryFile_Callback(hObject, eventdata, handles)
% hObject    handle to show (see GCBO)
if ((get(handles.HistoryFile,'Value') == get(handles.View,'Max')))
   set (handles.History,'visible','on');
   set (handles.View,'visible','on');
   
else
    set (handles.History,'visible','off');
    set (handles.View,'visible','off');
end

function Help_Callback(hObject, eventdata, handles)
uiwait(msgbox('Welcome to the "fifteens" game,The purpose of the game is to arrange the squares numbering order: 1,2,3,...,15  by shifting their positions to the only available space. Only one square adjacent to the empty space can be moved at each step. Press the corresponding button to move a square with a given number.  Good luck!','help','help'))

function a_Callback(hObject, eventdata, handles)
a=get(handles.a,'string');
b=get(handles.b,'string');
e=get(handles.e,'string');
if(b==' ')
    set(handles.b,'string',a);
    set(handles.a,'string',' ');
elseif(e==' ')
    set(handles.e,'string',a);
    set(handles.a,'string',' ');
end
Win(handles);


function b_Callback(hObject, eventdata, handles)
b=get(handles.b,'string');
a=get(handles.a,'string');
f=get(handles.f,'string');
c=get(handles.c,'string');
if(c==' ')
    set(handles.c,'string',b);
    set(handles.b,'string',' ');
elseif(f==' ')
    set(handles.f,'string',b);
    set(handles.b,'string',' ');
elseif(a==' ')
    set(handles.a,'string',b);
    set(handles.b,'string',' ');
end
% Win(handles);


function c_Callback(hObject, eventdata, handles)
g=get(handles.g,'string');
c=get(handles.c,'string');
b=get(handles.b,'string');
d=get(handles.d,'string');
if (b==' ')
    set(handles.b,'string',c);
    set(handles.c,'string',' ');
elseif (g==' ')
    set(handles.g,'string',c);
    set(handles.c,'string',' ');
elseif (d==' ')
    set (handles.d,'string',c);
    set(handles.c,'string',' ');
end
    % Win(handles);

function d_Callback(hObject, eventdata, handles)
d=get(handles.d,'string');
c=get(handles.c,'string');
h=get(handles.h,'string');
if(c==' ')
    set(handles.c,'string',d);
    set(handles.d,'string',' ');
elseif(h==' ')
    set(handles.h,'string',d);
    set(handles.d,'string',' ');
end
% Win(handles);


function e_Callback(hObject, eventdata, handles)
e=get(handles.e,'string');
a=get(handles.a,'string');
f=get(handles.f,'string');
i=get(handles.i,'string');
if(a==' ')
    set(handles.a,'string',e);
    set(handles.e,'string',' ');
elseif(f==' ')
    set(handles.f,'string',e);
    set(handles.e,'string',' ');
elseif(i==' ')
    set(handles.i,'string',e);
    set(handles.e,'string',' ');
end
% Win(handles);


function f_Callback(hObject, eventdata, handles)
b=get(handles.b,'string');
e=get(handles.e,'string');
j=get(handles.j,'string');
f=get(handles.f,'string');
g=get(handles.g,'string');
if(b==' ')
    set(handles.b,'string',f);
    set(handles.f,'string',' ');
elseif(e==' ')
    set(handles.e,'string',f);
    set(handles.f,'string',' ');
elseif(g==' ')
    set(handles.g,'string',f);
    set(handles.f,'string',' ');
elseif (j==' ')
    set(handles.j,'string',f);
    set(handles.f,'string',' ');
    
end
% Win(handles);


function g_Callback(hObject, eventdata, handles)
g=get(handles.g,'string');
c=get(handles.c,'string');
k=get(handles.k,'string');
f=get(handles.f,'string');
h=get(handles.h,'string');
if (c==' ')
    set(handles.c,'string',g);
    set(handles.g,'string',' ');
elseif (k==' ')
    set(handles.k,'string',g);
    set(handles.g,'string',' ');
elseif (f==' ')
    set(handles.f,'string',g);
    set(handles.g,'string',' ');
elseif(h==' ')
    set (handles.h,'string',g);
     set(handles.g,'string',' ');
end

    
        
function h_Callback(hObject, eventdata, handles)

h=get(handles.h,'string');
d=get(handles.d,'string');
l=get(handles.l,'string');
g=get(handles.g,'string');
if(g==' ')
    set(handles.g,'string',h);
    set(handles.h,'string',' ');
elseif(l==' ')
    set(handles.l,'string',h);
    set(handles.h,'string',' ');
elseif(d==' ')
    set(handles.d,'string',h);
    set(handles.h,'string',' ');
end
% Win(handles);


function i_Callback(hObject, eventdata, handles)

j=get(handles.j,'string');
 m=get(handles.m,'string');
i=get(handles.i,'string');
e=get(handles.e,'string');

if (j==' ')
    set(handles.j,'string',i);
    set(handles.i,'string',' ');
elseif (e==' ')
    set(handles.e,'string',i);
    set(handles.i,'string',' ');
elseif (m==' ')
            set (handles.m,'string',i);
            set(handles.i,'string',' ');
 
    end
%     Win(handles);
    
    
    
function j_Callback(hObject, eventdata, handles)
j=get(handles.j,'string');
i=get(handles.i,'string');
k=get(handles.k,'string');
f=get(handles.f,'string');
n=get(handles.n,'string');
if (i==' ')
    set(handles.i,'string',j);
    set(handles.j,'string',' ');
elseif (k==' ')
    set(handles.k,'string',j);
    set(handles.j,'string',' ');
elseif (f ==' ')
    set(handles.f,'string',j);
    set(handles.j,'string',' ');
elseif(n==' ')
    set (handles.n,'string',j);
    set(handles.j,'string',' ');
end
    

function k_Callback(hObject, eventdata, handles)
g=get(handles.g,'string');
k=get(handles.k,'string');
j=get(handles.j,'string');
l=get(handles.l,'string');
o=get(handles.o,'string');

if (g==' ')
    set(handles.g,'string',k);
    set(handles.k,'string',' ');
elseif (j==' ')
    set(handles.j,'string',k);
    set(handles.k,'string',' ');
elseif(l==' ')
    set (handles.l,'string',k);
    set(handles.k,'string',' ');
elseif(o==' ')
 set (handles.o,'string',k);
 set(handles.k,'string',' ');
end
Win(handles);



function l_Callback(hObject, eventdata, handles)
l=get(handles.l,'string');
p=get(handles.p,'string');
k=get(handles.k,'string');
h=get(handles.h,'string');
if(h==' ')
    set(handles.h,'string',l);
    set(handles.l,'string',' ');
elseif(k==' ')
    set(handles.k,'string',l);
    set(handles.l,'string',' ');
elseif(p==' ')
    set(handles.p,'string',l);
    set(handles.l,'string',' ');
end
%  Win(handles);



function m_Callback(hObject, eventdata, handles)
m=get(handles.m,'string');
n=get(handles.n,'string');
i=get(handles.i,'string');
if(n==' ')
    set(handles.n,'string',m);
    set(handles.m,'string',' ');
elseif(i==' ')
    set(handles.i,'string',m);
    set(handles.m,'string',' ');
end
% Win(handles);



function n_Callback(hObject, eventdata, handles)
n=get(handles.n,'string');
j=get(handles.j,'string');
o=get(handles.o,'string');
m=get(handles.m,'string');
if(m==' ')
    set(handles.m,'string',n);
    set(handles.n,'string',' ');
elseif(o==' ')
    set(handles.o,'string',n);
    set(handles.n,'string',' ');
elseif(j==' ')
    set(handles.j,'string',n);
    set(handles.n,'string',' ');
end
% Win(handles);


function o_Callback(hObject, eventdata, handles)
o=get(handles.o,'string');
p=get(handles.p,'string');
k=get(handles.k,'string');
n=get(handles.n,'string');
if(p==' ')
    set(handles.p,'string',o);
    set(handles.o,'string',' ');
elseif(k==' ')
    set(handles.k,'string',o);
    set(handles.o,'string',' ');
elseif(n==' ')
    set(handles.n,'string',o);
    set(handles.o,'string',' ');
end
% Win(handles);



function p_Callback(hObject, eventdata, handles)
p=get(handles.p,'string');
l=get(handles.l,'string');
o=get(handles.o,'string');
if(l==' ')
    set(handles.l,'string',p);
    set(handles.p,'string',' ');
elseif(o==' ')
    set(handles.o,'string',p);
    set(handles.p,'string',' ');
  
end
 Win(handles);




function result_Callback(hObject, eventdata, handles)



function result_CreateFcn(hObject, eventdata, handles)

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function Won_Callback(hObject, eventdata, handles)


function edit_Won_Callback(hObject, eventdata, handles)


function edit_Won_CreateFcn(hObject, eventdata, handles)

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function Lose_Callback(hObject, eventdata, handles)

function edit_Lose_Callback(hObject, eventdata, handles)


function edit_Lose_CreateFcn(hObject, eventdata, handles)

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function edit_Exit_CreateFcn(hObject, eventdata, handles)

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function start_Callback(hObject, eventdata, handles)
 N=randperm(15);
 M= randperm(8);
 str = get(handles.choose,'string');
val = get(handles.choose,'value');
switch str{val}
    
    case 'FIFTEEN'
        
 set (handles.d,'visible','on');
 set (handles.h,'visible','on');
 set (handles.l,'visible','on');
 set (handles.p,'visible','on');
 set (handles.m,'visible','on');
 set (handles.n,'visible','on');
 set (handles.o,'visible','on');
        
 set (handles.a,'string',num2str(N(1)));
 set (handles.b,'string',num2str(N(2)));
 set (handles.c,'string',num2str(N(3)));
 set (handles.d,'string',num2str(N(4)));
 set (handles.e,'string',num2str(N(5)));
 set (handles.f,'string',num2str(N(6)));
 set (handles.g,'string',num2str(N(7)));
 set (handles.h,'string',num2str(N(8)));
 set (handles.i,'string',num2str(N(9)));
 set (handles.j,'string',num2str(N(10)));
 set (handles.k,'string',num2str(N(11)));
 set (handles.l,'string',num2str(N(12)));
 set (handles.m,'string',num2str(N(13)));
 set (handles.n,'string',num2str(N(14)));
 set (handles.o,'string',num2str(N(15)));
 set (handles.p,'string',' ');
 
 
    case 'EIGHT'
        set (handles.d,'visible','off');
        set (handles.h,'visible','off');
        set (handles.l,'visible','off');
        set (handles.p,'visible','off');
        set (handles.m,'visible','off');
        set (handles.n,'visible','off');
        set (handles.o,'visible','off');
        set (handles.a,'string',num2str(M(1)));
        set (handles.b,'string',num2str(M(2)));
        set (handles.c,'string',num2str(M(3)));
        set (handles.e,'string',num2str(M(4)));
        set (handles.f,'string',num2str(M(5)));
        set (handles.g,'string',num2str(M(6)));
        set (handles.i,'string',num2str(M(7)));
        set (handles.j,'string',num2str(M(8)));
        set (handles.k,'string',' ');
end
 

function choose_Callback(hObject, eventdata, handles)
% hObject    handle to choose (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

if (handles.choose)
x= xlsread('project.xls');
set(handles.text_Won,'string',num2str(x(1)));
set(handles.text_Lose,'string',num2str(x(2)));

end



function choose_CreateFcn(hObject, eventdata, handles)

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
    
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));

end

function Win(handles)
str = get(handles.choose,'string');
val = get(handles.choose,'value');
switch str{val}
    
    case 'FIFTEEN'
        
        a1=(get (handles.a,'string'));
        b1=(get (handles.b,'string'));
        c1=(get (handles.c,'string'));
        d1=(get (handles.d,'string'));
        e1=(get (handles.e,'string'));
        f1=(get (handles.f,'string'));
        g1=(get (handles.g,'string')); 
        h1=(get (handles.h,'string'));
        i1=(get (handles.i,'string'));
        j1=(get (handles.j,'string'));
        k1=(get (handles.k,'string'));
        l1=(get (handles.l,'string'));
        m1=(get (handles.m,'string'));
        n1=(get (handles.n,'string'));
        o1=(get (handles.o,'string'));
        p1=(get (handles.p,'string'));
        
if ((a1=='1')&&(b1=='2')&&(c1=='3')&&(d1=='4')&&(e1=='5')&&(f1=='6')&&(g1=='7')&&(h1=='8')&&(i1=='9')&&(j1=='10')&&(k1=='11')&&(l1=='12')&&(m1=='13')&&(n1=='14')&&(o1=='15'))
set(handles.result,'string','CONGRATULATIONS...You Win!!! This Game, Prepared By Nedaa & Submitted To Eng.Ashraf');
    
    % Sound effect for computer's victory
    y=chirp(0:0.001:1,100,1,25,'q',[],'concave');
    sound(1000./y,8192); pause(0.3);sound(100./y,8192);
elseif((a1=='1')&&(b1=='2')&&(c1=='3')&&(d1=='4')&&(e1=='5')&&(f1=='6')&&(g1=='7')&&(h1=='8')&&(i1=='9')&&(j1=='10')&&(k1=='11')&&(l1=='12')&&(m1=='15')&&(n1=='13')&&(o1=='14')) 
 set (handles.result,'string','Hard Luck...YOU LOSE!!! This Game Prepared By Nedaa And Submitted To Eng.Ashraf');    
    
       w =str2num(get(handles.text_Won,'string'));
       L= str2num(get(handles.text_Lose,'string'));
       L = L+1;
       xlswrite('project.xls',[w L]);

end
          

    case 'EIGHT'
        
        a1=(get (handles.a,'string'));
        b1=(get (handles.b,'string'));
        c1=(get (handles.c,'string'));
      
        e1=(get (handles.e,'string'));
        f1=(get (handles.f,'string'));
        g1=(get (handles.g,'string')); 
       
        i1=(get (handles.i,'string'));
        j1=(get (handles.j,'string'));
        k1=(get (handles.k,'string'));
       
  if((a1=='1')&&(b1=='2')&&(c1=='3')&&(e1=='4')&&(f1=='5')&&(g1=='6')&&(i1=='7')&&(j1=='8'))
      set (handles.result,'string','CONGRATULATIONS...You Win!!! This Game Prepared By Nedaa & Submitted To Eng.Ashraf');
      
    % Sound effect for computer's victory
    
    y=chirp(0:0.001:1,100,1,25,'q',[],'concave');
    sound(1000./y,8192); pause(0.3);sound(100./y,8192);
    
    w =str2num(get(handles.text_Won,'string'));
    L= str2num(get(handles.text_Lose,'string'));
    w = w+1;
    xlswrite('project.xls',[w L]);
       
       
  elseif((a1=='1')&&(b1=='2')&&(c1=='3')&&(e1=='4')&&(f1=='5')&&(g1=='6')&&(i1=='8')&&(j1=='7'))
    set (handles.result,'string','Hard Luck...YOU LOSE!!! This Game Prepared By Nedaa And Submitted To Eng.Ashraf');   
   
       % Sound effect for computer's victory
       y=chirp(0:0.001:1,100,1,25,'q',[],'concave');
       sound(1000./y,8192); pause(0.3);sound(100./y,8192);
       
       w =str2num(get(handles.text_Won,'string'));
       L= str2num(get(handles.text_Lose,'string'));
       L= L+1;
       
       xlswrite('project.xls',[w L]);    
       end
       
end
          


function exit_Callback(hObject, eventdata, handles)


close(handles.figure1);

function View_Callback(hObject, eventdata, handles)



Contact us