/p>
1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
xmlns="http://www.w3.org/1999/xhtml">
content="text/html; charset=gb2312" />
无标题文档1 | 2 | 3 | 4 | 5 |
16 | 6 | |||
15 | 7 | |||
14 | 8 | |||
13 | 12 | 11 | 10 | 9 |
请输入1-16其中一位整数,代表要停止的位置
value="12" type="text" />
type="button" value="开始" οnclick="StartGame()"
/>
function Trim(str){
return
str.replace(/(^\s*)|(\s*$)/g, "");
}
function GetSide(m,n){
//初始化数组
var arr =
[];
for(var
i=0;i
arr.push([]);
for(var
j=0;j
arr[i][j]=i*n+j;
}
}
//获取数组最外圈
var
resultArr=[];
var
tempX=0,
tempY=0,
direction="Along",
count=0;
while(tempX>=0 &&
tempX
tempY>=0 &&
tempY
count
{
count++;
resultArr.push([tempY,tempX]);
if(direction=="Along"){
if(tempX==n-1)
tempY++;
else
tempX++;
if(tempX==n-1&&tempY==m-1)
direction="Inverse"
}
else{
if(tempX==0)
tempY--;
else
tempX--;
if(tempX==0&&tempY==0)
break;
}
}
return
resultArr;
}
var index=0, //当前亮区位置
prevIndex=0, //前一位置
Speed=300, //初始速度
Time, //定义对象
arr = GetSide(5,5), //初始化数组
EndIndex=0, //决定在哪一格变慢
tb =
document.getElementByIdx_x("tb"), //获取tb对象
cycle=0, //转动圈数
EndCycle=0, //计算圈数
flag=false, //结束转动标志
quick=0; //加速
function StartGame(){
cycle=0;
flag=false;
EndIndex=Math.floor(Math.random()*16);
//EndCycle=Math.floor(Math.random()*4);
EndCycle=1;
Time =
setInterval(Star,Speed);
}
function Star(num){
//跑马灯变速
if(flag==false){
//走五格开始加速
if(quick==5){
clearInterval(Time);
Speed=50;
Time=setInterval(Star,Speed);
}
//跑N圈减速
if(cycle==EndCycle+1
&& index==EndIndex){
clearInterval(Time);
Speed=300;
flag=true;
//触发结束
Time=setInterval(Star,Speed);
}
}
if(index>=arr.length){
index=0;
cycle++;
}
//结束转动并选中号码
if(flag==true
&&
index==parseInt(Trim(document.getElementByIdx_x("txtnum").value))-1){
quick=0;
clearInterval(Time);
}
tb.rows[arr[index][0]].cells[arr[index][1]].style.border="3px solid
red";
if(index>0)
prevIndex=index-1;
else{
prevIndex=arr.length-1;
}
tb.rows[arr[prevIndex][0]].cells[arr[prevIndex][1]].style.border="3px
solid #ccc";
index++;
quick++;
}