100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > javascript编写的网页小游戏 很给力

javascript编写的网页小游戏 很给力

时间:2023-08-14 14:11:23

相关推荐

javascript编写的网页小游戏 很给力

这是游戏界面

以下为游戏代码:

1 <html> 2 <HEAD> 3 4 <SCRIPT LANGUAGE="JavaScript"> 5 <!-- Original: Nick Young () --> 6 <!-- recompose: Pakchoi () --> 7 8 var timerID = null; 9 var INT = 40; 10 var loadFLG = 0; 11 var gameFLG = 0; 12 var missFLG = 0; 13 var tim = 0; 14 var blcol = new Array(5); // block color 15 var blsta = new Array(40); // block status 16 var blNO = new Array(40); // block No 17 var blclr = 0; // clear block 18 var ballX = 0; // ball data 19 var ballY = 0; 20 var ballN = 5; 21 var ballDX = 0; 22 var ballDY = 0; 23 var tmpRL = 193; 24 var X = 0; 25 blcol[0] = "blue"; 26 blcol[1] = "yello"; 27 blcol[2] = "red"; 28 blcol[3] = "purple"; 29 blcol[4] = "#FF0000"; 30 blcol[5] = "black"; 31 32 function mainF() 33 { 34 clearTimeout(timerID); 35 tim = tim + 1; 36 with (Math) 37{ 38 tmptim = floor(tim / 10)}; 39 document.forms[0].TM.value = tmptim; 40 ballX = ballX + ballDX; 41 ballY = ballY + ballDY; 42 outCHK(); 43 blkCHK(); 44 ball.style.posTop = ballY; 45 ball.style.posLeft = ballX; 46 racket.style.posLeft = tmpRL; 47 if (gameFLG == 01) 48 { 49timerID = setTimeout("mainF()", INT); 50} 51} 5253 function initG() 54{ 55 if (blclr >= 40) 56 { 57blclr = 0; 58tim = 0; 59ballN = 3; 60with (Math) 61 { 62 tmptim = floor(tim / 10); 63 } 64document.forms[0].TM.value = tmptim; 65clrmes.style.posTop = -1000; 66clrmes.style.posLeft = -1000; 67ovrmes.style.posTop = -1000; 68ovrmes.style.posLeft = -1000; 69for (ib = 0; ib < 5; ib++) 70 { 71 for (ia = 0; ia < 8; ia++) 72{ 73 chc(ib * 8 + ia +1, ib); 74 blsta[ib * 8 + ia] = ib; 75} 76 } 77 } 78 document.forms[0].BL.value = ballN; 79 starter.style.posTop = -1000; 80 starter.style.posLeft = -1000; 81 gameFLG = 1; 82 loadFLG = 1; 83 ballX = 209; 84 ballY = 270; 85 ballDX =- 8; 86 ballDY =- 8; 87 tmpRL = 193; 88 missFLG = 0; 89 timerID = setTimeout("mainF()", INT); 90} 91 92 function SUP() 93 { 94UP.outerHTML = "<DIV ID='DN' STYLE='position:absolute'><A HREF='javascript:SDN()'>SPEED DOWN</A></DIV>"; 95DN.style.posTop = 170; 96DN.style.posLeft = 432; 97INT = 40; 98 } 99 function SDN()100 {101DN.outerHTML = "<DIV ID='UP' STYLE='position:absolute'><A HREF='javascript:SUP()'>SPEED UP</A></DIV>";102UP.style.posTop = 170;103UP.style.posLeft = 432;104INT = 50;105 }106 function MouseMv() 107 {108 if (loadFLG == 1) 109 {110tmpRL = X - 20;111if (tmpRL < 16) { tmpRL = 16; }112if (tmpRL > 370) { tmpRL = 370; }113 }114 }115 function outCHK() 116 {117if (ballX < 16){ ballX = 32 - ballX; ballDX = -ballDX; }118if (ballX > 401){ ballX = 802 - ballX; ballDX = -ballDX; }119if (ballY < 16){ ballY = 32 - ballY; ballDY = -ballDY; }120if (ballY >= 272)121 {122 if (missFLG == 0) 123{124 tmpX = (ballDX / ballDY) * (272 - ballY) + ballX;125 if (tmpX >= tmpRL - 12)126{127 if (tmpX <= tmpRL + 42) 128 {129ballY = 272; ballDY = -ballDY;130ballX = tmpX;131ballRD = tmpX - tmpRL;132with (Math){ ballDX = 8 * abs(ballDX) / ballDX; }133if (ballRD < -4){ ballDX = -15; }134if (ballRD > 36){ ballDX = 15; }135if (ballRD >= 14){ if (ballRD <= 16) { ballDX = -2; } }136if (ballRD >= 17){ if (ballRD <= 20) { ballDX = 2; } }137if (ballRD >= 0){ if (ballRD <= 4) { ballDX = -4; } }138if (ballRD >= 28){ if (ballRD <= 32) { ballDX = 4; } }139if (ballRD >= -4){ if (ballRD <= -1) { ballDX = -11; } }140if (ballRD >= 33){ if (ballRD <= 36) { ballDX = 11; } }141}142 }143 if (ballDY > 0){ missFLG = 1; }144 } 145else146 {147 if (ballY > 290){ missFLG = 0; ballN = ballN - 1; gameEnd(); }148 }149 }150 }151 function blkCHK() 152 {153 tmpY = ballY + 4;154 tmpX = ballX + 4;155 if (tmpY >= 48)156{ 157 if (tmpY <= 147) 158 {159 if (tmpX >= 29)160 {161if (tmpX <= 396)162 {163 with (Math) 164 {165 ia = floor((tmpX - 29) / 46);166 ib = floor((tmpY - 48) / 20);167 ic = ib * 8 + ia;168 }169 if (blsta[ic] <= 4) 170 {171 tmpbc = blsta[ic] + 1;172 blsta[ic] = tmpbc;173 chc(ic + 1, tmpbc);174 if (tmpbc == 5){ blclr = blclr + 1; }175 if (blclr >= 40){ gameEnd(); }176 if (ballDX > 0) 177{178 iy=(ballDY / ballDX) * (29 + 46 * ia - tmpX) + tmpY;179 if (iy > 48 + 20 * ib + 18) 180 {181 tmpY1 = 48 + 20 * ib + 18;182 tmpX1 = (ballDX / ballDY) * (48 + 20 * ib + 18 - tmpY) + tmpX;183 ballX = tmpX1 - 4;184 ballY = tmpY1 - 4;185 ballDY = -ballDY;186} 187 else 188 {189 if (iy < 44 + 20 * ib) 190 {191tmpY1 = 48 + 20 * ib;192tmpX1 = (ballDX / ballDY) * (48 + 20 * ib - tmpY) + tmpX;193ballX = tmpX1 - 4;194ballY = tmpY1 - 4;195ballDY = -ballDY;196 } 197 else198 {199tmpX1 = 29 + 46 * ia;200tmpY1 = (ballDY / ballDX) * (29 + 46 * ia - tmpX) + tmpY;201ballX = tmpX1 - 4;202ballY = tmpY1 - 4;203ballDX = -ballDX;204 }205}206} 207 else 208{209 iy = (ballDY / ballDX) * (29+46 * ia + 44 - tmpX) + tmpY;210 if (iy > 48 + 20 * ib + 18) 211 {212 tmpY1 = 48 + 20 * ib + 18;213 tmpX1 = (ballDX / ballDY) * (48 + 20 * ib + 18 - tmpY) + tmpX;214 ballX = tmpX1 - 4;215 ballY = tmpY1 - 4;216 ballDY = -ballDY;217} 218 else 219 {220 if (iy < 44 + 20 * ib) 221 {222tmpY1 = 48 + 20 * ib;223tmpX1 = (ballDX / ballDY) * (48 + 20 * ib - tmpY) + tmpX;224ballX = tmpX1 - 4;225ballY = tmpY1 - 4;226ballDY = -ballDY;227 } 228 else229 {230tmpX1 = 29+46 * ia + 44;231tmpY1 = (ballDY / ballDX) * (29 + 46 * ia + 44 - tmpX) + tmpY;232ballX = tmpX1 - 4;233ballY = tmpY1 - 4;234ballDX = -ballDX;235 }236}237}238 }239 }240 }241}242}243 }244 function gameEnd()245 {246document.forms[0].BL.value = ballN;247gameFLG = 0;248loadFLG = 0;249starter.style.posTop = 200;250starter.style.posLeft = 180;251if (blclr >= 40) 252 {253 clrmes.style.posTop = 150;254 clrmes.style.posLeft = 160;255 }256if (ballN <= 0)257 {258 ovrmes.style.posTop = 150;259 ovrmes.style.posLeft = 160;260 blclr = 40;261 }262 }263 function onLD() 264 {265bgIE.style.posTop = 16;266bgIE.style.posLeft = 16;267ball.style.posTop = 270;268ball.style.posLeft = 209;269racket.style.posTop = 280;270racket.style.posLeft = 193;271info.style.posTop = 16;272info.style.posLeft = 432;273starter.style.posTop = -1000;274starter.style.posLeft = -1000;275clrmes.style.posTop = -1000;276clrmes.style.posLeft = -1000;277ovrmes.style.posTop = -1000;278ovrmes.style.posLeft = -1000;279DN.style.posTop = 170;280DN.style.posLeft = 432;281for (ib = 0; ib < 5; ib++)282 {283 for (ia = 0; ia < 8; ia++) 284 {285 blsta[ib * 8 + ia] = ib;286 }287 }288starter.style.posTop = 200;289starter.style.posLeft = 180;290 }291 function chc(bno,bcl)292 {293tmpbno = ((bno < 10.5) ? "b0" : "b") + (bno-1); 294eval(tmpbno).bgColor = blcol[bcl];295 }296 // End -->297 </script>298 </HEAD>299 300 301 <BODY onLoad="onLD();" onMouseMove='X=event.x;MouseMv();'>302 <span id=info style='position:absolute'>303 <pre>304 <font style="font-size:24px" color="#000044"><i><b>PONG</b></i></font>305 <form>306 Ball: <input type=text name=BL size=5 value=5>307 Time: <input type=text name=TM size=5 value=0>308 </form>309 </pre>310 </span>311 312 <SCRIPT LANGUAGE="JavaScript">313 <!-- block image write-->314 315 with (document) 316 {317write("<table id='bgIE' width='394' height='300' bgcolor='#000000' style='position:absolute'><td></td></table>");318 319write("<table id='b00' width='42' height='16' bgcolor='#FFFF00' style='position:absolute; top:48; left:29'><td></td></table>");320write("<table id='b01' width='42' height='16' bgcolor='#FFFF00' style='position:absolute; top:48; left:75'><td></td></table>");321write("<table id='b02' width='42' height='16' bgcolor='#FFFF00' style='position:absolute; top:48; left:121'><td></td></table>");322write("<table id='b03' width='42' height='16' bgcolor='#FFFF00' style='position:absolute; top:48; left:167'><td></td></table>");323write("<table id='b04' width='42' height='16' bgcolor='#FFFF00' style='position:absolute; top:48; left:213'><td></td></table>");324write("<table id='b05' width='42' height='16' bgcolor='#FFFF00' style='position:absolute; top:48; left:259'><td></td></table>");325write("<table id='b06' width='42' height='16' bgcolor='#FFFF00' style='position:absolute; top:48; left:305'><td></td></table>");326write("<table id='b07' width='42' height='16' bgcolor='#FFFF00' style='position:absolute; top:48; left:351'><td></td></table>");327 328write("<table id='b08' width='42' height='16' bgcolor='#FFCF00' style='position:absolute; top:68; left:29'><td></td></table>");329write("<table id='b09' width='42' height='16' bgcolor='#FFCF00' style='position:absolute; top:68; left:75'><td></td></table>");330write("<table id='b10' width='42' height='16' bgcolor='#FFCF00' style='position:absolute; top:68; left:121'><td></td></table>");331write("<table id='b11' width='42' height='16' bgcolor='#FFCF00' style='position:absolute; top:68; left:167'><td></td></table>");332write("<table id='b12' width='42' height='16' bgcolor='#FFCF00' style='position:absolute; top:68; left:213'><td></td></table>");333write("<table id='b13' width='42' height='16' bgcolor='#FFCF00' style='position:absolute; top:68; left:259'><td></td></table>");334write("<table id='b14' width='42' height='16' bgcolor='#FFCF00' style='position:absolute; top:68; left:305'><td></td></table>");335write("<table id='b15' width='42' height='16' bgcolor='#FFCF00' style='position:absolute; top:68; left:351'><td></td></table>");336 337write("<table id='b16' width='42' height='16' bgcolor='#FF7F00' style='position:absolute; top:88; left:29'><td></td></table>");338write("<table id='b17' width='42' height='16' bgcolor='#FF7F00' style='position:absolute; top:88; left:75'><td></td></table>");339write("<table id='b18' width='42' height='16' bgcolor='#FF7F00' style='position:absolute; top:88; left:121'><td></td></table>");340write("<table id='b19' width='42' height='16' bgcolor='#FF7F00' style='position:absolute; top:88; left:167'><td></td></table>");341write("<table id='b20' width='42' height='16' bgcolor='#FF7F00' style='position:absolute; top:88; left:213'><td></td></table>");342write("<table id='b21' width='42' height='16' bgcolor='#FF7F00' style='position:absolute; top:88; left:259'><td></td></table>");343write("<table id='b22' width='42' height='16' bgcolor='#FF7F00' style='position:absolute; top:88; left:305'><td></td></table>");344write("<table id='b23' width='42' height='16' bgcolor='#FF7F00' style='position:absolute; top:88; left:351'><td></td></table>");345 346write("<table id='b24' width='42' height='16' bgcolor='#FF3F00' style='position:absolute; top:108; left:29'><td></td></table>");347write("<table id='b25' width='42' height='16' bgcolor='#FF3F00' style='position:absolute; top:108; left:75'><td></td></table>");348write("<table id='b26' width='42' height='16' bgcolor='#FF3F00' style='position:absolute; top:108; left:121'><td></td></table>");349write("<table id='b27' width='42' height='16' bgcolor='#FF3F00' style='position:absolute; top:108; left:167'><td></td></table>");350write("<table id='b28' width='42' height='16' bgcolor='#FF3F00' style='position:absolute; top:108; left:213'><td></td></table>");351write("<table id='b29' width='42' height='16' bgcolor='#FF3F00' style='position:absolute; top:108; left:259'><td></td></table>");352write("<table id='b30' width='42' height='16' bgcolor='#FF3F00' style='position:absolute; top:108; left:305'><td></td></table>");353write("<table id='b31' width='42' height='16' bgcolor='#FF3F00' style='position:absolute; top:108; left:351'><td></td></table>");354 355write("<table id='b32' width='42' height='16' bgcolor='#FF0000' style='position:absolute; top:128; left:29'><td></td></table>");356write("<table id='b33' width='42' height='16' bgcolor='#FF0000' style='position:absolute; top:128; left:75'><td></td></table>");357write("<table id='b34' width='42' height='16' bgcolor='#FF0000' style='position:absolute; top:128; left:121'><td></td></table>");358write("<table id='b35' width='42' height='16' bgcolor='#FF0000' style='position:absolute; top:128; left:167'><td></td></table>");359write("<table id='b36' width='42' height='16' bgcolor='#FF0000' style='position:absolute; top:128; left:213'><td></td></table>");360write("<table id='b37' width='42' height='16' bgcolor='#FF0000' style='position:absolute; top:128; left:259'><td></td></table>");361write("<table id='b38' width='42' height='16' bgcolor='#FF0000' style='position:absolute; top:128; left:305'><td></td></table>");362write("<table id='b39' width='42' height='16' bgcolor='#FF0000' style='position:absolute; top:128; left:351'><td></td></table>");363 364write("<div id='ball' style='position:absolute'>");365write("<table width='4' height='8' bgcolor='#B0B0B0' style='position:absolute; left:0; top:0'><td></td></table>");366write("<table width='8' height='4' bgcolor='#B0B0B0' style='position:absolute; left:-1; top:2'><td></td></table>");367write("<table width='4' height='4' bgcolor='#FFFFFF' style='position:absolute; left:0; top:1'><td></td></table>");368write("</div>");369write("<table id='racket' width='40' height='4' bgcolor='#B0B0FF' style='position:absolute'><td></td></table>");370write("<div id='starter' style='position:absolute'><form><input type='button' value='START' ONCLICK='initG();blur()'></form></div>");371write("<div id='clrmes' style='position:absolute'><font style='font-size:24px' color='#44CC44'>ALL CLEAR!</font></div>");372write("<div id='ovrmes' style='position:absolute'><font style='font-size:24px' color='#CC4444'>GAME OVER!</font></div>");373write("<div id='DN' style='position:absolute'><a href='javascript:SDN()'>SPEED DOWN</a></div>");374 }375 </script>376 377 </html>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。