JS block Dodge game Code _javascript Tips

Source: Internet
Author: User
Drag the mouse Red square, you can start, do not let the blue square touch your control of the Red Square
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" > <!--saved from Url= (0037) http://www.xeron.org/cosas/ escapa.htm--> <ptml><pead><title>www.jb51.net Community escapa! Red box Dodge game </TITLE> <meta Http-equiv=content-type content= "text/html; charset=windows-1252 "> <script language=javascript type=text/javascript> isNS4 = (document.layers)? True:false; IsIE4 = (document.all &&!document.getelementbyid)? True:false; IsIE5 = (document.all && document.getElementById)? True:false; IsNS6 = (!document.all && document.getElementById)? True:false; var CurX, Cury, curX2, curY2, Boxx, BoxY, moving=0, touch=0; var gametime=0, started=0, speed; var starttime, Endtime, finaltime=0; Pass Finaltime to popup windows to ask for initials var enemyxdir = new Array (1,1,1,1); var enemyydir = new Array (1,1,1,1); if (isNS4 | | isNS6) {document.captureevents (event.mouseup| event.mousedown| Event.mousemove); } docuMent.onmousedown = start; Document.onmousemove = checklocation; Document.onmouseup = stop; function Startclock () {var today = new Date (); starttime = Today.gettime ();} function Endclock () {var today = new Date (); endtime = Today.gettime ();} function Calctime () {var time = (endtime-starttime-0)/1000; return time;} function Giveposx (divname) {if (isNS4) var posleft = Document.layers[divname].left; else if (isIE4 | | isIE5) var posleft = document.all (divname). Style.pixelleft; else if (isNS6) var posleft = parseint (document.getElementById (divname). Style.left + ""); return posleft; The function Giveposy (divname) {if (isNS4) var postop = Document.layers[divname].top; else if (isIE4 | | isIE5) var postop = document.all (divname). Style.pixeltop; else if (isNS6) var postop = parseint (document.getElementById (divname). Style.top + ""); return postop; function Setposx (divname, xpos) {if (isNS4) document.layers[divname].left = xpos;else if (isIE4 | | isIE5) document.all (divname). Style.pixelleft = xpos; else if (isNS6) document.getElementById (divname). Style.left = xpos; function Setposy (divname, ypos) {if (isNS4) document.layers[divname].top = ypos; else if (isIE4 | | isIE5) document.all (divname). Style.pixeltop = Ypos; else if (isNS6) document.getElementById (divname). Style.top = Ypos; function Givesize (divname, dimension) {var divsize = 0; if (dimension = = ' Y ') {if (isNS4) divsize = document.layers[divname].clip.height; else if (isIE4 | | isIE5) divsize = document.all (divname). Style.pixelheight; else if (isNS6) divsize = parseint (document.getElementById (divname). Style.height + ""); else if (dimension = = ' X ') {if (isNS4) divsize = document.layers[divname].clip.width; else if (isIE4 | | isIE5) divsize = document.all (divname). Style.pixelwidth; else if (isNS6) divsize = parseint (dOcument.getelementbyid (divname). Style.width + ""); return divsize; }//Check to the If ' box ' is touching ' enemy1 ' function checktouching (num) {var enemy = "enemy" + num + "" V Ar difx = giveposx (' box ')-giveposx (Enemy)-0; -0 converts to integer var dify = giveposy (' box ')-Giveposy (Enemy)-0; Set touch = 1 if it's touching an enemy if (Difx > ( -1 * givesize (' box ', ' X ')) && Difx < Givesize (E Nemy, ' x ') && dify > ( -1 * givesize (' box ', ' Y ')) && dify < Givesize (enemy, ' Y ')) {touch = 1; else Touch = 0; function Movenemy (num,step_x,step_y) {var enemy = "enemy" + num + "" "var Enemyx = givesize (Enemy, ' X '); var enemyy = givesize (enemy, ' Y '); if (Giveposx (enemy) >= (450-enemyx) | | giveposx (enemy) <= 0) {Enemyxdir[num] =-1 * enemyxdir[num]; } if (Giveposy (enemy) >= (450-enemyy) | | giveposy (enemy) <= 0) {EnemyydIr[num] =-1 * enemyydir[num]; var newposx = Giveposx (enemy) + (Step_x*enemyxdir[num]) + 0; var newposy = Giveposy (enemy) + (Step_y*enemyydir[num]) + 0; Setposx (Enemy, NEWPOSX); Setposy (Enemy, Newposy); checktouching (num + ""); if (touch = = 1) {stop (); reset (); } function Movenemies () {gametime = gametime + 1 if (gametime >= 0 && gametime < MB) Speed = 80; else if (gametime >= && gametime <) speed = 60; else if (gametime >= && gametime <) speed = 40; else if (gametime >= && gametime <) speed = 30; else if (gametime >= && gametime <) speed = 20; else speed = 10; Window.status = "Speed:" + Speed + "gametime:" + gametime; Movenemy (0,-10,12); Movenemy (1,-12,-20); Movenemy (2,15,-13); Movenemy (3,17,11); SetTimeout (Movenemies,speed); } function StarT (e) {if (started = 0) {movenemies (); Startclock (); started = 1; } CurX = (isNS4 | | | isNS6)? E.pagex:window.event.x; Cury = (IsNS4 | | | isNS6)? E.pagey:window.event.y; curX2 = eval (curX-40); curY2 = eval (curY-40); Boxx = eval (curX-20); BoxY = eval (curY-20); var boxleft = giveposx (' box '); var boxtop = giveposy (' box '); if (CurX > Boxleft && curX2 < boxleft && Cury > Boxtop && curY2 < boxtop) {m oving = 1; Setposx (' box ', Boxx); Setposy (' box ', BoxY); if (isNS4 | | isNS6) {document.captureevents (event.mousemove); }} function Stop (e) {moving=0; if (isNS4 | | isNS6) {document.releaseevents (event.mousemove); } function Reset (e) {endclock (); moving=0; if (isNS4 | | isNS6) {document.releaseevents (event.mousemove); } if (Finaltime = = 0) {Finaltime = CALctime (); Window.alert (' You hold ' + finaltime + ' seconds ... salutations Fp '); var entername = window.confirm (' Enter your name? '); if (entername) {//window.open ("?" + finaltime, ' WinWin ', ' width=300,height=500,left=40,top=40,st Atus=1,resizable '); Document.location.reload (); }//Else document.location.reload (); Document.location.reload (); }} function Checklocation (e) {CurX = (isNS4 | | isNS6)? e.pagex:window.event.x; Cury = (IsNS4 | | | isNS6)? E.pagey:window.event.y; Boxx = eval (curX-20); BoxY = eval (curY-20); Checktouching (' 1 '); if (moving = = 1 && Touch = = 0) {setposx (' box ', Boxx); Setposy (' box ', BoxY); if (Cury > 381 && curx >-&& cury < && CurX < 381) return false; else Stop (); Reset (); else if (touch = 1){Stop (); reset (); } </SCRIPT> <meta content= "MSHTML 6.00.2800.1106" name=generator></pead> <body text= #000000 BgC olor= #ffffff leftmargin=0 topmargin=0 marginwidth= "0" marginheight= "0" > <div id=box style= "left:205px"; width:40px; Position:absolute; top:205px; height:40px; Background-color: #990000; Layer-background-color: #990000 "> <table height=40 width=40> <TBODY> <TR> <td>&nbsp ;</td></td></tr></tbody></table></div> <div id=enemy0 style= "left:270px; width:60px; Position:absolute; top:60px; height:50px; Background-color: #000099; Layer-background-color: #000099 "> <table height=50 width=60> <TBODY> <TR> <td>&nbsp ;</td></tr></tbody></table></div> <div id=enemy1 style= "left:300px; width:100px; Position:absolute; top:330px; height:20px; Background-color: #000099; Layer-backgrounD-color: #000099 "> <table height=20 width=100> <TBODY> <TR> &LT;TD&GT;&NBSP;&LT;/TD&GT;&L t;/tr></tbody></table></div> <div id=enemy2 style= "left:70px; width:30px; Position:absolute; top:320px; height:60px; Background-color: #000099; Layer-background-color: #000099 "> <table height=60 width=30> <TBODY> <TR> <td>&nbsp ;</td></tr></tbody></table></div> <div id=enemy3 style= "left:70px; width:60px; Position:absolute; top:70px; height:60px; Background-color: #000099; Layer-background-color: #000099 "> <table height=60 width=60> <TBODY> <TR> <td>&nbsp ;</td></tr></tbody></table></div> <table cellspacing=0 cellPadding=0 border=0> <!--row 1--> <TBODY> <TR> <td width=50 bgcolor= #000000 height=50> <table&gt ; <TBODY><TR> <TD></TD></TR></TBODY></TABLE></TD> <td width=50 bgcolor = #000000 height=50> <TABLE> <TBODY> <TR> <td></td>&lt ;/tr></tbody></table></td> <td width=50 bgcolor= #000000 height=50> <TABLE> <TBODY> <TR> <td></td></tr></tbody></table></td&gt ; &LT;TD width=50 bgcolor= #000000 height=50> <TABLE> <TBODY> <TR> & Lt td></td></tr></tbody></table></td> <td width=50 bgColor= #000000 height=50> <TABLE> <TBODY> <TR> <TD></TD></TR></TBODY>< /table></td> <td width=50 bgcolor= #000000 height=50> <TABLE> <TBODY> <TR> <TD></TD></TR></TBODY></TABLE></TD> <td width=50 bgcolor= #000000 H eight=50> <TABLE> <TBODY> <TR> &LT;TD&GT;&LT;/TD&GT;&LT;/TR&GT;&L t;/tbody></table></td> <td width=50 bgcolor= #000000 height=50> <TABLE> ; Tbody> <TR> <TD></TD></TR></TBODY></TABLE></TD> < TD width=50 bgcolor= #000000 height=50> <TABLE> <TBODY> <TR> <t d></td></tr></tbody></table></td></tr><!--Row 2--> <TR> <T D width=50 bgcolor= #000000 height=50> <TABLE> <TBODY> <TR> <td ></TD></TR></TBODY></TABLE></TD> <td width=50 height=50> <TABLE> <TBODY> <TR> <TD></TD></TR></TBODY></TABLE></TD> &LT;TD width=5 0 height=50> <TABLE> <TBODY> <TR> <td></td></tr&gt ;</tbody></table></td> <td width=50 height=50> <TABLE> <TBODY> <TR> <TD></TD></TR></TBODY></TABLE></TD> &LT;TD width=50 height=50> <TABLE> <TBODY> <TR> <td></td></tr>& lt;/tbody></table></td> <td width=50 height=50> <TABLE> <TBODY> <TR> <TD></TD></TR></TBODY></TABLE></TD> &LT;TD width=50 He ight=50> <TABLE> <TBODY> <TR> <td></td></tr>&lt ;/tbody></table></td> <td width=50 height=50> <TABLE> <TBODY> <TR> <TD></TD></TR></TBODY></TABLE></TD> <td width=50 bgcolor= #000000 height=50& Gt <TABLE> <TBODY> <TR> <td></td></tr></tbody></tab le></td></tr><!--Row 3--> <TR> <td width=50 bgcolor= #000000 height=50> & Lt table> <TBODY> <TR> &LT;TD&GT;&LT;/TD&GT;&LT;/TR&GT;&LT;/TBODY&GT;&LT;/TABLE&G t;</td> <td width=50 height=50> <TABLE> <TBODY> <TR> <TD></TD></TR></TBODY></TABLE></TD> <td width=50 height=50> <ta ble> <TBODY> <TR> <TD></TD></TR></TBODY></TABLE> </TD> &LT;TD width=50 height=50> <TABLE> <TBODY> <TR> &LT;TD&GT;&L t;/td></tr></tbody></table></td> <td width=50 height=50> <TABLE> <TBODY> <TR> <TD></TD></TR></TBODY></TABLE></TD> &LT;TD width=50 height=50> <TABLE> <TBODY> <TR> <TD>< /td></tr></tbody></table></td> <td width=50 height=50> <TABLE> <TBODY> <TR> <TD></TD></TR></TBODY></TABLE></TD> &LT;TD width=50 height=50> <TABLE> <TBODY> <TR> <td></t d></tr></tbody></table></td> <td width=50 bgcolor= #000000 height=50> <TABL E> <tbody> <TR> <TD></TD></TR></TBODY></TABLE></TD></TR>< !--Row 4--> <TR> <td width=50 bgcolor= #000000 height=50> <TABLE> <tbody& Gt <TR> <TD></TD></TR></TBODY></TABLE></TD> <td width=50 height= 50> <TABLE> <TBODY> <TR> <td></td></tr></tbo dy></table></td> <td width=50 height=50> <TABLE> <TBODY> &L t;tr> <TD></TD></TR></TBODY></TABLE></TD> <td width=50 height=50 > <TABLE> <TBODY> <TR> <td></td></tr></tbody ></TABLE></TD> <td width=50 height=50> <TABLE> <TBODY> < Tr> <TD></TD></TR></TBODY></TABLE></TD> <td width=50 height=50> & Lt table> <TBODY> <TR> &LT;TD&GT;&LT;/TD&GT;&LT;/TR&GT;&LT;/TBODY&GT;&LT;/TABLE&G t;</td> <td width=50 height=50> <TABLE> <TBODY> <TR> <TD></TD></TR></TBODY></TABLE></TD> <td width=50 height=50> <ta ble> <TBODY> <TR> <TD></TD></TR></TBODY></TABLE> </TD> <td width=50 bgcolor= #000000 height=50> <TABLE> <TBODY> <tr > <TD></TD></TR></TBODY></TABLE></TD></TR><!--Row 5--> <TR> <td width=50 bgcolor= #000000 height=50> <TABLE> <TBODY> <tr& Gt <td></TD></TR></TBODY></TABLE></TD> <td width=50 height=50> <TABLE> <TBODY> <TR> <td></td></tr></tbody></table></td& Gt &LT;TD width=50 height=50> <TABLE> <TBODY> <TR> <td></td ></TR></TBODY></TABLE></TD> <td width=50 height=50> <TABLE> &L T Tbody> <TR> <TD></TD></TR></TBODY></TABLE></TD> < TD width=50 height=50> <TABLE> <TBODY> <TR> <TD></TD> </TR></TBODY></TABLE></TD> <td width=50 height=50> <TABLE> &LT;TB ody> <TR> <TD></TD></TR></TBODY></TABLE></TD> &LT;TD Width=50 Height=50> <TABLE> <TBODY> <TR> <TD></TD></TR>< /tbody></table></td> <td width=50 height=50> <TABLE> <TBODY> <TR> <TD></TD></TR></TBODY></TABLE></TD> <td width=50 bgcol or= #000000 height=50> <TABLE> <TBODY> <TR> <td></td>& lt;/tr></tbody></table></td></tr><!--Row 6--> <TR> <td width=50 BgColo r= #000000 height=50> <TABLE> <TBODY> <TR> &LT;TD&GT;&LT;/TD&GT;&L t;/tr></tbody></table></td> <td width=50 height=50> <TABLE> <TBOD Y> <TR> <TD></TD></TR></TBODY></TABLE></TD> <td W Idth=50 height=50> <TABLE> <TBODY> <TR> <td></td></tr></tbody>&lt ;/table></td> <td width=50 height=50> <TABLE> <TBODY> <TR> <TD></TD></TR></TBODY></TABLE></TD> &LT;TD width=50 height=50> <TABLE> <TBODY> <TR> <td></td></tr></tbody></ table></td> <td width=50 height=50> <TABLE> <TBODY> <TR> <TD></TD></TR></TBODY></TABLE></TD> &LT;TD width=50 height=50> <TABLE> <TBODY> <TR> <td></td></tr></tbody></ta ble></td> <td width=50 height=50> <TABLE> <TBODY> <TR> <td></td></TR></TBODY></TABLE></TD> <td width=50 bgcolor= #000000 height=50> <table > <TBODY> <TR> <td></td></tr></tbody></table>&lt ;/td></tr><!--Row 7--> <TR> <td width=50 bgcolor= #000000 height=50> <table& Gt <TBODY> <TR> <TD></TD></TR></TBODY></TABLE></TD> &LT;TD width=50 height=50> <TABLE> <TBODY> <TR> <td></td ></TR></TBODY></TABLE></TD> <td width=50 height=50> <TABLE> &L T Tbody> <TR> <TD></TD></TR></TBODY></TABLE></TD> < TD width=50 height=50> <TABLE> <TBODY> <TR> <TD></TD> </tr></tbody></table></td> <td width=50 height=50> <TABLE> <TBODY> <TR> <TD></TD></TR></TBODY></TABLE></TD> &LT;TD width=50 height=50> <TABLE> <TBODY> <TR> <TD></TD></TR> </TBODY></TABLE></TD> <td width=50 height=50> <TABLE> <TBODY> <TR> <TD></TD></TR></TBODY></TABLE></TD> <td width=50 H eight=50> <TABLE> <TBODY> <TR> &LT;TD&GT;&LT;/TD&GT;&LT;/TR&GT;&L t;/tbody></table></td> <td width=50 bgcolor= #000000 height=50> <TABLE> ; Tbody> <TR> <td></td></tr></tbody></table></td></tr&gt ;<!--Row 8--> <TR> <td width=50 bgcolor= #000000 height=50> <TABLE> <TBODY> <t r> <TD></TD></TR></TBODY></TABLE></TD> <td width=50 height=50&gt ; <TABLE> <TBODY> <TR> <td></td></tr></tbody></tab le></td> <td width=50 height=50> <TABLE> <TBODY> <TR> <TD></TD></TR></TBODY></TABLE></TD> <td width=50 height=50> &L T table> <TBODY> <TR> &LT;TD&GT;&LT;/TD&GT;&LT;/TR&GT;&LT;/TBODY&GT;&LT;/TABLE&G t;</td> <td width=50 height=50> <TABLE> <TBODY> <TR> <TD></TD></TR></TBODY></TABLE></TD> <td width=50 height=50> <ta Ble> <TBODY> <TR> <TD></TD></TR></TBODY></TABLE></TD> &LT;TD width=50 height=50> <TABLE> <TBODY> <TR> <td>&lt ;/td></tr></tbody></table></td> <td width=50 height=50> <TABLE> <TBODY> <TR> <TD></TD></TR></TBODY></TABLE></TD> &LT;TD width=50 bgcolor= #000000 height=50> <TABLE> <TBODY> <TR> <TD></TD></TR></TBODY></TABLE></TD></TR><!--Row 9--> <TR> &LT;TD width=50 bgcolor= #000000 height=50> <TABLE> <TBODY> <TR> <TD></TD></TR></TBODY></TABLE></TD> <td width=50 bgcolor= #000000 height=50& Gt <TABLE> <TBODY> <TR> <td></td></tr></tbody></table></td&gt ; &LT;TD width=50 bgcolor= #000000 height=50> <TABLE> <TBODY> <TR> & Lt td></td></tr></tbody></table></td> <td width=50 bgColor= #000000 height=50> <TABLE> <TBODY> <TR> <TD></TD></TR></TBODY>< /table></td> <td width=50 bgcolor= #000000 height=50> <TABLE> <TBODY> <TR> <TD></TD></TR></TBODY></TABLE></TD> <td width=50 BgC olor= #000000 height=50> <TABLE> <TBODY> <TR> <td></td&gt ;</tr></tbody></table></td> <td width=50 bgcolor= #000000 height=50> <TABLE&gt ; ,; Tbody> <TR> <TD></TD></TR></TBODY></TABLE></TD> < TD width=50 bgcolor= #000000 height=50> <TABLE> <TBODY> <TR> <t d></td></tr></tbody></table></td> <td width=50 bgColor= #000000 height=50> <TABLE> <TBODY> <TR> <td></td></tr></tbody></ table></td></tr></tbody></table> <font face= "Verdana,arial,helvetica" size= "2" >  </font><div id= "Layer1" > click onto the red block and jump over it:move the red B Lock avoiding crash with the blue ones Don don't the edge of the black. If you can reach the than seconds, you are a genius. It is said this pilots from the US Air Force are forced to reach 2 minutes.</div&Gt </BODY></HTML>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

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.