js版扫雷实现代码 原理不错 时间:2020-05-12 人气:0 效果图:以下代码复制粘贴到记事本后保存为.html文件,打开后会出现提示,右击允许即可: 寻雷-----by 魅月 <script language="javascript"> var data=new Array( [0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,0] ); var count=0; do{ var a=1+Math.round(8*(Math.random())); var b=1+Math.round(8*(Math.random())); if(data[a][b]==0){ data[a][b]="shit"; count+=1; } }while(count<10) for(var i=1;i<10;i++){ for(var j=1;j<10;j++){ if(data[i][j]!="shit"){ var counter=0; if(data[i-1][j-1]=="shit") counter+=1; if(data[i-1][j]=="shit") counter+=1; if(data[i-1][j+1]=="shit") counter+=1; if(data[i][j-1]=="shit") counter+=1; if(data[i][j+1]=="shit") counter+=1; if(data[i+1][j-1]=="shit") counter+=1; if(data[i+1][j]=="shit") counter+=1; if(data[i+1][j+1]=="shit") counter+=1; data[i][j]=counter; } } } function pop(){ event.bubbles=true; var number=parseInt(event.srcElement.getAttribute("id")); var j=number % 10; var i=(number-j)/10; if(data[i][j]=="shit"){ alert("中雷了"); check(); return; } if(data[i][j]==0){ for(var p=i-1;p [Ctrl+A 全选 注:如需引入外部Js需刷新才能执行] 加载全部内容