By convention, it is necessary: gameplay: direction keys: 12345678 _ out of order, even if the game is successful! Compatible with various browsers and uses reverse order and determination to ensure certain solutions. The next step is the js Code, which does not require HTML combination. Simply put the code in the body. Click here for a direct experience. & Lt; SC... SyntaxHighlighter. all ();
By convention, it is required:
Gameplay: direction keys
Winning or losing: 12345678 _ out of order, even if it is successful!
Compatible with various browsers and uses reverse order and judgment to ensure certain solutions.
The next step is the js Code, which does not require HTML combination. Simply put the code in the body. Click here for a direct experience.
Script
Function gd (){
Var arr = [1, 2, 3, 4, 5, 6, 7, 8]. sort (function () {return Math. random ()>. 5 });
For (var I = 0, k = 0, n = arr. length; I
For (var j = I + 1; j
Arr [I]> arr [j] & (k = 1-k );
K & (I = arr [N-2]) & (arr [N-2] = arr [n-1]) & (arr [n-1] = I );
Return arr. concat (0 );
}
Function v (){
Return (d + ''). replace (0,''). replace (/(. {5}),/g, '$1 \ r \ n ');
}
Document. writeln ('');
Var p = 8, d = gd (), t1 = document. getElementById ("t1 ");
SetTimeout ('T1. value = v () ', 10 );
Document. onkeyup = function (e ){
Var k = (e | window. event). keyCode-36, q;
If (k = 1 & (p % 3 <2) | k = 3 & (p % 3> 0) | k = 2 & p <6 | k = 4 & p> 2 ){
Q = p + (k> 2? 1:-1) * (k % 2*2-3 );
D [p] = d [q], d [p = q] = 0;
If (t1.value = v (). match (/^ 1, 2, 3 [^ \ d] * 4, 5, 6 [^ 0] * $ /))
Alert ('You WIN! ');
}
}
Script
Replay supplement: I re-wrote a version of any row and column and made some enhancements. For details, see "write an M * N puzzle game with over 30 lines of js Code". choose M * nbu, instant switch, instant replay.