Browse Source

项目迁移

tbphp 2 years ago
commit
0482c381e1
10 changed files with 275 additions and 0 deletions
  1. 23 0
      css/common.css
  2. BIN
      images/bg.png
  3. BIN
      images/hover.png
  4. BIN
      images/l.png
  5. BIN
      images/lock.png
  6. BIN
      images/open.png
  7. BIN
      images/wrong.png
  8. 33 0
      index.html
  9. 214 0
      js/common.js
  10. 5 0
      js/jq.js

+ 23 - 0
css/common.css

@@ -0,0 +1,23 @@
+*{padding: 0px;margin: 0px;list-style: none;cursor: default;}
+#top{height: 30px;margin-top: 80px;text-align: center;}
+#top span{height: 24px;line-height: 24px;display: inline-block;cursor: pointer;color: blue;border: 1px solid #CCC;width: 40px;margin-left: 5px;margin-right: 5px;text-align: center;background-color: #FFF;}
+#top span:hover{background: #EEE;}
+#top span:active{background: #CCC;}
+#main{position: relative;border: 1px solid black;margin: 0 auto;margin-top: 10px;}
+#main ul{clear: left;height: 30px;}
+#main ul li{background: url(../images/bg.png);float: left;width: 30px;text-align: center;line-height: 30px;height: 30px;font-size: 14px;font-family: 微软雅黑;font-weight: bold;}
+#main ul li.mine{background: url(../images/l.png);}
+#main ul li.lock{background: url(../images/lock.png);}
+#main ul li.open{background: url(../images/open.png);}
+#main ul li.hover{background: url(../images/hover.png);}
+#main ul li.wrong{background: url(../images/wrong.png);}
+#main ul li.num1{color: #414fbc;}
+#main ul li.num2{color: #1e6c01;}
+#main ul li.num3{color: #a90704;}
+#main ul li.num4{color: #010180;}
+#main ul li.num5{color: #760100;}
+#low{height: 30px;text-align: center;margin-top: 10px;}
+#low span{margin-left: 5px;margin-right: 5px;display: inline-block;cursor: pointer;color: red;border: 1px solid #CCC;width: 100px;height: 24px;line-height: 24px;text-align: center;}
+#info{position: fixed;top: 10px;left: 20px;width: 500px;font-family: 微软雅黑;z-index: -1}
+#info ul{margin-top: 20px;font-size: 16px;font-weight: bold;}
+#info li{width: 200px;list-style: decimal;font-size: 14px;margin-bottom: 5px;font-weight: normal;line-height: 18px;}

BIN
images/bg.png


BIN
images/hover.png


BIN
images/l.png


BIN
images/lock.png


BIN
images/open.png


BIN
images/wrong.png


+ 33 - 0
index.html

@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<link rel="stylesheet" type="text/css" href="css/common.css">
+<script type="text/javascript" src="js/jq.js"></script>
+<script type="text/javascript" src="js/common.js"></script>
+<title>扫雷</title>
+</head>
+<body>
+	<div id="info">
+		<ul>游戏说明:
+			<li>遵循 windows 的扫雷游戏规则;</li>
+			<li>揭开方块:鼠标左键单击未被揭开的方块;</li>
+			<li>标记方块:鼠标右键单击未被揭开的方块,会将其标记旗帜,并且锁定不会被揭开;</li>
+			<li>快速揭开:鼠标中键(或者直接左键,为了方面,我也把快速揭开绑定到了左建,并且与上一个操作"揭开方块"并不冲突)单击数字方块,系统会执行自动揭开方块;</li>
+		</ul>
+	</div>
+	<div id="top">
+		<span rel="small">初级</span>
+		<span rel="medium">中级</span>
+		<span rel="large">高级</span>
+	</div>
+	<div id="main"></div>
+	<div id="low">
+		<span rel="time"></span><span rel="replay">重新开始</span><span rel="count"></span>
+		<br /><br />
+		<a href="http://wpa.qq.com/msgrd?v=3&amp;uin=332487886&amp;site=qq&amp;menu=yes" target="_blank">
+			<img style="cursor: pointer;" border="0" title="找我聊天!" alt="找我聊天!" src="http://wpa.qq.com/pa?p=2:332487886:51">
+		</a>
+	</div>
+</body>
+</html>

+ 214 - 0
js/common.js

