日期:2008-08-30  浏览次数:21007 次

<HTML>
<HEAD>
<TITLE>JavaScript 地雷</TITLE>

<style>

input.no {
background-color:eeeeee;
border:none;
width:20;
height:20;
color:blue;
}
input.ye {
background-color:eeeeee;
border:none;
width:20;
height:20;
color:red;
}
input {
width:20;
height:20;
color:red;
}
input.mode0 {
width:50;
height:30;
border-style:inset
}
input.mode1 {
width:50;
height:30;
COLOR:GREEN;
}
</style>
</HEAD>
<BODY BGCOLOR="#000000">
<div ID=dilei style="position:absolute;left:0;top:5">
<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0>
  <SCRIPT LANGUAGE="JavaScript">
<!--
var x,y=0;
while(document.write("<tr>"),y++<20)
for(x=0;x++<20;document.write("<td ><font size=-5><input ID="+x+"_"+y+" type=button>"))
;

//-->
</SCRIPT>
</TABLE>
</div>
<div ID=ToolBar style="position:absolute;top:5;left:401;/*height:300;*/background-color:green;width:200">
<input id=Mode type=button value="挖雷" class=mode1  onclick="javascript: modeTab();"><nobr><span id=modenow style="color:blue">现在可以揭开方块</span>
</div>
</BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--//34
var Row,Col,i=0;
var RowSize=20,ColSize=20;
var mineNum=45;  //地雷数
var mode=1;


var mineX=new Array(mineNum), mineY=new Array(mineNum);
var Mine= new Array(RowSize),Decouv= new Array(RowSize);
for(i=0;i<20;i++){
  Mine[i]=new Array(ColSize);
  Decouv[i]= new Array(ColSize);
}


//初始化

for (Row=1;Row<=RowSize;Row++) {  
for (Col=1;Col<=ColSize;Col++) {  
Mine[Row-1][Col-1]=0;  
Decouv[Row-1][Col-1]=0;  
}  
};  
//布地雷 Math.random( )
i=0;
while (i<mineNum){
mineX[i]=Math.round(Math.random()*1000)%RowSize;
mineY[i]=Math.round(Math.random()*1000)%ColSize;
if(Mine[mineX[i]][mineY[i]]==9) continue;
Mine[mineX[i]][mineY[i]]=9;
Decouv[mineX[i]][mineY[i]]=9;
i++;
}
for(i=0;i<mineNum;i++){
for(j=1;j<=8;j++){
switch(j){
case 1:
divIndexX=mineX[i]-1;divIndexY=mineY[i]-1;
break;
case 2:
divIndexX=mineX[i]-1;divIndexY=mineY[i];
break;
case 3:
divIndexX=mineX[i]-1;divIndexY=mineY[i]+1;
break;
case 4:
divIndexX=mineX[i];divIndexY=mineY[i]-1;
break;
case 5:
divIndexX=mineX[i];divIndexY=mineY[i]+1;
break;
case 6:
divIndexX=mineX[i]+1;divIndexY=mineY[i]-1;
break;
case 7:
divIndexX=mineX[i]+1;divIndexY=mineY[i];
break;
case 8:
divIndexX=mineX[i]+1;divIndexY=mineY[i]+1;
}
if(divIndexX<0||divIndexY<0||divIndexX>=RowSize||divIndexY>=ColSize) continue;
Decouv[divIndexX][divIndexY]+=1;
Mine[divIndexX][divIndexY]=Decouv[divIndexX][divIndexY];
}
}
//模式切换

function modeTab(){
if(mode==1){
mode=0;
document.all("Mode").className="mode0";
document.all("Mode").value="探测";<