<머리>
拼图 <스타일>
td.numTd{
너비 : 20px ;
높이 : 20px ;
}
div.numDiv{
너비 : 100% ;
높이: 100% ;
배경색 : #000 ;
색상 : #FFF ;
텍스트 정렬: 가운데 ;
수직 정렬 : 중간 ;
}
<스크립트>
var currPos = 9;
함수 이동(이벤트){
스위치(event.keyCode){
case 37 :
// 左键
if (currPos % 3 != 0){
var currTd = document.getElementById("numTd_" currPos);
var nextTd = document.getElementById("numTd_" (currPos 1));
var temp = nextTd.innerHTML;
nextTd.innerHTML = " ";
currTd.innerHTML = 임시;
currPos ;
}
휴식;
case 38:
// 上键
if (currPos < 7){
var currTd = document.getElementById("numTd_" currPos);
var nextTd = document.getElementById("numTd_" (currPos 3));
var temp = nextTd.innerHTML;
nextTd.innerHTML = " ";
currTd.innerHTML = 임시;
currPos = 3;
}
휴식;
case 39:
// 右键
if (currPos % 3 != 1){
var currTd = document.getElementById("numTd_" currPos);
var nextTd = document.getElementById("numTd_" (currPos - 1));
var temp = nextTd.innerHTML;
nextTd.innerHTML = " ";
currTd.innerHTML = 임시;
currPos -- ;
}
휴식;
case 40:
// 下键
if (currPos > 3){
var currTd = document.getElementById("numTd_" currPos);
var nextTd = document.getElementById("numTd_" (currPos - 3));
var temp = nextTd.innerHTML;
nextTd.innerHTML = " ";
currTd.innerHTML = 임시;
currPos -= 3;
}
휴식;
기본값:
break;
}
if (isWin()){
alert("恭喜你,过关了!");
initNums();
}
}
function isWin(){
for (i = 1; i < 9; i ){
var numTd = document.getElementById(" numTd_" i);
var numDiv = numTd.getElementsByTagName("div");
if (i != numTd.innerText){
false를 반환합니다.
}
}
true를 반환합니다.
}
function initNums(){
var numArr = new Array(1, 2, 3, 4, 5, 6, 7, 8, 9);
var newnewNumArr = new Array();
do{
var tempStr = "";
for(i in numArr){
var 플래그 = true;
do{
tempNum = numArr[parseInt(Math.random() * 100) % 9];
if (tempStr.search(tempNum) == -1){
newNumArr[i] = tempNum;
tempStr = tempNum;
플래그 = 거짓;
}
}
while(플래그);
}
}while(inverNum(newNumArr) % 2 == 0);
var len = newNumArr.length;
for(j = 0; j < len; j ){
if (newNumArr[j] != 9){
document.getElementById("numTd_" (j 1)).innerHTML = "
" newNumArr[j] "
";
}
else{
document.getElementById("numTd_" (j 1)).innerHTML = " ";
currPos = j 1;
}
}
// document.getElementById("output").innerText = newNumArr;
}
function inverNum(numArr){
var len = numArr.length;
var 개수 = 0;
for(i = 0; i for(j = i 1; j if (numArr[j] > numArr[ i]){
개수 ;
}
}
}
// Alert("逆序数: " count);
반품 횟수;
}