<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<title>中国象棋单机双人</title>
<script>
var st="";
var qipuid=new Array();
var qipux=new Array();
var qipuy=new Array();
var qipuc=0;
var qipust="27,8,5,2,3,3,";
qipust+="24,8,7,1,1,2,";
qipust+="29,6,3,15,5,7,";
qipust+="18,8,3,8,3,7,";
qipust+="26,6,2,8,5,8";
qipusz=qipust.split(",");
var moveqizhi="";
var qizhix,qizhiy;
var zouqi="red";
var qiju="";
for (var x=0,qx=0;x<qipusz.length;x+=3)
{
qipuid[qx]=qipusz[x];
qipux[qx]=qipusz[x+1];
qipuy[qx]=qipusz[x+2];
qx++;
}
function yiqi(e)
{
if(moveqizhi=="") return;
eval("document.getElementById('a"+moveqizhi+"').style.top ="+((e.y?e.y:e.pageY)-25+(e.y?document.body.scrollTop:document.documentElement.scrollTop)));
eval("document.getElementById('a"+moveqizhi+"').style.left="+((e.x?e.x:e.pageX)-25+(e.y?document.body.scrollLeft:document.documentElement.scrollLeft)));
eval("document.getElementById('b"+moveqizhi+"').style.top ="+((e.y?e.y:e.pageY)-15+(e.y?document.body.scrollTop:document.documentElement.scrollTop)));
eval("document.getElementById('b"+moveqizhi+"').style.left="+((e.x?e.x:e.pageX)-15+(e.y?document.body.scrollLeft:document.documentElement.scrollLeft)));
}
function youqi(srx,sry)
{
var srx,sry;
srx=srx+"px";sry=sry+"px";
for(var x=1;x<=32;x++)
{
eval("srx1=document.getElementById('a"+x+"').style.top");
eval("sry1=document.getElementById('a"+x+"').style.left");
if (srx==srx1 && sry==sry1) {return true;}
}
return false;
}
function youqiy(srx1,sry1,srx2,sry2)
{
var srx1,srx2,sry1,sry1,sr,srx,sry;
rt=0;
if (srx1>srx2) {sr=srx1;srx1=srx2;srx2=sr;}
if (sry1>sry2) {sr=sry1;sry1=sry2;sry2=sr;}
for(var x=1;x<=32;x++)
{
eval("srx=document.getElementById('a"+x+"').style.top");
eval("sry=document.getElementById('a"+x+"').style.left");
srx=srx.replace(/px/i, "");
sry=sry.replace(/px/i, "");
if (srx1==srx2 && srx==srx1 && sry>sry1 && sry<sry2) rt++;
if (sry1==sry2 && sry==sry1 && srx>srx1 && srx<srx2) rt++;
}
return rt;
}
function panduan(qiziname,qiziyanse,x1,y1,x2,y2)
{
var qiziname,qiziyanse,x1,y1,x2,y2;
x1=x1*1;x2=x2*1;y1=y1*1;y2=y2*1;
if (x1==x2 && y1==y2) return false;
if (x2<50 || x2>500 || y2<50 || y2>450) {alert("所有棋子必须走在棋盘中");return false;}
if (qiziname=="-1" || qiziname=="1")
{
if (x1!=x2 && y1!=y2) {alert("车请走直线");return false;}
if (youqiy(x1,y1,x2,y2)>0) {alert("车不能跳走");return false;}
}
if (qiziname=="-2" || qiziname=="2")
{
if (!(Math.abs(x1-x2)==50 && Math.abs(y1-y2)==100 || Math.abs(x1-x2)==100 && Math.abs(y1-y2)==50)) {alert("马只能走日字");return false;}
if ( Math.abs(x1-x2)==50 && youqi(x1,(y1+y2)/2) || Math.abs(y1-y2)==50 && youqi((x1+x2)/2,y1)) {alert("憋脚马不能走");return false;}
}
if (qiziname=="-3" || qiziname=="3")
{
if (x1!=x2 && y1!=y2) {alert("炮请走直线");return false;}
if (youqiy(x1,y1,x2,y2)>1) {alert("炮不能跳走");return false;}
}
if (qiziname=="-4" || qiziname=="4")
{
if (Math.abs(x1-x2)!=50 || Math.abs(y1-y2)!=50) {alert("士只能斜走一格");return false;}
if (y2<200 || y2>300 ) {alert("士不能走出宫外");return false;}
}
if (qiziname=="-5" || qiziname=="5")
{
if (Math.abs(x1-x2)!=100 || Math.abs(y1-y2)!=100) {alert("象只能斜走两格");return false;}
if (x2==200 || x2==350 ) {alert("象不能过河");return false;}
if (youqi((x1+x2)/2,(y1+y2)/2)) {alert("象眼被塞");return false;}
}
if (qiziname=="-6" || qiziname=="6")
{
if (x1!=x2 && y1!=y2) {alert("将不能斜走");return false;}
if (Math.abs(x1-x2)!=50 && Math.abs(y1-y2)!=50) {alert("将只能走一格");return false;}
if (y2<200 || y2>300 || x2>150 && x2<400) {alert("将不能走出宫外");return false;}
}
if (qiziname=="-7" || qiziname=="7")
{
if (x1!=x2 && y1!=y2) {alert("兵不能斜走");return false;}
if (Math.abs(x1-x2)!=50 && Math.abs(y1-y2)!=50) {alert("兵只能走一格");return false;}
if (qiziname<0 && x2<x1 || qiziname>0 && x2>x1 ) {alert("兵不能倒走");return false;}
if (qiziname<0 && x2<300 && y1!==y2 || qiziname>0 && x2>250 && y1!==y2 ) {alert("过河兵才能横走");return false;}
}
var chizi=false;
for(var x=1;x<=32;x++)
{
eval("srx1=document.getElementById('a"+x+"').style.top");
eval("sry1=document.getElementById('a"+x+"').style.left");
eval("yanse1=document.getElementById('a"+x+"').style.color");
srx1=srx1.replace(/px/i, "");
sry1=sry1.replace(/px/i, "");
if (srx1==x2 && sry1==y2)
{
if (qiziyanse==yanse1) {alert("不能吃自己的棋子");return false;}
if ((qiziname=="-3" || qiziname=="3") && youqiy(x1,y1,x2,y2)!=1) {alert("炮要隔一吃子");return false;}
eval("document.getElementById('a"+x+"').style.top=-200");
eval("document.getElementById('a"+x+"').style.left=-200");
eval("document.getElementById('b"+x+"').style.top=-200");
eval("document.getElementById('b"+x+"').style.left=-200");
eval("quziname=document.getElementById('b"+x+"').getAttribute('qiziname')");
if (quziname==-6) qiju="红放胜利";
if (quziname== 6) qiju="黑方胜利";
chizi=true;
}
}
if ( (qiziname=="-3" || qiziname=="3") && youqiy(x1,y1,x2,y2)>0 && !chizi) {alert("炮不能跳走");return false;}
return true;
}
function dianqi(srid,e)
{
var srid,x,y;
if (qiju!="") {alert(qiju);return;}
if(moveqizhi=="")
{
if (zouqi=="red" && srid<17) {alert("请走红棋");return;}
if (zouqi!="red" && srid>16) {alert("请走黑棋");return;}
moveqizhi=srid;
eval("qizhix=document.getElementById('a"+srid+"').style.top");
eval("qizhiy=document.getElementById('a"+srid+"').style.left");
qizhix=qizhix.replace(/px/i, "");
qizhiy=qizhiy.replace(/px/i, "");
eval("document.getElementById('a"+moveqizhi+"').style.zIndex=7");
eval("document.getElementById('b"+moveqizhi+"').style.zIndex=7");
yiqi(e);
}
else
{
var qiziname,qiziyanse;
eval("qiziname=document.getElementById('b"+srid+"').getAttribute('qiziname')");
eval("qiziyanse=document.getElementById('b"+srid+"').qiziyanse");
x=eval("document.getElementById('a"+moveqizhi+"').style.top");
y=eval("document.getElementById('a"+moveqizhi+"').style.left");
x=x.replace(/px/i, "");
y=y.replace(/px/i, "");
newx=Math.round(x/50)*50;
newy=Math.round(y/50)*50;
if (panduan(qiziname,qiziyanse,qizhix,qizhiy,newx,newy))
{
zouqi=zouqi=="red"?"black":"red";
}
else
{
newx=qizhix*1;
newy=qizhiy*1;
}
eval("document.getElementById('a"+moveqizhi+"').style.top="+newx);
eval("document.getElementById('a"+moveqizhi+"').style.left="+newy);
eval("document.getElementById('b"+moveqizhi+"').style.top="+(newx+10));
eval("document.getElementById('b"+moveqizhi+"').style.left="+(newy+10));
eval("document.getElementById('a"+moveqizhi+"').style.zIndex=3");
eval("document.getElementById('b"+moveqizhi+"').style.zIndex=3");
moveqizhi="";
if (qiju!="") {alert(qiju);return;}
}
}
function qizhi(yanse,qizhiname,qizhiy,qizhix,srid,qiziname)
{
var yanse,qizhiname,qizhiy,qizhix,srid;
qizhix=qizhix*50;
qizhiy=qizhiy*50;
if (yanse==0) yanse="black";else yanse="red";
st+="<div id='a"+srid+"' qiziid="+srid+" qiziname='"+qiziname+"' qiziyanse='"+yanse+"' style='position:absolute;top:"+(qizhiy)+"px;left:"+(qizhix)+"px;color:"+yanse+";font-size:50;z-index:3;aaa:88;' onmousemove=yiqi(event) onclick=dianqi('"+srid+"',event)>●</div>"
st+="<div id='b"+srid+"' qiziid="+srid+" qiziname='"+qiziname+"' qiziyanse='"+yanse+"' style='position:absolute;top:"+(qizhiy+10)+"px;left:"+(qizhix+10)+"px;color:white;font-size:30;z-index:3;aaa:88;' onmousemove=yiqi(event) onclick=dianqi('"+srid+"',event)>"+qizhiname+"</div>"
}
function hengxian(qizhix)
{
qizhix=qizhix*50+25;
st+="<div style='position:absolute;width:402px;height:2px;top:"+qizhix+"px;left:75px;background:black;font-size:1' onmousemove=yiqi(event)></div>"
}
function shuxian(qizhix)
{
qizhix=qizhix*50+25;
st+="<div style='position:absolute;width:2px;height:450px;left:"+qizhix+"px;top:75px;background:black;font-size:1' onmousemove=yiqi(event)></div>"
}
function point(x,y)
{
var x,y;
st+="<div style='position:absolute;width:1px;height:1px;left:"+y+"px;top:"+x+"px;background:black;font-size:1'></div>"
}
function linehengc(top,left)
{
var top,left;
top=50*top+20;
left=50*left+15;
for(var y=0;y<=5;y++) point(top,y+left);
for(var y=0;y<=5;y++) point(top+10,y+left);
for(var y=0;y<=5;y++) point(top,y+left+15);
for(var y=0;y<=5;y++) point(top+10,y+left+15);
for(var x=0;x<=5;x++) point(x+top-5,left+5);
for(var x=0;x<=5;x++) point(x+top-5,left+15);
for(var x=0;x<=5;x++) point(x+top+12,left+5);
for(var x=0;x<=5;x++) point(x+top+12,y+left+9);
}
function linehengr(top,left)
{
var top,left;
top=50*top+20;
left=50*left+15;
for(var y=0;y<=5;y++) point(top,y+left);
for(var y=0;y<=5;y++) point(top+10,y+left);
for(var x=0;x<=5;x++) point(x+top-5,left+5);
for(var x=0;x<=5;x++) point(x+top+12,left+5);
}
function linehengl(top,left)
{
var top,left;
top=50*top+20;
left=50*left+15;
for(var y=0;y<=5;y++) point(top,y+left+15);
for(var y=0;y<=5;y++) point(top+10,y+left+15);
for(var x=0;x<=5;x++) point(x+top-5,left+15);
for(var x=0;x<=5;x++) point(x+top+12,y+left+9);
}
function duqipu()
{
if (qipuc>=qipuid.length) {alert("现在封盘,下次再继续");return;}
qizhimove(qipuid[qipuc],qipux[qipuc],qipuy[qipuc])
qipuc++;
}
function qizhimove(srid,x2,y2)
{
var srid,x,y,x2,y2;
x2=x2*50;
y2=y2*50;
luozhi=false;
eval("x1=document.getElementById('a"+srid+"').style.top");
re=/px/i;
x1= x1.replace(re, "");
eval("y1=document.getElementById('a"+srid+"').style.left");
re=/px/i;
y1= y1.replace(re, "");
qizhimoveloop(srid,x1*1,y1*1,x2,y2);
}
function qizhimoveloop(srid,x,y,x2,y2)
{
var srid,x,y;
eval("document.getElementById('a"+srid+"').style.top='"+x+"px'");
eval("document.getElementById('b"+srid+"').style.top='"+(x+10)+"px'");
eval("document.getElementById('a"+srid+"').style.left='"+y+"px'");
eval("document.getElementById('b"+srid+"').style.left='"+(y+10)+"px'");
if(x!=x2)
{
if (x>x2) x-=2;
if (x<x2) x+=2;
}
if(y!=y2)
{
if (y>y2) y-=2;
if (y<y2) y+=2;
}
if (x!=x2 || y!=y2) setTimeout("qizhimoveloop("+srid+","+x+","+y+","+x2+","+y2+")",10);
else setTimeout(duqipu,1000);
}
function hejie()
{
st+="<div style='position:absolute;width:350px;height:48px;left:100px;top:277px;background:white;font-size:1'></div>"
}
function kaishi()
{
for(var x=1;x<=10;x++) hengxian(x);
for(var x=1;x<=9;x++) shuxian(x);
for(var x=0;x<=100;x++) point(x+75,x+225);
for(var x=0;x<=100;x++) point(x+425,x+225);
for(var x=0;x<=100;x++) point(525-x,x+225);
for(var x=0;x<=100;x++) point(175-x,x+225);
hejie();
linehengc(3,2);
linehengc(3,8);
linehengc(8,2);
linehengc(8,8);
linehengl(4,1);
linehengc(4,3);
linehengc(4,5);
linehengc(4,7);
linehengr(4,9);
linehengl(7,1);
linehengc(7,3);
linehengc(7,5);
linehengc(7,7);
linehengr(7,9);
qizhi(0,"车",1,1,1,-1);
qizhi(0,"马",1,2,2,-2);
qizhi(0,"象",1,3,3,-5);
qizhi(0,"仕",1,4,4,-4);
qizhi(0,"将",1,5,5,-6);
qizhi(0,"仕",1,6,6,-4);
qizhi(0,"象",1,7,7,-5);
qizhi(0,"马",1,8,8,-2);
qizhi(0,"车",1,9,9,-1);
qizhi(0,"炮",3,2,10,-3);
qizhi(0,"炮",3,8,11,-3);
qizhi(0,"卒",4,1,12,-7);
qizhi(0,"卒",4,3,13,-7);
qizhi(0,"卒",4,5,14,-7);
qizhi(0,"卒",4,7,15,-7);
qizhi(0,"卒",4,9,16,-7);
qizhi(1,"车",10,1,17,1);
qizhi(1,"马",10,2,18,2);
qizhi(1,"相",10,3,19,5);
qizhi(1,"士",10,4,20,4);
qizhi(1,"帅",10,5,21,6);
qizhi(1,"士",10,6,22,4);
qizhi(1,"相",10,7,23,5);
qizhi(1,"马",10,8,24,2);
qizhi(1,"车",10,9,25,1);
qizhi(1,"炮",8,2,26,3);
qizhi(1,"炮",8,8,27,3);
qizhi(1,"兵",7,1,28,7);
qizhi(1,"兵",7,3,29,7);
qizhi(1,"兵",7,5,30,7);
qizhi(1,"兵",7,7,31,7);
qizhi(1,"兵",7,9,32,7);
document.body.innerHTML=st;
//duqipu();
}
</script>
</head>
<body onload=kaishi()>
</body>
</html>