分享
 
 
 

(Javascript醒目)在网页上写个扫雷吧:-D

王朝java/jsp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head>

<title></title>

<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">

<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">

<script id="clientEventHandlersJS" language="javascript">

<!--

/*

***********************************************************

* Web 扫雷 v2.1

***********************************************************

* Copyright (C) 2004 Zhong Weixiao

*

* 本软件为免费软件

* 您可以自由转载,但是转载时必须保留作者信息

*

* Bug 报告和技术支持

* 您可以发送邮件到zhongwx@gmail.com

* 或者通过Msn Messenger帐号 xwgnohz@hotmail.com 与作者联系

***********************************************************

*/

/*

*******************************************************************

* Web MineSweeper v2.1

*******************************************************************

* Copyright (C) 2004 Zhong Weixiao

*

* This program is free software;

* you can redistribute it, but you MUST keep the author information

*

* Support can be sent to:

* zhongwx@gmail.com

*******************************************************************

*/

var cells = new Array(); //all cells list

var Bombs = 10; //bomb number

var Map = 10; //map size

var MaxNumber = 1000; //a magic number to indicate bomb

// call by DclickIt

// check double click in opened cell

function isSetColor(i)

{

if((document.getElementById("Dcell"+i)).style.background=="#00ccff") {

return 1;

}

return 0;

}

// double click a cell

function DclickIt(i)

{

if((document.getElementById("Dcell"+i)).style.background=="#cccccc") {

return;

}

if (cells[i] == 0) {

return;

}

var count=0;

if (i%Map == 0) //first col

{

if (i-Map<0) { // first row

if (count + isSetColor(i+1) + isSetColor(i+Map) + isSetColor(i+Map+1) == cells[i])

{

if (isSetColor(i+1)==0)

if (clickIt(i+1)==1) return;

if (isSetColor(i+Map)==0)

if (clickIt(i+Map)==1) return;

if (isSetColor(i+Map+1)==0)

if (clickIt(i+Map+1)==1) return;

}

}

else if (i+Map>(Map*Map-1)) { //last row

if (isSetColor(i+1) + isSetColor(i-Map) + isSetColor(i-Map+1) == cells[i])

{

if (isSetColor(i+1)==0)

if (clickIt(i+1)==1) return;

if (isSetColor(i-Map)==0)

if (clickIt(i-Map)==1) return;

if (isSetColor(i-Map+1)==0)

if (clickIt(i-Map+1)==1) return;

}

}

else{

if (isSetColor(i+1) + isSetColor(i-Map) + isSetColor(i-Map+1) + isSetColor(i+Map) + isSetColor(i+Map+1) == cells[i]){

if (isSetColor(i+1)==0)

if (clickIt(i+1)==1) return;

if (isSetColor(i-Map)==0)

if (clickIt(i-Map)==1) return;

if (isSetColor(i-Map+1)==0)

if (clickIt(i-Map+1)==1) return;

if (isSetColor(i+Map)==0)

if (clickIt(i+Map)==1) return;

if (isSetColor(i+Map+1)==0)

if (clickIt(i+Map+1)==1) return;

}

}

}

else if (i%Map == Map-1) //last col

{

if (i-Map<0) { // first row

if (count + isSetColor(i-1) + isSetColor(i+Map) + isSetColor(i+Map-1) == cells[i])

{

if (isSetColor(i-1)==0)

if (clickIt(i-1)==1) return;

if (isSetColor(i+Map)==0)

if (clickIt(i+Map)==1) return;

if (isSetColor(i+Map-1)==0)

if (clickIt(i+Map-1)==1) return;

}

}

else if (i+Map>(Map*Map-1)) { //last row

if (isSetColor(i-1) + isSetColor(i-Map) + isSetColor(i-Map-1) == cells[i])

{

if (isSetColor(i-1)==0)

if (clickIt(i-1)==1) return;

if (isSetColor(i-Map)==0)

if (clickIt(i-Map)==1) return;

if (isSetColor(i-Map-1)==0)

if (clickIt(i-Map-1)==1) return;

}

}

else{

if (isSetColor(i-1) + isSetColor(i-Map) + isSetColor(i-Map-1) + isSetColor(i+Map) + isSetColor(i+Map-1) == cells[i]){

if (isSetColor(i-1)==0)

if (clickIt(i-1)==1) return;

if (isSetColor(i-Map)==0)

if (clickIt(i-Map)==1) return;

if (isSetColor(i-Map-1)==0)

if (clickIt(i-Map-1)==1) return;

if (isSetColor(i+Map)==0)

if (clickIt(i+Map)==1) return;

if (isSetColor(i+Map-1)==0)

if (clickIt(i+Map-1)==1) return;

}

}

}

else

{

if (i-Map<0) { // first row

if (isSetColor(i-1) + isSetColor(i+1) + isSetColor(i+Map) + isSetColor(i+Map-1) + isSetColor(i+Map+1) == cells[i]){

if (isSetColor(i-1)==0)

if (clickIt(i-1)==1) return;

if (isSetColor(i+1)==0)

if (clickIt(i+1)==1) return;

if (isSetColor(i+Map)==0)

if (clickIt(i+Map)==1) return;

if (isSetColor(i+Map-1)==0)

if (clickIt(i+Map-1)==1) return;

if (isSetColor(i+Map+1)==0)

if (clickIt(i+Map+1)==1) return;

}

}

else if (i+Map>(Map*Map-1)) { //last row

if (isSetColor(i-1) + isSetColor(i+1) + isSetColor(i-Map) + isSetColor(i-Map-1) + isSetColor(i-Map+1) == cells[i]){

if (isSetColor(i-1)==0)

if (clickIt(i-1)==1) return;

if (isSetColor(i+1)==0)

if (clickIt(i+1)==1) return;

if (isSetColor(i-Map)==0)

if (clickIt(i-Map)==1) return;

if (isSetColor(i-Map-1)==0)

if (clickIt(i-Map-1)==1) return;

if (isSetColor(i-Map+1)==0)

if (clickIt(i-Map+1)==1) return;

}

}

else{

if (isSetColor(i-1) + isSetColor(i+1) + isSetColor(i-Map) + isSetColor(i-Map-1) + isSetColor(i-Map+1)+ isSetColor(i+Map) + isSetColor(i+Map-1) + isSetColor(i+Map+1) == cells[i]){

if (isSetColor(i-1)==0)

if (clickIt(i-1)==1) return;

if (isSetColor(i+1)==0)

if (clickIt(i+1)==1) return;

if (isSetColor(i-Map)==0)

if (clickIt(i-Map)==1) return;

if (isSetColor(i-Map-1)==0)

if (clickIt(i-Map-1)==1) return;

if (isSetColor(i-Map+1)==0)

if (clickIt(i-Map+1)==1) return;

if (isSetColor(i+Map)==0)

if (clickIt(i+Map)==1) return;

if (isSetColor(i+Map-1)==0)

if (clickIt(i+Map-1)==1) return;

if (isSetColor(i+Map+1)==0)

if (clickIt(i+Map+1)==1) return;

}

}

}

}