@@ -0,0 +1,214 @@
+var po=new Array(),mines,X,Y,longtime=0,runtime;//初始化数据
+$(function(){
+	$('#main').contextmenu(function(){return false;});
+	var btn=$('#main>ul>li');
+	btn.hover(function(){
+		if(!$(this).attr('class'))$(this).addClass('hover');
+	},function(){
+		$(this).removeClass('hover');
+	});
+	btn.mouseup(mouse);
+	$("#low span[rel='replay']").click(rePlay);
+	$("#top span").click(function(){
+		$("#top span").css('border-color','#CCC');
+		$(this).css('border-color','red');
+		var rel=$(this).attr('rel');
+		if(rel=='small')X=9,Y=9,mines=10;
+		if(rel=='medium')X=16,Y=16,mines=40;
+		if(rel=='large')X=30,Y=16,mines=99;
+		rePlay();
+	});
+	$("#top span").first().click();
+});
+function mouse(e){
+	$(this).removeClass('hover');
+	var $th=$(this),rel=$th.attr('rel'),ex=checkE();
+	var x=Number(rel.substring(1,rel.indexOf('-'))),y=Number(rel.substring(rel.indexOf('-')+1));
+	if(((ex=='Firefox' || ex=='Chrome') && e.button==0) || (ex=='IE' && e.button==1)){
+		if($th.hasClass('lock'))return false;
+		if($th.hasClass('open')){
+			quickOpen(x,y);
+		}else{
+			if(po.length==0){init(x,y);runtime=setInterval("addtime()",1000);}
+			clickOpen(x,y);
+		}
+	}else if(((ex=='Firefox' || ex=='Chrome') && e.button==2) || (ex=='IE' && e.button==2)){
+		if(po.length>0)$th.toggleClass('lock');
+		$("#low span[rel='count']").text(mines-$('#main>ul>li.lock').length);
+	}else if(((ex=='Firefox' || ex=='Chrome') && e.button==1) || (ex=='IE' && e.button==4)){
+		if($th.hasClass('open'))quickOpen(x,y);
+	}
+}
+//初始化
+function init(x,y){
+	for(var i=1;i<=X;i++){
+		po[i]=new Array();
+		for(var l=1;l<=Y;l++){
+			po[i][l]=0;
+		}
+	}
+	po[x][y]=-1;
+	var m=mines;
+	//随机设雷
+	while(m>0){
+		var i=Math.ceil(Math.random()*X);
+		var j=Math.ceil(Math.random()*Y);
+		if(po[i][j]!=-1){
+			po[i][j]=-1;
+			m--;
+		}
+	}
+	po[x][y]=0;
+	for(var ax in po){
+		var x=Number(ax);
+		for(var ay in po[x]){
+			var y=Number(ay);
+			if(po[x][y]==-1){
+				if(x>1 && po[x-1][y]!=-1)po[x-1][y]++;
+				if(x<X && po[x+1][y]!=-1)po[x+1][y]++;
+				if(y>1){
+					if(po[x][y-1]!=-1)po[x][y-1]++;
+					if(x>1 && po[x-1][y-1]!=-1)po[x-1][y-1]++;
+					if(x<X && po[x+1][y-1]!=-1)po[x+1][y-1]++;
+				}
+				if(y<Y){
+					if(po[x][y+1]!=-1)po[x][y+1]++;
+					if(x>1 && po[x-1][y+1]!=-1)po[x-1][y+1]++;
+					if(x<X && po[x+1][y+1]!=-1)po[x+1][y+1]++;
+				}
+			}
+		}
+	}
+}
+function clickOpen(x,y){
+	var $th=$("#main>ul>li[rel='p"+x+"-"+y+"']"),num=po[x][y];
+	if(!$th.hasClass('open')){
+		if(num==-1){
+			clearInterval(runtime);
+			showMines();
+			$th.removeAttr('class').addClass('wrong');
+			$('#main>ul>li').unbind('mouseup');
+			if(confirm('小朋友,点着雷了!你是要再来一盘,还是回去测能智商?'))rePlay();
+			return false;
+		}else if(num>0){
+			$th.text(num).addClass('open num'+num);
+		}else{
+			$th.addClass('open');
+			if(x>1 && y>1 && !$("li[rel='p"+(x-1)+"-"+(y-1)+"']").hasClass('open'))clickOpen(x-1,y-1);
+			if(x>1 && !$("li[rel='p"+(x-1)+"-"+y+"']").hasClass('open'))clickOpen(x-1,y);
+			if(x>1 && y<Y && !$("li[rel='p"+(x-1)+"-"+(y+1)+"']").hasClass('open'))clickOpen(x-1,y+1);
+			if(y>1 && !$("li[rel='p"+x+"-"+(y-1)+"']").hasClass('open'))clickOpen(x,y-1);
+			if(y<Y && !$("li[rel='p"+x+"-"+(y+1)+"']").hasClass('open'))clickOpen(x,y+1);
+			if(x<X && y>1 && !$("li[rel='p"+(x+1)+"-"+(y-1)+"']").hasClass('open'))clickOpen(x+1,y-1);
+			if(x<X && !$("li[rel='p"+(x+1)+"-"+y+"']").hasClass('open'))clickOpen(x+1,y);
+			if(x<X && y<Y && !$("li[rel='p"+(x+1)+"-"+(y+1)+"']").hasClass('open'))clickOpen(x+1,y+1);
+		}
+		if($("#main>ul>li.open").length==X*Y-mines){
+			clearInterval(runtime);
+			showMines();
+			$('#main>ul>li').unbind('mouseup');
+			if(confirm('一共用了'+longtime+'秒,你太厉害了!!!要再来一盘吗?'))rePlay();
+		}
+	}
+}
+function quickOpen(x,y){
+	var num=po[x][y],n=0,p=new Array();
+	if(x>1 && y>1){
+		if($("li[rel='p"+(x-1)+"-"+(y-1)+"']").hasClass('lock'))n++;
+		else if(!$("li[rel='p"+(x-1)+"-"+(y-1)+"']").hasClass('open'))p.push(new Array(x-1,y-1));
+	}
+	if(x>1){
+		if($("li[rel='p"+(x-1)+"-"+y+"']").hasClass('lock'))n++;
+		else if(!$("li[rel='p"+(x-1)+"-"+y+"']").hasClass('open'))p.push(new Array(x-1,y));
+	}
+	if(x>1 && y<Y){
+		if($("li[rel='p"+(x-1)+"-"+(y+1)+"']").hasClass('lock'))n++;
+		else if(!$("li[rel='p"+(x-1)+"-"+(y+1)+"']").hasClass('open'))p.push(new Array(x-1,y+1));
+	}
+	if(y>1){
+		if($("li[rel='p"+x+"-"+(y-1)+"']").hasClass('lock'))n++;
+		else if(!$("li[rel='p"+x+"-"+(y-1)+"']").hasClass('open'))p.push(new Array(x,y-1));
+	}
+	if(y<Y){
+		if($("li[rel='p"+x+"-"+(y+1)+"']").hasClass('lock'))n++;
+		else if(!$("li[rel='p"+x+"-"+(y+1)+"']").hasClass('open'))p.push(new Array(x,y+1));
+	}
+	if(x<X && y>1){
+		if($("li[rel='p"+(x+1)+"-"+(y-1)+"']").hasClass('lock'))n++;
+		else if(!$("li[rel='p"+(x+1)+"-"+(y-1)+"']").hasClass('open'))p.push(new Array(x+1,y-1));
+	}
+	if(x<X){
+		if($("li[rel='p"+(x+1)+"-"+y+"']").hasClass('lock'))n++;
+		else if(!$("li[rel='p"+(x+1)+"-"+y+"']").hasClass('open'))p.push(new Array(x+1,y));
+	}
+	if(x<X && y<Y){
+		if($("li[rel='p"+(x+1)+"-"+(y+1)+"']").hasClass('lock'))n++;
+		else if(!$("li[rel='p"+(x+1)+"-"+(y+1)+"']").hasClass('open'))p.push(new Array(x+1,y+1));
+	}
+	if(n>=num){
+		for(var o in p){
+			clickOpen(p[o][0],p[o][1])
+		}
+	}
+	//自动揭开功能
+	// if(num-n==p.length){
+	// 	for(var o in p){
+	// 		$("li[rel='p"+p[o][0]+"-"+p[o][1]+"']").addClass('lock');
+	// 		$("#low span[rel='count']").text(mines-$('#main>ul>li.lock').length);
+	// 	}
+	// }
+}
+function drow(){
+	$("#low span[rel='count']").text(mines);
+	$("#low span[rel='time']").text(0);
+	//绘制表格
+	var html='';
+	for(var i=1;i<=Y;i++){
+		html+='<ul>';
+		for(var l=1;l<=X;l++){
+			html+='<li rel="p'+l+'-'+i+'"></li>';
+		}
+		html+='</ul>';
+	}
+	$('#main').css('height',Y*30).css('width',X*30).html(html);
+}
+function rePlay(){
+	po=new Array(),longtime=0;
+	drow();
+	clearInterval(runtime);
+	$('#main>ul>li').unbind().mouseup(mouse).hover(function(){
+		if(!$(this).attr('class'))$(this).addClass('hover');
+	},function(){
+		$(this).removeClass('hover');
+	});
+}
+//显示所有雷
+function showMines(){
+	$("#low span[rel='count']").text(0);
+	for(var ax in po){
+		for(var ay in po[ax]){
+			if(po[ax][ay]==-1){
+				$("#main>ul>li[rel='p"+ax+"-"+ay+"']").removeAttr('class').addClass('mine');
+			}
+		}
+	}
+}
+//判断浏览器
+function checkE(f){
+	var explorer = window.navigator.userAgent;
+	if(explorer.indexOf("MSIE") >= 0)var E='IE';
+	else if (explorer.indexOf("Firefox") >= 0)var E="Firefox";
+	else if(explorer.indexOf("Chrome") >= 0)var E="Chrome";
+	else if(explorer.indexOf("Opera") >= 0)var E="Opera";
+	else if(explorer.indexOf("Safari") >= 0)var E="Safari";
+	if(f){
+		if(f==E)return true;
+		else return false;
+	}else{
+		return E;
+	}
+}
+function addtime(){
+	longtime++;
+	$("#low span[rel='time']").text(longtime);
+}

File diff suppressed because it is too large
+ 5 - 0
js/jq.js