gusucode.com > 三维模仿源码程序 > 三维模仿源码程序/MathRubik2/CreateNewGame.m
function CreateNewGame(n,hAxes,bForceHistory) %CreateNewGame - to create new game % CreateNewGame(n,hAxes,bForceHistory) if ~exist('n','var')|isempty(n) n = 20; % number of random rotations end if nargin<2|isempty(hAxes)|hAxes==0 hAxes=FindRubikAxes; end Cube=get(hAxes,'UserData'); if nargin<3 bForceHistory=0; end if n<=0 Cube=InitCube(Cube); else Axe = floor(rand(n,1)*3)+1; % axes Side = 2*floor(rand(n,1)*2)-1; % sides Direction = 2*floor(rand(n,1)*2)-1; % directions for k=1:n, % random rotations Cube = RotateLayer(hAxes,Cube,Axe(k),Side(k),Direction(k),0); end if ~bForceHistory Cube.history=zeros(0,3); end end Cube.sol=[]; set(hAxes,'UserData',Cube) PlotCube(hAxes,Cube); ShowTitle(hAxes,Cube);