function Rolling_Cubes
%--------------------------------------------------------------------------
% About the game
disp(' GAME->Rolling Cubes')
disp('')
disp('DESCRIPTION:')
disp('')
disp('')
disp('1. You start with eight cubes around a center hole.')
disp('2. Each cube is black on the bottom and white on the top.')
disp('3. Roll cubes in the start position but with the white faces on bottom.')
disp('3. Click on a cube to roll it. It is possible to win in 36 moves.')
disp('')
disp('')
%disp('Press any key to continue...')
pause(2);
%--------------------------------------------------------------------------
%Game definitions
for ii=1:8
Cube(:,:,ii)=[2 2 0 0 2 2
2 0 1 1 0 2
0 1 1 1 1 0
0 1 1 1 1 0
2 0 1 1 0 2
2 2 0 0 2 2];%6X6
Face(:,:,ii)=Cube(3:4,3:4,ii);
end
Box=[1 2 3
4 0 5
6 7 8];
%--------------------------------------------------------------------------
%Game Board
Count_Move=0;
Cube_Board(Face,Box,Count_Move);
%--------------------------------------------------------------------------
%Game begins
Button=1;
while Button==1
[BXnew BYnew]=find(Box==0);
[Xnew Ynew Button] = ginput(1);
Xnew=ceil(Xnew);
Ynew=ceil(Ynew);
pick=Box(Xnew,Ynew);
if xor(BXnew==Xnew,BYnew==Ynew)
if xor(abs(Xnew-BXnew)==1,abs(Ynew-BYnew)==1)
temp=[BXnew BYnew];
BXnew=Xnew; BYnew=Ynew;
Xnew=temp(1); Ynew=temp(2);
Cube(:,:,pick)=Swap_Element(Cube(:,:,pick),Xnew,Ynew,BXnew,BYnew);
Box(BXnew,BYnew)=0;
Box(Xnew,Ynew)=pick;
Face(:,:,pick)=Cube(3:4,3:4,pick);
Count_Move=Count_Move+1;
Cube_Board(Face,Box,Count_Move);
end
end
%--------------------------------------------------------------------------
%Game ends
count=0;
for ii=1:8
Face(:,:,ii)=Cube(3:4,3:4,ii);
if Face(:,:,ii)==[0 0;0 0], count=count+1; end
end
if count==8,
hold on
text(1.75,2.5,'U won the Game','color','r','fontsize',30);
text(1.75,1.5,'Thanx 4 Playing...','color','w','fontsize',20);
break;
end
%--------------------------------------------------------------------------
end
close;