`
fx05062219
  • 浏览: 20336 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

扫雷-打发时间

阅读更多
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<style type="text/css">
#container {
	width: 670px;
	height: 670px;
	background-color: #eeffee;
	margin: 100px auto;
}

.block {
	width: 20px;
	height: 20px;
	background-color: white;
	border: 1px solid;
	float: left;
	margin: 0 0 0 0px;
	text-align: center;
}

.block2 {
	width: 10px;
	height: 10px;
	background-color: red;
	float: left;
}

.openedBlockNormal {
	width: 20px;
	height: 20px;
	background-color: green;
	border: 1px solid;
	float: left;
	margin: 0 0 0 0px;
	text-align: center;
}

.openedBlockBomb {
	width: 20px;
	height: 20px;
	background-color: red;
	border: 1px solid;
	float: left;
	margin: 0 0 0 0px;
	text-align: center;
}

.openedBlockEmpty {
	width: 20px;
	height: 20px;
	background-color: yellow;
	border: 1px solid;
	float: left;
	margin: 0 0 0 0px;
	text-align: center;
}
</style>
<script type="text/javascript">
	var EventUtil = new Object;
	EventUtil.addEvent = function(oTarget, sEventType, funName) {
		if (oTarget.addEventListener) {//for DOM;
			oTarget.addEventListener(sEventType, funName, false);
		} else if (oTarget.attachEvent) {
			oTarget.attachEvent("on" + sEventType, funName);
		} else {
			oTarget["on" + sEventType] = funName;
		}
	};
	EventUtil.removeEvent = function(oTarget, sEventType, funName) {
		if (oTarget.removeEventListener) {//for DOM;
			oTarget.removeEventListener(sEventType, funName, false);
		} else if (oTarget.detachEvent) {
			oTarget.detachEvent("on" + sEventType, funName);
		} else {
			oTarget["on" + sEventType] = null;
		}
	};
</script>
<script type="text/javascript" src="bomb.js"></script>
</head>
<body>

<div id="containers" style="cursor: pointer"></div>
</body>
<script type="text/javascript">
	document.oncontextmenu = function() {
		return false;
	};
	var parent = document.getElementById("containers");
	var container = new Container(parent, "600px", "600px", 30, 30, 0);
	container.init();
	parent.appendChild(container.html);
</script>
</html>
// this class stands for eight direction of every block.
function Direction() {
	this.up = null;
	this.right = null;
	this.down = null;
	this.left = null;
	this.leftUp = null;
	this.rightUp = null;
	this.leftDown = null;
	this.rightDown = null;
}
// every block object stands for one block in the page.
function Block(className) {
	// blocks around.
	this.neighbors = new Direction();// [up,rightUp,right,rightDown,down,leftDown,left,leftUp]
	// html element. div used here.
	this.html = null;
	// position of this block.
	this.index = -1;
	// is this block a bomb?
	this.isBomb = false;
	// how many bombs around of this blocks.
	this.bombNumAround = -1;
	// html css style
	this.className = className;
	// is it already opened?
	this.isOpen = false;
	// do some preparation for this block;
	this.init();
}
// calculate how many bombs of around.
Block.prototype.calcBombAround = function() {
	if (!this.isBomb) {
		var bombNumber = 0;
		for ( var p in this.neighbors) {
			if (typeof (this.neighbors[p]) != "function") {
				if (null != this.neighbors[p] && this.neighbors[p].isBomb) {
					bombNumber++;
				}

			}
		}
		this.bombNumAround = bombNumber;
	}
};
// return html element.
Block.prototype.getHtml = function() {
	return this.html;
};
Block.prototype.init = function() {
	var that = this;
	// create a html element.
	this.html = document.createElement("div");
	// adding mouse over handler for this block. change background color for
	// this block.
	EventUtil.addEvent(this.html, "mouseover", function(evt) {
		var element = evt.target ? evt.target : evt.srcElement;
		element.style.backgroundColor = "#eeAB6F";
	});
	// remove the style which were added in mouseover handler.
	EventUtil.addEvent(this.html, "mouseout", function(evt) {
		var element = evt.target ? evt.target : evt.srcElement;
		element.style.backgroundColor = "";
		element.style.cursor = "";
	});
	// user click some block.
	EventUtil.addEvent(this.html, "mousedown", function(evt) {
		// right click button.
		if (evt.button == 2) {
			// if this block already indicate as a bomb, then change to normal
			// block.
			if (that.getStyle() == "openedBlockBomb") {
				that.changeStyle("block");
			} else if (that.getStyle() == "block") {
				// if this block is a normal block, indicate as a bomb.
				that.changeStyle("openedBlockBomb");
			}
		} else {// left click!
			// open it
			that.open();
		}

	});

	// setting defalut style name.
	this.changeStyle(this.className);
};
// change css style.
Block.prototype.changeStyle = function(styleName) {
	this.html.setAttribute("class", styleName);
	this.html.setAttribute("className", styleName);
};
// getting csss style
Block.prototype.getStyle = function() {
	var style = this.html.getAttribute("class");
	if (style == null || typeof (style) == "undefined") {
		style = this.html.getAttribute("className");
	}
	return style;
};
Block.prototype.open = function() {
	// if there is no bomb around, change style as an empty block.
	if (this.bombNumAround == 0) {
		this.changeStyle("openedBlockEmpty");
	} else if (this.bombNumAround > 0) {
		// setting bomb number to inner html.
		this.html.innerHTML = this.bombNumAround;
		this.changeStyle("openedBlockNormal");
	} else {
		// setting style as a bomb.
		this.changeStyle("openedBlockBomb");
		alert("bomb!!");
	}

	this.isOpen = true;
	// if 0 ==bomb number,them open other block around.
	if (this.bombNumAround == 0) {
		var directions = new Array();
		directions.push("up");
		directions.push("right");
		directions.push("down");
		directions.push("left");
		directions.push("leftUp");
		directions.push("rightUp");
		directions.push("leftDown");
		directions.push("rightDown");
		for ( var i = 0; i < directions.length; i++) {
			var blockInDirection = this.neighbors[directions[i]];
			if (null != blockInDirection
					&& typeof (blockInDirection) != "undefined"
					&& !blockInDirection.isBomb && !blockInDirection.isOpen) {
				blockInDirection.open();
			}
		}
	}
};

function Container(parent, width, heigth, rows, columns, bomb) {
	this.bombNumber = bomb;
	this.parent = parent;
	this.width = width;
	this.heigth = heigth;
	this.rows = rows;
	this.columns = columns;
	this.childObject = new Array();
	this.html = null;

}
Container.prototype.init = function() {
	this.html = document.createElement("div");
	this.html.id = "container";

	var bombArray = new Object();
	// how many bombs in all.
	var bombNumber = 100;
	var index = this.rows * this.columns + 1;
	var loopNumber = 0;
	// randomly generate the position of bomb.
	while (true) {
		if (loopNumber >= bombNumber) {
			break;
		}
		var randomBombPosition = Math.floor(Math.random() * index);
		if (bombArray[randomBombPosition] != true) {
			bombArray[randomBombPosition] = true;
			loopNumber++;
		}

	}
	// generate block objects.
	for ( var i = 0; i < this.rows * this.columns; i++) {
		var block = new Block("block");

		if (bombArray[i] == true) {
			block.isBomb = true;
		}

		this.childObject.push(block);
		this.html.appendChild(block.html);
	}
	// generating the relation of blocks. neighbors around.
	for ( var j = 0; j < this.rows * this.columns; j++) {
		block = this.childObject[j];
		block.neighbors.up = this.childObject[j - this.columns];
		block.neighbors.right = this.childObject[j + 1];
		block.neighbors.down = this.childObject[j + this.columns];
		block.neighbors.left = this.childObject[j - 1];
		block.neighbors.leftUp = this.childObject[j - this.columns - 1];
		block.neighbors.rightUp = this.childObject[j - this.columns + 1];
		block.neighbors.leftDown = this.childObject[j + this.columns - 1];
		block.neighbors.rightDown = this.childObject[j + this.columns + 1];
		if (j / this.columns == 0) {
			block.neighbors.up = null;
			block.neighbors.leftUp = null;
			block.neighbors.rightUp = null;
		} else if (j / this.columns == this.rows - 1) {
			block.neighbors.down = null;
			block.neighbors.leftDown = null;
			block.neighbors.rightDown = null;
		}
		if (j % this.columns == 0) {
			block.neighbors.left = null;
			block.neighbors.leftUp = null;
			block.neighbors.leftDown = null;
		} else if (j % this.columns == this.columns - 1) {
			block.neighbors.right = null;
			block.neighbors.rightUp = null;
			block.neighbors.rightDown = null;
		}
		block.calcBombAround();
	}

};


分享到:
评论

相关推荐

    Windows经典软件扫雷

    Windows平台经典软件扫雷,情怀软件,打发时间,发现现在系统中没有了,找到后,分享出来。最喜欢的小游戏了,消磨时间神器。

    JAVA实现GUI计时器+贪吃蛇+扫雷

    上班闲着无聊做了一个JAVA版的GUI计时器,包括了中午的打卡时间、下午的下班时间、周末的倒计时和当天已...最后 实在是闲着没事 做了贪吃蛇和扫雷两款小游戏整合到里面 闲着没事 打发打发时间 有兴趣的可以拿去参考参考

    Java版扫雷和连连看.zip

    java实现的扫雷和连连看,工作之余,写来打发闲暇时间,只实现了游戏主逻辑,计分,计时等功能,我就偷懒了,有兴趣的小伙伴可自行加入。

    saolei.rar

    自制的一个扫雷小游戏。winders 没有 自己写了一个,纯的js来实现的,初学者打发时间写到。磕磕碰碰就写了一个功能已经完成的扫雷小游戏。

    基于Andorid的电子杂志应用系统设计.zip

    基于Andorid的电子杂志应用系统设计实现源码,主要针对计算机相关专业的正在做毕设的学生和需要项目实战练习的学习者,也可作为课程设计、期末大作业。

    《网络传播技术与实务》第10章-握在手中的网络——移动通信与无线网络技术.ppt

    《网络传播技术与实务》第10章-握在手中的网络——移动通信与无线网络技术.ppt

    基于COMSOL的电磁传感器用于螺孔缺陷检测的建模与仿真

    内容概要:本文详细介绍了如何利用COMSOL Multiphysics进行螺孔缺陷检测的电磁传感器建模与仿真。首先,通过参数化建模创建带有螺纹孔的金属块,并在螺纹根部引入微小V型槽作为缺陷。接着,设置了材料属性,特别是针对缺陷区域的非线性磁导率变化进行了细致调整。然后,配置了物理场环境,包括激活AC/DC模块的电流和磁场接口,设定合适的边界条件和激励电流频率范围。网格划分采用了自适应策略,确保缺陷区域的高分辨率。求解器设置为频域稳态求解,并通过后处理展示了缺陷处的电磁场分布特性,如电场强度突变和涡流密度矢量图。此外,还讨论了实际应用中的注意事项和技术细节,如表面粗糙度的影响、频率选择以及结果验证方法。 适合人群:从事无损检测、电磁仿真研究的技术人员,以及有一定COMSOL使用经验的研发人员。 使用场景及目标:适用于工业生产中对螺孔内部微小裂纹的精确检测,旨在提高产品质量和安全性,防止因隐蔽缺陷导致的重大事故发生。 其他说明:文中提供了大量具体的MATLAB和COMSOL命令代码片段,帮助读者快速复现实验步骤并深入理解每个环节的设计意图。同时强调了实际操作中的常见陷阱及其应对措施,使读者能够更好地掌握这一复杂技术的应用要点。

    【ABB机器人】-IRB1600机器人维护信息.pdf

    【ABB机器人】-IRB1600机器人维护信息.pdf

    《计算机网络基础》第2章-数据通信.ppt

    《计算机网络基础》第2章-数据通信.ppt

    rubyinstaller-devkit-3.4.3-1-x64

    ruby-3.4.3-windows-x64安装包

    声子晶体中声表面波的光学特性及其应用研究

    内容概要:本文详细探讨了声子晶体中声表面波的光学特性。声子晶体作为一种人工复合材料,能够对弹性波(即声子)进行独特调控。文中介绍了声子晶体的基础原理,包括其周期性结构产生的带隙效应,以及声表面波与其相互作用时发生的折射、反射等光学类比现象。此外,还讨论了声子晶体在传感器、通信等领域的潜在应用,特别是在构建声表面波滤波器方面的重要意义。文章通过具体的Python和MATLAB代码展示了如何模拟声子晶体的结构和声表面波的传播特性,并解释了带隙形成的物理机制。同时,强调了几何对称性和材料参数对声波调控的影响,提出了优化仿真的方法和技术。 适合人群:从事材料科学、物理学及相关领域的研究人员,尤其是对声子晶体和声表面波感兴趣的学者和技术人员。 使用场景及目标:适用于希望深入了解声子晶体声表面波光学特性的科研工作者,旨在帮助他们掌握相关理论知识和数值模拟技能,从而应用于新型声学器件的设计和开发。 其他说明:文章提供了多个实例和代码片段,便于读者理解和实践。同时,指出了实验中常见的挑战和解决方案,如材料损耗建模、缺陷引入等,有助于提高仿真的准确性。

    机械工程电梯柔性提升系统横向-纵向耦合动力学建模与仿真:基于Galerkin法的振动控制分析及工程应用(含详细代码及解释)

    内容概要:本文详细介绍了电梯柔性提升系统横向-纵向耦合动力学建模与仿真的全过程。首先,基于能量法和Hamilton原理,建立了考虑平衡绳影响的横向-纵向耦合振动控制方程,并使用Galerkin法将其离散化为常微分方程。随后,通过Python代码实现并仿真了高速电梯参数下的振动响应,分析了平衡绳和导轨不平顺对系统振动的具体影响。研究结果显示,平衡绳能有效抑制横向振动(上行降低20%,下行降低5%),但对纵向振动有一定影响;而导轨不平顺会导致横向振动突变,对纵向振动影响较小。最终,通过数值仿真验证了论文中的主要结论,为电梯振动控制提供了理论依据和工程建议。 适合人群:具备一定力学和编程基础,对机械振动、电梯工程感兴趣的科研人员和工程师。 使用场景及目标:①理解电梯柔性提升系统的振动特性及其影响因素;②掌握基于能量法和Hamilton原理建立复杂系统动力学模型的方法;③学习如何使用Galerkin法离散化偏微分方程并进行数值仿真;④为电梯系统的设计优化提供参考,特别是平衡绳和导轨安装精度的控制。 其他说明:本文不仅提供了理论分析,还通过详细的Python代码展示了完整的仿真流程,便于读者动手实践。研究结果强调了平衡绳和导轨不平顺对电梯振动的重要影响,提出了具体的设计建议,如安装平衡绳以抑制横向振动、严格控制导轨安装精度等。此外,文中还验证了钢丝绳的安全系数,确保仿真条件符合工程实际。

    《网络规划与设计教程》第二章:网络互联技术概述.ppt

    《网络规划与设计教程》第二章:网络互联技术概述

    电力电子领域单相Boost PFC电路的双闭环控制仿真模型及其实现方法

    内容概要:本文详细介绍了单相Boost功率因数校正(PFC)电路及其双闭环控制仿真模型的设计与实现。首先阐述了单相PFC电路的基础概念,解释了Boost电路的工作原理,即通过控制开关管的导通与关断来提升输入电压并实现功率因数校正。接着讨论了在网侧220V/50Hz条件下,如何利用电压外环电流内环双闭环控制系统确保输出电压稳定性和高功率因数。文中还提供了基于Python和MATLAB/Simulink的具体代码示例,展示了如何模拟Boost电路的行为以及构建双闭环控制策略。此外,针对可能出现的问题如启动时电压超调、电流波形畸变等提出了相应的解决方案和技术细节。 适合人群:从事电力电子系统设计的研究人员、工程师和技术爱好者,尤其是那些希望深入了解PFC技术和掌握相关仿真技能的人群。 使用场景及目标:适用于需要优化电力电子设备性能的应用场合,例如工业自动化、家用电器等领域。通过学习本文的内容,读者可以更好地理解和应用单相Boost PFC电路及其双闭环控制机制,从而提高产品的效率和可靠性。 其他说明:文中不仅包含了理论性的介绍,还有大量的实战经验和技巧分享,帮助读者更快地掌握这一复杂的技术领域。同时强调了在实际工程实践中应注意的关键点,如参数选择、波形调试等方面的知识。

    黑马程序员ThreeJS 3D车展效果展示(含素材源码)

    源文件

    《计算机程序设计(C语言)》第7章-第6节-变量的存储类别.ppt

    《计算机程序设计(C语言)》第7章-第6节-变量的存储类别.ppt

    《计算机程序设计(C语言)》第4章-第2节-if语句.ppt

    《计算机程序设计(C语言)》第4章-第2节-if语句.ppt

    FPGA领域Verilog实现串口通信:兼容Xilinx与Altera的收发模块设计与应用

    内容概要:本文详细介绍了基于FPGA的串口通信模块的设计与实现,涵盖波特率生成、发送模块的状态机设计以及接收模块的抗干扰措施。特别针对Xilinx和Altera两种主流FPGA平台进行了优化,确保代码可以在不同平台上无缝运行。文中不仅提供了完整的Verilog代码片段,还分享了许多实用的调试技巧,如波特率分频系数的精确计算、采样点的选择、跨平台复位信号的处理等。此外,作者还强调了硬件连接和约束文件配置的重要性,为初学者提供了一套完整的解决方案。 适合人群:对FPGA有一定了解,希望深入掌握串口通信机制的工程师和技术爱好者。 使用场景及目标:适用于需要在FPGA平台上实现可靠串口通信的应用场合,如嵌入式系统开发、工业自动化控制等领域。通过本教程的学习,读者能够独立完成串口通信模块的设计与调试,掌握关键技术和常见问题的解决方法。 其他说明:文章附带了经过验证的实际案例和代码,便于读者进行实践操作。同时提醒开发者注意电压匹配等问题,以防止硬件损坏。

    基于FX3U PLC与RS485通信板的多品牌变频器控制方案详解

    内容概要:本文详细介绍了使用FX3U PLC配合FX3U-485BD通信板对西门子V20、台达VFD-M和三菱E700三种变频器进行通信控制的方法。涵盖了硬件配置、接线方法、参数设置、程序编写等方面的内容。文中不仅提供了具体的接线步骤,还针对不同品牌的变频器给出了详细的参数配置指导,并附有简单的梯形图程序示例,帮助读者理解和实施变频器的精确控制。此外,文章还分享了一些实用的经验技巧,如解决通信不稳定等问题的方法。 适合人群:从事工业自动化领域的工程师和技术人员,特别是那些需要集成多个品牌变频器控制系统的人群。 使用场景及目标:适用于需要通过PLC对多种品牌变频器进行集中控制的应用场合,如工厂生产线、自动化设备等。主要目标是提高系统的灵活性和可靠性,减少维护成本,提升生产效率。 其他说明:文中提供的信息和案例有助于读者快速掌握PLC与变频器之间的通信控制技术,同时也强调了实际操作过程中需要注意的一些细节问题,如接线规范、参数匹配等。

    《组态软件控制技术》第7章--报表系统.ppt

    《组态软件控制技术》第7章--报表系统.ppt

Global site tag (gtag.js) - Google Analytics