重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
并不是说JS代码可以解决!
创新互联建站是一家专业提供龙岗企业网站建设,专注与网站设计制作、成都做网站、H5高端网站建设、小程序制作等业务。10年已为龙岗众多企业、政府机构等服务。创新互联专业网站建设公司优惠进行中。
只是说他是靠JS代码来判断最小化的动作!
如果用CHROME的话,开启JS控制台,
把触发暂停的函数删除了,就可以了
扫雷在应用商店里叫Minesweeper,把鼠标放在右下角,点搜索,然后输入Minesweeper,点下面的应用商店就找到了
document.oncontextmenu=function(){return false;}
这个是当右击菜单事件。返回false就可以取消了,楼主试下吧!~谢谢
1)jquery.tableGen.js,这段js的作用是产生一个表格,表格中显示数字和雷区,调用的方法很简单,如下:
var options ={
rows:5,
cols:5,
percent:0.1
};
$("table").tableGen(options);
思路是:根据table的单元格的数目随机产生percent的雷,并填充td。然后遍历所有的td,查找周围雷的个数来填充单元格的数字
[javascript] view plain copy
var neigUp = new Array();
var neig = new Array();
var neigDw = new Array();
var cols,rows;
var table,tds;
var colors =["black","blue","red","orange","yellow","green","black","black"]; var mineNum ;
function($){
var randoms = function(max,percent){
// General digital between 0 and max num times
if(!max)max =100;
if(!percent) percent =0.1;
num = max*percent;
var i=0;
var arr = new Array();
while(inum) arr[i++]=Math.floor(Math.random()*max);
return arr;
}
$.fn.tableGen = function(options){
var setting = $.extend({
rows:10,
cols:10,
percent:0.1
},options || {}
);
rows = setting.rows;
cols = setting.cols;
neigUp = [-(cols+1),-cols,-(cols-1)];
neig =[-1,1];
neigDw =[cols-1,cols,cols+1];
var str = "";
for(var j=0;jsetting.rows;j++){
str+="tr";
for(var i=0;isetting.cols;i++){
str+="td"+i+"/td";
}
str+="/tr";
}
this.empty();
this.append(str);
$("td",this).addClass("org"); // orginal color
//fill
var arr = randoms(setting.rows*setting.cols,setting.percent);
tds = $("td",this);
mineNum = arr.length;
for(var i=0;iarr.length;i++){
$(tds[arr[i]]).addClass("mine").html("span"+"*"+"/span").find("span").css("opacity",0);
}
// add tips number to regular cells
var $this =this;
tds.each(function(i){
if($(this).text() == "*") return;
var cnt = 0;
var seq = i;
for(var i=0;ineig.length;i++){
var p = neig[i]+seq;
if(tds[p]Math.floor(p/cols) == Math.floor(seq/cols) $(tds[p]).text() == "*") cnt++;
}
for(var i=0;ineigUp.length;i++){
var p = neigUp[i]+seq;
if(tds[p]Math.floor(p/cols)+1 == Math.floor(seq/cols ) $(tds[p]).text() == "*") cnt++;
}
for(var i=0;ineigDw.length;i++){
var p = neigDw[i]+seq;
if(tds[p]Math.floor(p/cols)-1 == Math.floor(seq/cols) $(tds[p]).text() == "*") cnt++;
}
if(!cnt) { cnt = ""; colors[""]="";}
$(this).html("span"+cnt+"/span").css("color",colors[cnt]).find("span").css("opacity",0);
});
tds.addClass("mark");
} // tableGen Fn end
)(jQuery);
2)jquery.fill.js。这段代码的作用是定义点击事件,每次点击根据点击的内容来显示周围的区域或者提示成功失败
[javascript] view plain copy
(function($){
neig =[-1,1];
neigDw =[cols];
neigUp = [-cols];
var recover =function(td,table){
if(!td) return;
if(!td.attr) td = $(td);
if(!td.hasClass("mark")){
return;
}
if(td.text() == ""){
td.removeClass("mark").find("span").css("opacity",1);
}
else if(td.text() !="*"){
td.removeClass("mark").find("span").css("opacity",1);
return;
}
else if(td.text() == "*"){
return;
}
var seq = td.index("td",table);
tds = table.filter("td");
/*----------------------------*/
for(var i=0;ineig.length;i++){
var p = neig[i]+seq;
if(tds[p]Math.floor(p/cols) == Math.floor(seq/cols) $(tds[p]).text() != "*") {
recover($(tds[p]),table);
}
}
for(var i=0;ineigUp.length;i++){
var p = neigUp[i]+seq;
if(tds[p]Math.floor(p/cols)+1 == Math.floor(seq/cols ) $(tds[p]).text() != "*") {
recover($(tds[p]),table);
}
}
for(var i=0;ineigDw.length;i++){
var p = neigDw[i]+seq;
if(tds[p]Math.floor(p/cols)-1 == Math.floor(seq/cols) $(tds[p]).text() != "*") {
recover($(tds[p]),table);
}
}
}
$.fn.fill = function(){
table = $(this);
tds =$("td",table);
var mineCnt = 0;
tds.click(function(event){
if($(this).text() != "*"){
if(event.altKey){
tds.removeClass("mark").find("span").css("opacity",1);
var rs = confirm("No Bomb here !Bad Luck,Try Again?");
if(rs){
table.tableGen(options).fill();
}
return;
}
}
if($(this).text() == "*"){
$(this).removeClass("mark").find("span").css("opacity",1);
var event = event || window.event;
if(event.altKey){
mineCnt++;
if(mineCnt == mineNum){
var rs = confirm("congratulations!Try Again?");
if(rs){
table.tableGen(options).fill();
}
return;
}
return;
}
// Game over
tds.removeClass("mark").find("span").css("opacity",1);
var rs = confirm("Bomb!Bad Luck,Try Again?");
if(rs){
table.tableGen(options);
table.fill();
}
}
else if($(this).text() !="*" $(this).text() !=""){
$(this).removeClass("mark").find("span").css("opacity",1);
}
else
recover($(this),tds);
});
};
})(jQuery);
[html] view plain copy
!-- !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" ""
head
script type="text/javascript" src="jquery.js"/script
script type="text/javascript" src="jquery.table.js"/script
script type="text/javascript" src="jquery.fill.js"/script
titleMine/title
style type="text/css"
table{
table-layout: fixed;
}
.org {
border:1px solid black;
background-color:white;
overflow: hidden;
width: 10px;
height:10px;
}
.mine{
}
.mark{
background-color: orange;
}
.flag{
background: url(flag.png);
background-color: blue;
}
/style
/head
body
h3Mine Game/h3
table colspan='4'
/table
script type="text/javascript"
var options ={
rows:5,
cols:5,
percent:0.1
};
$("table").tableGen(options);
$("table").fill();
/script
/body
/html --