Custian's JavaScript Chinese chess _javascript skills

Source: Internet
Author: User
IE6.0 only
Non-XHTML standard, perhaps IE 7.0 can not see .... Ha ha
Blue go first.
<style> * {font:24px arial, "Song Dynasty"; font-weight:bold; color:white; cursor:default;} Table {table-layout:fixed; border-collapse:collapse; position:absolute; left:50px; top:50px;} TD {width:80px; height:80px; border:1px solid silver; color:black; text-align:center; line-height:80px;} img.i1 {width:78px; height:78px;} img.i2 {width:49px; height:49px;} img.i3 {width:25px; height:49px;} . chessman_red {Background:url (/attachments/2007/3/29/20070329_2187cc5e9def581951f2v22efdusxq7j.jpg); width:50px; height:50px; line-height:50px; Text-align:center; }. Chessman_blue {Background:url (/attachments/2007/3/29/20070329_5caa80c54f776b93bd582bwravrwxf43.jpg); width : 50px; height:50px; line-height:50px; Text-align:center; } </style> <script> var TB; var cch=new Array (); var his=new Array (); var players=["Red", "Blue"]; var curplayer=1; Window.onload=function () {document.onselectstart=function () {return (false);} Document.onclick=do_click; Document.oncontextmenu=do_context; Tb=document.createelement ("table"); Document.body.appendChild (TB); for (Var i=0;i<9;i++) {R=tb.insertrow (); if (i==4) {C=r.insertcell (); c.colspan=8; C.style.width= "720px"; C.style.fontsize= "42px"; c.style.fontfamily= "Official script"; c.innertext= "Chu Franco boundary"; Continue for (Var j=0;j<8;j++) {C=r.insertcell (); } tmp=new Image (); Tmp.src= "/attachments/2007/3/29/20070329_3f2ffb6cdf0bda991381aocfwljomick.jpg"; Tmp.classname= "I1"; Document.body.appendChild (TMP); With (Tmp.style) {position= "absolute"; left= "291"; Top= "51"; } tmp=new Image (); Tmp.src= "/attachments/2007/3/29/20070329_fec757c6d7874546161f8tgsdqeabnts.jpg"; Tmp.classname= "I1"; Document.body.appendChild (TMP);With (Tmp.style) {position= "absolute"; left= "371"; Top= "51"; } tmp=new Image (); Tmp.src= "/attachments/2007/3/29/20070329_fec757c6d7874546161f8tgsdqeabnts.jpg"; Tmp.classname= "I1"; Document.body.appendChild (TMP); With (Tmp.style) {position= "absolute"; left= "291"; top= "131"; } tmp=new Image (); Tmp.src= "/attachments/2007/3/29/20070329_3f2ffb6cdf0bda991381aocfwljomick.jpg"; Tmp.classname= "I1"; Document.body.appendChild (TMP); With (Tmp.style) {position= "absolute"; left= "371"; top= "131"; } tmp=new Image (); Tmp.src= "/attachments/2007/3/29/20070329_3f2ffb6cdf0bda991381aocfwljomick.jpg"; Tmp.classname= "I1"; Document.body.appendChild (TMP); With (Tmp.style) {position= "absolute"; left= "291"; top= "611"; } tmp=new Image (); Tmp.src= "/ATTACHMENTS/2007/3/29/20070329_FEC757C6D7874546161F8TGSDQEABNTS.jpg "; Tmp.classname= "I1"; Document.body.appendChild (TMP); With (Tmp.style) {position= "absolute"; left= "371"; top= "611"; } tmp=new Image (); Tmp.src= "/attachments/2007/3/29/20070329_fec757c6d7874546161f8tgsdqeabnts.jpg"; Tmp.classname= "I1"; Document.body.appendChild (TMP); With (Tmp.style) {position= "absolute"; left= "291"; top= "691"; } tmp=new Image (); Tmp.src= "/attachments/2007/3/29/20070329_3f2ffb6cdf0bda991381aocfwljomick.jpg"; Tmp.classname= "I1"; Document.body.appendChild (TMP); With (Tmp.style) {position= "absolute"; left= "371"; top= "691"; } tmp=new Image (); Tmp.src= "/attachments/2007/3/29/20070329_0bf3ba9aa9f7af079806v71jcpmo4ygx.jpg"; Tmp.classname= "I2"; Document.body.appendChild (TMP); With (Tmp.style) {position= "absolute"; left= "106"; top= "186"; } Tmp=neW Image (); Tmp.src= "/attachments/2007/3/29/20070329_0bf3ba9aa9f7af079806v71jcpmo4ygx.jpg"; Tmp.classname= "I2"; Document.body.appendChild (TMP); With (Tmp.style) {position= "absolute"; left= "586"; top= "186"; } tmp=new Image (); Tmp.src= "/attachments/2007/3/29/20070329_0bf3ba9aa9f7af079806v71jcpmo4ygx.jpg"; Tmp.classname= "I2"; Document.body.appendChild (TMP); With (Tmp.style) {position= "absolute"; left= "106"; top= "586"; } tmp=new Image (); Tmp.src= "/attachments/2007/3/29/20070329_0bf3ba9aa9f7af079806v71jcpmo4ygx.jpg"; Tmp.classname= "I2"; Document.body.appendChild (TMP); With (Tmp.style) {position= "absolute"; left= "586"; top= "586"; } tmp=new Image (); Tmp.src= "/attachments/2007/3/29/20070329_0bf3ba9aa9f7af079806v71jcpmo4ygx.jpg"; Tmp.classname= "I2"; Document.body.appendChild (TMP); With (tmp.styLe) {position= "absolute"; left= "186"; top= "266"; } tmp=new Image (); Tmp.src= "/attachments/2007/3/29/20070329_0bf3ba9aa9f7af079806v71jcpmo4ygx.jpg"; Tmp.classname= "I2"; Document.body.appendChild (TMP); With (Tmp.style) {position= "absolute"; left= "346"; top= "266"; } tmp=new Image (); Tmp.src= "/attachments/2007/3/29/20070329_0bf3ba9aa9f7af079806v71jcpmo4ygx.jpg"; Tmp.classname= "I2"; Document.body.appendChild (TMP); With (Tmp.style) {position= "absolute"; left= "506"; top= "266"; } tmp=new Image (); Tmp.src= "/attachments/2007/3/29/20070329_0bf3ba9aa9f7af079806v71jcpmo4ygx.jpg"; Tmp.classname= "I2"; Document.body.appendChild (TMP); With (Tmp.style) {position= "absolute"; left= "186"; top= "506"; } tmp=new Image (); Tmp.src= "/attachments/2007/3/29/20070329_0bf3ba9aa9f7af079806v71jcpmo4ygx.jpg "; Tmp.classname= "I2"; Document.body.appendChild (TMP); With (Tmp.style) {position= "absolute"; left= "346"; top= "506"; } tmp=new Image (); Tmp.src= "/attachments/2007/3/29/20070329_0bf3ba9aa9f7af079806v71jcpmo4ygx.jpg"; Tmp.classname= "I2"; Document.body.appendChild (TMP); With (Tmp.style) {position= "absolute"; left= "506"; top= "506"; } tmp=new Image (); Tmp.src= "/attachments/2007/3/29/20070329_0b05dbadff2eb90fdc79ftu6o43rtus6.jpg"; Tmp.classname= "i3"; Document.body.appendChild (TMP); With (Tmp.style) {position= "absolute"; left= "50"; top= "266"; } tmp=new Image (); Tmp.src= "/attachments/2007/3/29/20070329_0b05dbadff2eb90fdc79ftu6o43rtus6.jpg"; Tmp.classname= "i3"; Document.body.appendChild (TMP); With (Tmp.style) {position= "absolute"; left= "50"; top= "506"; } tmp=new Image (); Tmp.src= "/attachments/2007/3/29/20070329_f751e991e2d883fd916262mzpct8ylkt.jpg"; Tmp.classname= "i3"; Document.body.appendChild (TMP); With (Tmp.style) {position= "absolute"; left= "665"; top= "266"; } tmp=new Image (); Tmp.src= "/attachments/2007/3/29/20070329_f751e991e2d883fd916262mzpct8ylkt.jpg"; Tmp.classname= "i3"; Document.body.appendChild (TMP); With (Tmp.style) {position= "absolute"; left= "665"; top= "506"; Createchessman ("Car", 0,0, "Red"); Createchessman ("Car", 8,0, "Red"); Createchessman ("Horse", 1,0, "Red"); Createchessman ("Horse", 7,0, "Red"); Createchessman ("Cannon", 1,2, "red"); Createchessman ("Cannon", 7,2, "Red"); Createchessman ("phase", 2,0, "Red"); Createchessman ("phase", 6,0, "Red"); Createchessman ("Shi", 3,0, "Red"); Createchessman ("Shi", 5,0, "Red"); Createchessman ("Handsome", 4,0, "Red"); Createchessman ("Bing", 0,3, "Red"); Createchessman ("Bing", 2,3, "red"); Createchessman ("Bing", 4,3, "Red"); Createchessman ("Bing", 6,3, "Red"); Createchessman ("Bing", 8,3, "Red"); Createchessman ("Car", 0,9, "Blue"); Createchessman ("Car", 8,9, "Blue"); Createchessman ("Horse", 1,9, "Blue"); Createchessman ("Horse", 7,9, "Blue"); Createchessman ("Cannon", 1,7, "Blue"); Createchessman ("Cannon", 7,7, "Blue"); Createchessman ("Like", 2,9, "Blue"); Createchessman ("Like", 6,9, "Blue"); Createchessman ("Shi", 3,9, "Blue"); Createchessman ("Shi", 5,9, "Blue"); Createchessman ("Will", 4,9, "Blue"); Createchessman ("Stroke", 0,6, "Blue"); Createchessman ("Stroke", 2,6, "Blue"); Createchessman ("Stroke", 4,6, "Blue"); Createchessman ("Stroke", 6,6, "Blue"); Createchessman ("Stroke", 8,6, "Blue"); function Createchessman (text,x,y,player) {var nd=document.createelement ("div"); Nd.classname= "Chessman_" +player; Nd.innertext=text; Nd.player=player; Nd.moveto=chessman_moveto; Nd.destory=chessman_destory; Document.body.appendChild (ND); Nd.moveto (x,y,true); function Chessman_moveto (x,y,force) {var mi, MA, MN; if (!force) {switch (this.innertext) {case "car": if (this.x!=x&&this.y!=y) retur n (false); if (this.x==x) {mi=y>this.y?this.y:y; ma=y>this.y?y:this.y; for (Var i=mi+1;i<ma;i++) if (Cch[i*9+this.x]) return (false); }else{mi=x>this.x?this.x:x; ma=x>this.x?x:this.x; for (Var i=mi+1;i<ma;i++) if (Cch[this.y*9+i]) return (false); } break; Case "Horse": if (!) ( (Math.Abs (This.x-x) ==2&&math.abs (this.y-y) ==1) | | (Math.Abs (This.x-x) ==1&&math.abs (this.y-y) ==2))) return (false); if (Math.Abs (this.x-x) ==2&&cch[this.y*9+ (this.x+x)/2]) return (false); if (Math.Abs (this.y-y) ==2&&cch[(this.y+y)/2*9+this.x]) return (false); Break Case "Shi": Case "Shi": if (x<3| | x>5| | (! (y<3| | y>6)) | | Math.Abs (this.x-x)!=1| | Math.Abs (this.y-y)!=1) return (false); Break Case "phase": if (Math.Abs (this.x-x)!=2| | Math.Abs (this.y-y)!=2| | Y&GT;4) return (false); if (cch[(this.y+y)/2*9+ (this.x+x)/2]) return (false); Break Case "like": if (Math.Abs (this.x-x)!=2| | Math.Abs (this.y-y)!=2| | Y&LT;5) return (false); if (cch[(this.y+y)/2*9+ (this.x+x)/2]) return (false); Break Case "Shuai": Case "will": if (x<3| | x>5| | (! (y<3| | y>6)) | | (! ((Math.Abs (this.x-x) ==1&&math.abs (this.y-y) ==0) | | (Math.Abs (This.x-x) ==0&&math.abs (this.y-y) ==1))) return (false); Break Case "Bing"://if (curplayer%2==0) {if (Y&LT;5) {if (y-this.y!=1) return (false); }else{if (!) ( (y-this.y==1&&x==this.x) | | (Y==this.y&&math.abs (this.x-x) ==1)) return (false); } break; }else{if (y>4) {if (Y-this.y!=-1) return (false); }else{if (!) ( (y-this.y==-1&&x==this.x) | | (Y==this.y&&math.abs (this.x-x) ==1)) return (false); }//} break; Case "Stroke"://if (curplayer%2==0) {if (y>4) {if (y-this.y!=-1 ) return (false); }else{if (!) ( (y-this.y==-1&&x==this.x) | | (Y==this.y&&math.abs (this.x-x) ==1)) return (false); } break; }else{if (y&LT;5) {if (y-this.y!=1) return (false); }else{if (!) ( (y-this.y==1&&x==this.x) | | (Y==this.y&&math.abs (this.x-x) ==1)) return (false); }//} break; Case "Cannon": if (this.x!=x&&this.y!=y) return (false); if (cch[y*9+x]&&cch[y*9+x].player!=this.player) {mn=0; if (this.x==x) {mi=y>this.y?this.y:y; ma=y>this.y?y:this.y; for (Var i=mi+1;i<ma;i++) if (cch[i*9+this.x]) mn++; if (Mn!=1) return (false); }else{mi=x>this.x?this.x:x; ma=x>this.x?x:this.x; for (Var i=mi+1;i<ma;i++) if (cch[this.y*9+i]) mn++; if (Mn!=1) return (false); }}else{if (this.x==x) {mi=y>this.y?this.y:y; ma=y>this.y?y:this.y; for (Var i=mi+1;i<ma;i++) if (Cch[i*9+this.x]) return (false); }else{mi=x>this.x?this.x:x; ma=x>this.x?x:this.x; for (Var i=mi+1;i<ma;i++) if (Cch[this.y*9+i]) return (false); }} break; Case "": Break; }} Cch[this.y*9+this.x]=null; Cch[y*9+x]=this; if (!force) His.push ("Move" +this.player+ "" +this.innertext+ "" +this.x+ "," +this.y+ "" +x+ "," +y "); this.style.position= "Absolute"; this.style.left=25+x*80; this.style.top=25+y*80; This.x=x; This.y=y; return (true); function Chessman_destory () {var tmp; His.push ("DestorY "+this.player+" "+this.innertext+" "+this.x+", "+this.y"; Tmp=document.createelement ("div"); Tmp.classname= "Chessman_" +this.player; Tmp.innertext=this.innertext; Tmp.style.float= "left"; Eval ("D_his_" +this.player). appendchild (TMP); This.parentNode.removeChild (this); function Exchange () {var x, y; var ccch=new Array (); for (Var i=0;i<cch.length;i++) {if (!cch[i]) continue; x=i%9; Y=parseint (I/9); ccch[(9-y) *9+x]=cch[i]; for (Var i=0;i<ccch.length;i++) {if (!ccch[i]) continue; x=i%9; Y=parseint (I/9); Ccch[i].moveto (x,y,true); } cch=ccch; function Do_click () {var x, y; var o=event.srcelement; if (O.player) {if (Document.currentchessman) {if (Document.currentchessman.player==o.player) { Document.currentchessman.style.border= ""; Document.currentchessman=o; Document.currentchessman.style.border= "1px solid" +document.currentchessman.player; }else{if (!document.currentchessman.moveto (O.X,O.Y)) return; O.destory (); Document.currentchessman.style.border= ""; Document.currentchessman=null; Exchange (); curplayer++; }}else{if (o.player!=players[curplayer%2]) return; Document.currentchessman=o; Document.currentchessman.style.border= "1px solid" +document.currentchessman.player; }}else{if (Document.currentchessman) {if ((event.x-50)%80>25&& (event.x-50)%80<55 )|| ((event.y-50)%80>25&& (event.y-50)%80<55)) Return X=math.round ((EVENT.X+DOCUMENT.BODY.SCROLLLEFT-50)/80); Y=math.round ((EVENT.Y+DOCUMENT.BODY.SCROLLTOP-50)/80); if (x>-1&&x<9&&y>-1&AMP;&AMP;Y&LT;10) {if (!document.currentchessman.moveto (x,y)) return; Document.currentchessman.style.border= ""; Document.currentchessman=null; Exchange (); curplayer++; function Do_context () {if (Document.currentchessman) {Document.currentChessman.style}}}} . border= ""; Document.currentchessman=null; return (false); } function Undo () {var o, S, T, p, x1, x2, x3, y1, Y2, y3; if (his.length==0) return; S=his.pop (). Split (""); if (s[0]== "move") {X1=number (S[3].split (",") [0]); Y1=number (S[3].split (",") [1]); X2=number (S[4].split (",") [0]); Y2=number (S[4].split (",") [1]); O=CCH[Y2*9+X2]; O.moveto (x1,y1,true); curplayer--; }else if (s[0]== "Destory") {p=s[1]; T=S[2]; X1=number (S[3].split (",") [0]); Y1=numbER (S[3].split (",") [1]); S=his.pop (). Split (""); X2=number (S[3].split (",") [0]); Y2=number (S[3].split (",") [1]); X3=number (S[4].split (",") [0]); Y3=number (S[4].split (",") [1]); O=CCH[Y3*9+X3]; O.moveto (x2,y2,true); curplayer--; Createchessman (T,X1,Y1,P); } </script> <input type= "button" value= "re-Open" onclick= "window.location.reload ();" > <input type= "but Ton "value=" undo "onclick=" Undo (); "> <div id=" d_his_red "></div> <div id=" D_his_blue "></div>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.