日期:2014-05-16 浏览次数:20598 次
<SCRIPT LANGUAGE="JavaScript">
<!--
var RowMax = 42;//列数
var ColMax = 22;//行数
var PicMax = 26;//总图片数
var TimeMax = 60;//总时间
var OffSet = 32;//使用系统图标webdings(从asc2的32开始)
var st;//倒计时
var TmpStr = "";
var TmpObj = null;
var TmpTime = 0;
var TmpInt = 0;
var PicAry = new Array(PicMax);
var Matrix = new Array(RowMax);
for(i=0; i <RowMax; i++){
Matrix[i] = new Array(ColMax);
}
var P = new Array(4);
for(i=0; i <4; i++){
P[i] = new Object();
}
//初始化
function SetTab(){
clearInterval(st);//清除倒计时
//从input中取出设定值
TmpInt = parseInt(document.getElementById("setrow").value);//列
if(TmpInt>0 && TmpInt <41 && !(TmpInt%2)){RowMax = (TmpInt+2);}
TmpInt = parseInt(document.getElementById("setcol").value);//行
if(TmpInt>0 && TmpInt <21){ColMax = (TmpInt+2);}
TmpInt = parseInt(document.getElementById("setpic").value);//图片数
if(TmpInt>0 && TmpInt <27){PicMax = TmpInt;}
TmpInt = parseInt(document.getElementById("settime").value);//时间
if(TmpInt>0 && TmpInt <601){TimeMax = TmpInt;}
TmpTime = TimeMax;
OffSet = 40 + Math.floor( (120-PicMax) * Math.random() );//图标asc2值40~120(32~158)
//图片数组,记录每种图片总数的奇偶
for(PicNum=0; PicNum <=PicMax; PicNum++){PicAry[PicNum] = 0;}
PicNum = 0;//总数为奇数的图片种类总数
TmpInt = (RowMax-2) * (ColMax-2);//有效区域的图片总数
//绘制表格
TmpStr = " <table border=\"1\">";
for(j=0; j <ColMax; j++){
TmpStr += " <tr>";
for(i=0; i <RowMax; i++){
TmpStr += " <td onclick=\"CheckP(this,"+i+","+j+");\" width=\"32\" height=\"40\"> <font face=\"webdings\" size=\"6\" "
if(0==i || 0==j || (RowMax-1)==i || (ColMax-1)==j){
Matrix[i][j] = 0;//边界填充空单元格,连线用。
TmpStr += ">";
}
else{
TmpInt--;
Matrix[i][j] = 1 + Math.floor( PicMax * Math.random() );
if(TmpInt <PicNum){//图片配对
for(k=1; k <=PicMax; k++){
if(PicAry[k]){
Matrix[i][j] = k;
break;
}
}
}
//更新该类图片的奇偶数数组,以及单张图片总数
if(PicAry[Matrix[i][j]]){
PicAry[Matrix[i][j]] = 0;
PicNum--;
}
else{
PicAry[Matrix[i][j]] = 1;
PicNum++;
}
//填写颜色
var tmp_color = Math.floor(0xFFFF00*Matrix[i][j]/PicMax).toString(16);
TmpStr += "color=\"#";
for(k=tmp_color.length; k <6; k++) TmpStr += "0";
TmpStr += tmp_color;
TmpStr += "\">";
//添图片(webdings图标)
TmpStr += String.fromCharCode(Matrix[i][j] + OffSet);//different pics
}
TmpStr += " </font> </td>";
}
TmpStr += " </tr>";
}
TmpStr += " </table>";
TmpInt = (RowMax-2) * (ColMax-2) / 2;//剩余数量,判断结束用。
//TmpStr += " <BGSOUND volume=-1000 src=\"emc.mid\" LOOP=-1>"//背景音乐
document.getElementById("container").innerHTML = TmpStr;//输出表格
document.getElementById("