论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > Javascript教程
Tag:验证,特效,入门,实例,验证,表单,特效,正则表达式,跑马灯,document,函数,代码,getElementByID,菜单,图片,视频教程

Javascript制作钻石棋游戏

文章类别:Javascript | 发表日期:2010-6-18 9:28:18

详细代码:

<!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>

视频教程列表
文章教程搜索
 
Javascript推荐教程
Javascript热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058