function RclickIt(numb)

{

if ( (document.getElementById("Dcell"+numb)).style.background=="#ffffff" ) {

event.cancelBubble=true;

event.returnValue=false;

return false;

}

(document.getElementById("Dcell"+numb)).style.background="#00CCFF";

if (checkResult() == 1)

{

alert("You Win!");

init();

}

//alert( (document.getElementById("Dcell"+numb)).style.background );

event.cancelBubble=true;

event.returnValue=false;

return false;

}

// check the result after right click

function checkResult()

{

for(var i=0;i<Map*Map;i++)

{

if (cells[i] == MaxNumber)

{

if( (document.getElementById("Dcell"+i)).style.background != "#00ccff" )

{

return 0;

}

}

else

{

if( (document.getElementById("Dcell"+i)).style.background == "#00ccff" )

{

return 0;

}

}

}

return 1;

}

// click to open a cell

function clickIt(numb){

//

if ((document.getElementById("Dcell"+numb)).style.background=="#ffffff")

return;

//alert(numb);

if (cells[numb] == MaxNumber)

{

displayAll();

(document.getElementById("Dcell"+numb)).style.background="#FF0000";

alert("You Lost!");

Button_Start_onclick();

return 1;

}

else

{

displayOne(numb);

if (cells[numb] == 0) {

relation(numb);

}

return 0;

}

return 0;

//(document.getElementById("Dcell"+i))

}

// open a cell

function displayOne(i)

{

if(cells[i] == 0)

{

(document.getElementById("Dcell"+i)).innerHTML = "&nbsp;";

(document.getElementById("Dcell"+i)).style.background="#FFFFFF";

}else{

(document.getElementById("Dcell"+i)).innerHTML = cells[i];

(document.getElementById("Dcell"+i)).style.background="#FFFFFF";

}

}

// open all cells because you lost

function displayAll()

{

//display

for(var i=0;i<Map*Map;i++)

{

if(cells[i] ==MaxNumber) {

(document.getElementById("Dcell"+i)).innerHTML = "X";

(document.getElementById("Dcell"+i)).style.background="#CC9900";

} else if (cells[i] == 0) {

(document.getElementById("Dcell"+i)).innerHTML = "&nbsp;";

} else{

(document.getElementById("Dcell"+i)).innerHTML = cells[i];

}

}

}

// a function to check the a cell can be open automatically

function doAgin(i)

{

if(cells[i] == 0){

//if (( document.getElementById("Dcell"+(i)) ).innerHTML != "0"){

if (( document.getElementById("Dcell"+(i)) ).style.background!="#ffffff"){

displayOne(i);

relation(i);

}

}

else

{

displayOne(i);

}

}

// check all neighbor cell can be open automatically

function relation(i)

{

if (i%Map == 0) //first col

{

if (i-Map<0) { // first row

doAgin(i+1);

doAgin(i+Map);

doAgin(i+Map+1);

}

else if (i+Map>(Map*Map-1)) { //last row

doAgin(i+1);

doAgin(i-Map);

doAgin(i-Map+1);

}

else{

doAgin(i-Map);

doAgin(i+1);

doAgin(i+Map);

doAgin(i+Map+1);

doAgin(i-Map+1);

}

}

else if (i%Map == Map-1) //last col

{

if (i-Map<0) { // first row

doAgin(i-1);

doAgin(i+Map);

doAgin(i+Map-1);

}

else if (i+Map>(Map*Map-1)) { //last row

doAgin(i-1);

doAgin(i-Map);

doAgin(i-Map-1);

}

else{

doAgin(i-Map);

doAgin(i-1);

doAgin(i+Map);

doAgin(i+Map-1);

doAgin(i-Map-1);

}

}

else

{

if (i-Map<0) { // first row

doAgin(i-1);

doAgin(i+1);

doAgin(i+Map);

doAgin(i+Map+1);

doAgin(i+Map-1);

}

else if (i+Map>(Map*Map-1)) { //last row

doAgin(i-1);

doAgin(i+1);

doAgin(i-Map);

doAgin(i-Map+1);

doAgin(i-Map-1);

}

else{

doAgin(i+Map);

doAgin(i-1);

doAgin(i+1);

doAgin(i-Map);

doAgin(i-Map+1);

doAgin(i-Map-1);

doAgin(i+Map+1);

doAgin(i+Map-1);

}

}

}

// init map

function init()

{

var strtable = "<TABLE id='Table1' cellSpacing='0' cellPadding='0' width='" + 20*Map + "' border='1'>"

for(var m=0;m<Map;m++)

{

strtable+="<TR>"

for(var n=0;n<Map;n++)

{

strtable+="<TD align='center' width='40' id='Dcell" + (m*Map+n) + "' onclick=\"clickIt(" + (m*Map+n) + ")\" oncontextmenu=\"RclickIt(" + (m*Map+n) + ")\" ondblclick=\"DclickIt(" + (m*Map+n) + ")\">&nbsp;&nbsp;</TD>"

}

strtable+="</TR>"

}

strtable+= "<TABLE>"

//alert(strtable);

Divcells.innerHTML = strtable;

Button_Start_onclick();

}

// init bombs and all cells

function Button_Start_onclick() {

for (var i=0; i<Map*Map; i++)

{

cells[i] = 0;

}

var j=0;

while(1)

{

var randNum = (Math.floor( Math.random()*Map*Map ));

if (cells[randNum] == 0)

{

cells[randNum] = MaxNumber;

j++;

if (j==Bombs)

{

break;

}

}

}

//alert(cells)

for(var i=0;i<Map*Map;i++) {

(document.getElementById("Dcell"+i)).innerHTML = "&nbsp;";

(document.getElementById("Dcell"+i)).style.background="#CCCCCC";

}

for(var i=0;i<Map*Map;i++)

{

if (cells[i]==MaxNumber)

{

continue;

}

var count=0;

if (i % Map == 0) //first col

{

if ((i-Map) < 0) { // first row

count+=cells[i+1];

count+=cells[i+Map];

count+=cells[i+Map+1];

}

else if ((i+Map) > (Map*Map-1)) { //last row

count+=cells[i-Map];

count+=cells[i+1];

count+=cells[i+1-Map];

}

else{

count+=cells[i-Map];

count+=cells[i+1];

count+=cells[i+Map];

count+=cells[i+Map+1];

count+=cells[i+1-Map];

}

}

else if (i%Map == Map-1) //last col

{

if ((i-Map) < 0) { // first row

count+=cells[i-1];

count+=cells[i+Map];

count+=cells[i+Map-1];

}

else if ((i+Map) > (Map*Map-1)) { //last row

count+=cells[i-Map];

count+=cells[i-1];

count+=cells[i-Map-1];

}

else{

count+=cells[i-Map];

count+=cells[i-1];

count+=cells[i+Map];

count+=cells[i+Map-1];

count+=cells[i-Map-1];

}

}

else

{

if ((i-Map) < 0) { // first row

count+=cells[i-1];

count+=cells[i+1];

count+=cells[i+Map];

count+=cells[i+Map-1];

count+=cells[i+Map+1];

}

else if ((i+Map) > (Map*Map-1)) { //last row

count+=cells[i-Map];

count+=cells[i-1];

count+=cells[i+1];

count+=cells[i-Map-1];

count+=cells[i-Map+1];

}

else{

count+=cells[i-Map];

count+=cells[i-1];

count+=cells[i+1];

count+=cells[i+Map];

count+=cells[i-Map+1];

count+=cells[i-Map-1];

count+=cells[i+Map-1];

count+=cells[i+Map+1];

}

}

cells[i] = Math.floor(count/MaxNumber);

}

//displayAll(); //debug

}

// begin level

function beginLevel()

{

Bombs = 10;

Map = 10;

init();

}

// advance level

function advLevel()

{

Bombs = 40;

Map = 16;

init();

}

// custom level

function myLevel()

{

var myMap = textMapSize.value;

var myBomb = textBombNumber.value

if( (myMap)<1 || (myMap)>20 )

{

alert("地图大小应该在1-20之间");

return;

}

if( (myBomb)<1 || (myBomb)>100 )

{

alert("地雷数量应该在1-100之间");

return;

}

if (myMap*myMap < myBomb)

{

alert("天呀,你给的地图区域放不了这么多地雷呀!");

return;

}

myMap = Math.floor(myMap)

myBomb = Math.floor(myBomb)

Bombs = myBomb;

Map = myMap;

init();

}

//-->

</script>

</head>

<body onload="init()">

<table width="500" border="0" cellpadding="0" cellspacing="0">

<tr>

<td><table width="200" border="0" cellpadding="0" cellspacing="0">

<tr>

<td><input id="Button_Start12" type="button" value="初级(10X10小格 10雷)" name="Button_Start1" language="javascript" style="width:200"

onClick="return beginLevel()"></td>

</tr>

<tr>

<td><input id="Button_Start23" type="button" value="高级(16X16小格 40雷)" name="Button_Start2" language="javascript" style="width:200"

onClick="return advLevel()"></td>

</tr>

<tr>

<td><hr></td>

</tr>

<tr>

<td><div align="center">地图大小:

<input type="text" id="textMapSize3" name="textMapSize" style="width:100" value=12>

</div></td>

</tr>

<tr>

<td><div align="center">地雷数量:

<input type="text" id="textBombNumber3" name="textBombNumber" style="width:100" value=12>

</div></td>

</tr>

<tr>

<td><input id="Button_Start43" type="button" value="生成地图" name="Button_Start4" language="javascript" style="width:200"

onClick="return myLevel()"></td>

</tr>

<tr>

<td><hr></td>

</tr>

<tr>

<td><input id="Button_Start33" type="button" value="我要作弊:)" name="Button_Start3" language="javascript" style="width:200"

onClick="return displayAll()"></td>

</tr>

</table></td>

<td><br>

<table width="300" border="0" cellspacing="4">

<tr>

<td>Web 扫雷 v2.1 (2004/11/3)<br>

开发环境:Javascript<br>

运行环境:IE<br>

操作方法:左键打开,右键标示,双击打开周围未标示区域<br>

作者:Zhong Weixiao <a href="zhongwx@gmail.com

mailto:zhongwx@gmail.com">zhongwx@gmail.com</a><br>

转载请与作者联系,并保留作者信息 </td>

</tr>

</table></td>

</tr>

</table>

<br>

<div id="Divcells" style="cursor:default"></div>

</body>

</html>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有