详细代码:
<!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=gb2312" />
<title>钻石棋——Cssbbs.com</title>
<link rel="stylesheet" type="text/css" href="c.css" />
<style>
body{text-align:center; font-size:12px;}
td{font-size:12px;text-align:center}
table .qz{ border:1px solid #ccc; padding:0px; margin:0px;}
.ayc{ background:#fff; background-image:none}
table td{width:60px; height:60px;}
table td input,.axs{ height:60px; width:60px; border:0px; background:url(http://www.cssbbs.com/img/zsq.gif) no-repeat center center; color:#ccc; font-size:12px}
#zhuangtai{ font-size:16px;}
.axz{height:60px; width:60px; border:0px; background:url(http://www.cssbbs.com/img/zsq1.gif) no-repeat center center; }
.zhuangt{ height:30px; line-height:30px; font-size:12px;}
.zhuangt span{ color:red; font-weight:bold;}
</style>
</head>
<body>
<h1 style="text-align:center;">独立钻石棋</h1>
<p>
百度百科查看玩法和介绍:<a href="http://baike.baidu.com/view/824863.htm" target=_blank>http://baike.baidu.com/view/824863.htm</a>
</p>
<div class="zhuangt">
剩余<span id='zhuangtai'>32</span> 个棋子、共走<span id='bushu'>0</span>步
</div>
<script type="text/javascript">
var x,y,x1,y1,a1,a2,an=0,qzs=0,str="",bs=0;
var xy =new Array() ;
xy[0]=new Array();
xy[1]=new Array();
xy[2]=new Array();
xy[3]=new Array();
xy[4]=new Array();
xy[5]=new Array();
xy[6]=new Array();
function xz(x,y)
{
var a1=document.getElementById("n"+x+y);
//alert(x+"-"+y+"-"+x1+"-"+y1+"-"+xy[x,y]);
if(an==0 && xy[x][y]==1){
a1.className="axz";
a2=a1;
an=1;
x1=x;
y1=y;
}
else if(an==1)
{
if(ks2(x,y,x1,y1)==1){
xy[x1][y1]=0;
a1.className="axs";
xy[x][y]=1;
a2.className="ayc";
qzs=qzs-1;
bs=bs+1;
document.getElementById("zhuangtai").innerHTML=qzs;
document.getElementById("bushu").innerHTML=bs;
}else
{
a2.className="axs";
}
an=0;
}
}
//--------------------------------
//检测棋子
function ks(x,y)
{
if(x<=1 && y<=1 || x<=1 && y>=5 || x>=5 && y<=1 || x>=5 && y>=5 || x==3 && y==3){
xs=0;
}
else
{
xs=1;
}
return xs;
}
//检测第二步
function ks2(x,y,x1,y1)
{
xs=0;
if(x==x1 && (y-2==y1 || y+2==y1) && xy[x][y]==0)
{
if(y-2==y1 && xy[x][y-1]==1){
xs=1;
yincang(x,y-1);
}else if(y+2==y1 && xy[x][y+1]==1){
xs=1;
yincang(x,y+1);
}
}else if(y==y1 && (x-2==x1 || x+2==x1) && xy[x][y]==0)
{
if(x-2==x1 && xy[x-1][y]==1){
xs=1;
yincang(x-1,y);
}else if(x+2==x1 && xy[x+1][y]==1){
xs=1;
yincang(x+1,y);
}
}
return xs;
}
//------------隐藏棋子
function yincang(x,y)
{
xy[x][y]=0;
document.getElementById("n"+x+y).className="ayc";
}
function zb(x,y)
{
for (x=0;x<=6;x++)
{
for (y=0;y<=6;y++)
{
if(ks(x,y)==1)
{
document.getElementById("n"+x+y).className="ayc";
}
}
}
document.getElementById("n25").className="axs";
}
//-------------------------------------------
document.write("<table>");
for (x=0;x<=6;x++)
{
document.write("<tr>");
for (y=0;y<=6;y++)
{
if(ks(x,y)==1 || (x==3 && y==3)){
xy[x][y]=1;
//str=str+","+x+","+y+"-"+xy[x][y]+"<br>";
//alert(x+"-"+y+"-"+x1+"-"+y1+"+xy[x][y]+");
document.write("<td class='qz'><input id='n"+x+y+"' type='button' value='' onclick='xz("+x+","+y+")'/></td>");
}
else{
document.write("<td></td>");
}
}
document.write("</tr>");
}
document.write("</table>");
document.getElementById("n33").className="ayc";
qzs=32;
xy[3][3]=0;
//document.write(str);
</script>
<br />
<a href="http://www.Cssbbs.com">Cssbbs.com</a>
</body>
</html>
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |