<HTML>
<HEAD>
<TITLE>Javascript 地雷</TITLE>
<style>
input
background
border:none;
width:
height:
color:blue;
}
input
background
border:none;
width:
height:
color:red;
}
input {
width:
height:
color:red;
}
input
width:
height:
border
}
input
width:
height:
COLOR:GREEN;
}
</style>
</HEAD>
<BODY BGCOLOR="#
<div ID=dilei style="position:absolute;left:
<TABLE BORDER=
<SCRIPT LANGUAGE="JavaScript">
<!
var x
while(document
for(x=
<input ID="+x+"_"+y+" type=button>"))
;
//
</SCRIPT>
</TABLE>
</div>
<div ID=ToolBar style="position:absolute;top:
/*height:
<input id=Mode type=button value="挖雷" class=mode
onclick="javascript: modeTab();">
<nobr>
<span id=modenow style="color:blue">現在可以揭開方塊</span>
</div>
</BODY>
<SCRIPT LANGUAGE="JavaScript">
<!
var Row
var RowSize=
var mineNum=
var mode=
var mineX=new Array(mineNum)
var Mine= new Array(RowSize)
for(i=
Mine[i]=new Array(ColSize);
Decouv[i]= new Array(ColSize);
}
//初始化
for (Row=
for (Col=
Mine[Row
Decouv[Row
}
};
//布地雷 Math
i=
while (i<mineNum){
mineX[i]=Math
mineY[i]=Math
if(Mine[mineX[i]][mineY[i]]==
Mine[mineX[i]][mineY[i]]=
Decouv[mineX[i]][mineY[i]]=
i++;
}
for(i=
for(j=
switch(j){
case
divIndexX=mineX[i]
break;
case
divIndexX=mineX[i]
break;
case
divIndexX=mineX[i]
break;
case
divIndexX=mineX[i];divIndexY=mineY[i]
break;
case
divIndexX=mineX[i];divIndexY=mineY[i]+
break;
case
divIndexX=mineX[i]+
break;
case
divIndexX=mineX[i]+
break;
case
divIndexX=mineX[i]+
}
if(divIndexX<
Decouv[divIndexX][divIndexY]+=
Mine[divIndexX][divIndexY]=Decouv[divIndexX][divIndexY];
}
}
//模式切換
function modeTab(){
if(mode==
mode=
document
document
document
}else{
mode=
document
document
document
}
}
function TRY(){
var SRCElem=event
if(SRCElem
SRCElem
if(SRCElem
tryDown(SRCElem);
}
function tryDown(Elem){
var indexX
var ss=Elem
indexX=ss[
indexY=ss[
if(mode==
if(Elem
Elem
Mine[indexX][indexY]=Decouv[indexX][indexY];
Decouv[indexX][indexY]=
return;}
else{
Elem
Decouv[indexX][indexY]=Mine[indexX][indexY];
return;
}
}
if(Decouv[indexX][indexY]>
if(Decouv[indexX][indexY]>=
return;
Elem
Elem
Decouv[indexX][indexY]=
return;
}
Elem
Elem
if(Decouv[indexX][indexY]>
Decouv[indexX][indexY]=
return;
}
if(Decouv[indexX][indexY]==
{
Elem
tryGo(indexX
}
return;
}
function TRY
Elm
}
function judge
if(Decouv[x][y]!=
return
var i=
for(i=
switch(i){//
case
divIndexX=x;divIndexY=y
break;
case
divIndexX=x
break;
case
divIndexX=x;divIndexY=y+
break;
case
divIndexX=x+
}
if(divIndexX>=
<ColSize&&Decouv[divIndexX][divIndexY]>=
return j;
}
}
return
}
function tryGo(x
var stackX=new Array()
var i=
var test=
var divIndexX=x
stackX[i]=divIndexX;stackY[i]=divIndexY;
while(test){
var Elem;
eval("Elem=document
Elem
if(Decouv[divIndexX][divIndexY]<=
Decouv[divIndexX][divIndexY]=
else{
Elem
Decouv[divIndexX][divIndexY]=
}
switch(judge
case
divIndexY
break;
case
divIndexX
break;
case
divIndexY++;
break;
case
divIndexX++;
break;
case
i=i
if(i<
return;
}
divIndexX=stackX[i];divIndexY=stackY[i];
continue;
}
i=i+
}
}
document
//
</SCRIPT>
</HTML>
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19918.html