📄 ch19-265.txt
字号:
<HTML>
<HEAD>
<TITLE>游戏篇--一款流行游戏</TITLE>
</HEAD>
<BODY bgcolor="#fef4d2" onload=PopUpBall()>
<center>
<font color="ffaafa"><h2>游戏篇--一款流行游戏</h2></font>
<hr width=300>
<br>
<!-- 案例代码1开始 -->
<script language=JavaScript>
var index = null;
var balltime = 0;
var ballcol = 0;
<!-- [Step1]: 这里可以更改弹球的次数 -->
var ballnum = 10;
var ballsta = new Array(40);
var planecol = new Array(5);
planecol[0] = "#FFFF00";
planecol[1] = "#FFCF00";
planecol[2] = "#FF7F00";
planecol[3] = "#FF3F00";
planecol[4] = "#FF0000";
planecol[5] = "#000000";
function PopUpBall() {
bgIE.style.posTop = 116;
bgIE.style.posLeft = 116;
ball.style.posTop = 290;
ball.style.posLeft = 209;
ballracket.style.posTop = 300;
ballracket.style.posLeft = 195;
ballbutton.style.posTop = -1000;
ballbutton.style.posLeft = -1000;
endgame.style.posTop = -1000;
endgame.style.posLeft = -1000;
for (ib = 0; ib < 5; ib++) {
for (ia = 0; ia < 8; ia++) { ballsta[ib * 8 + ia] = ib; } }
ballbutton.style.posTop = 300;
ballbutton.style.posLeft = 280;
}
function BallMain() {
clearTimeout(index);
balltime = balltime + 1;
with (Math){ tmpballtime = floor(balltime / 10)};
ballX = ballX + ballDX;
ballY = ballY + ballDY;
ErrorCheck();
PlaneCheck();
ball.style.posTop = ballY;
ball.style.posLeft = ballX;
if (gameFLG == 01){index = setTimeout("BallMain()", 0); }
}
function ErrorCheck() {
if (ballX < 16){ ballX = 32 - ballX; ballDX = -ballDX; }
if (ballX > 401){ ballX = 802 - ballX; ballDX = -ballDX; }
if (ballY < 16){ ballY = 32 - ballY; ballDY = -ballDY; }
if (ballY >= 272) {
if (missFLG == 0) { tmpX = (ballDX / ballDY) * (272 - ballY) + ballX;
if (tmpX >= tmpRL - 12) {
if (tmpX <= tmpRL + 42) {
ballY = 272; ballDY = -ballDY;
ballX = tmpX;
ballRD = tmpX - tmpRL;
with (Math){ ballDX = 8 * abs(ballDX) / ballDX; }
if (ballRD < -4){ ballDX = -15; }
if (ballRD > 36){ ballDX = 15; }
if (ballRD >= 14){ if (ballRD <= 16) { ballDX = -2; } }
if (ballRD >= 17){ if (ballRD <= 20) { ballDX = 2; } }
if (ballRD >= 0){ if (ballRD <= 4) { ballDX = -4; } }
if (ballRD >= 28){ if (ballRD <= 32) { ballDX = 4; } }
if (ballRD >= -4){ if (ballRD <= -1) { ballDX = -11; } }
if (ballRD >= 33){ if (ballRD <= 36) { ballDX = 11; } } } }
if (ballDY > 0){ missFLG = 1; }}
else { if (ballY > 290){ missFLG = 0; ballnum = ballnum - 1; EndBall(); } } }
}
function PlaneCheck() {
tmpY = ballY + 4;
tmpX = ballX + 4;
if (tmpY >= 48) {
if (tmpY <= 147) {
if (tmpX >= 29) {
if (tmpX <= 396) {
with (Math) {
ia = floor((tmpX - 29) / 46);
ib = floor((tmpY - 48) / 20);
ic = ib * 8 + ia; }
if (ballsta[ic] <= 4) {
tmpbc = ballsta[ic] + 1;
ballsta[ic] = tmpbc;
chc(ic + 1, tmpbc);
if (tmpbc == 5){ ballcol = ballcol + 1; }
if (ballcol >= 40){ EndBall(); }
if (ballDX > 0) {
iy=(ballDY / ballDX) * (29 + 46 * ia - tmpX) + tmpY;
if (iy > 48 + 20 * ib + 18) {
tmpY1 = 48 + 20 * ib + 18;
tmpX1 = (ballDX / ballDY) * (48 + 20 * ib + 18 - tmpY) + tmpX;
ballX = tmpX1 - 4;
ballY = tmpY1 - 4;
ballDY = -ballDY; }
else {
if (iy < 44 + 20 * ib) {
tmpY1 = 48 + 20 * ib;
tmpX1 = (ballDX / ballDY) * (48 + 20 * ib - tmpY) + tmpX;
ballX = tmpX1 - 4;
ballY = tmpY1 - 4;
ballDY = -ballDY; }
else {
tmpX1 = 29 + 46 * ia;
tmpY1 = (ballDY / ballDX) * (29 + 46 * ia - tmpX) + tmpY;
ballX = tmpX1 - 4;
ballY = tmpY1 - 4;
ballDX = -ballDX; } } }
else {
iy = (ballDY / ballDX) * (29+46 * ia + 44 - tmpX) + tmpY;
if (iy > 48 + 20 * ib + 18) {
tmpY1 = 48 + 20 * ib + 18;
tmpX1 = (ballDX / ballDY) * (48 + 20 * ib + 18 - tmpY) + tmpX;
ballX = tmpX1 - 4;
ballY = tmpY1 - 4;
ballDY = -ballDY; }
else {
if (iy < 44 + 20 * ib) {
tmpY1 = 48 + 20 * ib;
tmpX1 = (ballDX / ballDY) * (48 + 20 * ib - tmpY) + tmpX;
ballX = tmpX1 - 4;
ballY = tmpY1 - 4;
ballDY = -ballDY; }
else {
tmpX1 = 29+46 * ia + 44;
tmpY1 = (ballDY / ballDX) * (29 + 46 * ia + 44 - tmpX) + tmpY;
ballX = tmpX1 - 4;
ballY = tmpY1 - 4;
ballDX = -ballDX; } } } } } } } }
}
function initAll() {
if (ballcol >= 40) {
ballcol = 0;
balltime = 0;
ballnum = 3;
with (Math) { tmpballtime = floor(balltime / 10); }
for (ib = 0; ib < 5; ib++){
for (ia = 0; ia < 8; ia++){
chc(ib * 8 + ia +1, ib);
ballsta[ib * 8 + ia] = ib; } } }
gameFLG = 1;
ballX = 209;
ballY = 270;
ballDX =- 8;
ballDY =- 8;
tmpRL = 193;
missFLG = 0;
index = setTimeout("BallMain()", 0);
}
function chc(bno,bcl) {
eval(((bno <= 10) ? "b0" : "b") + (bno-1)).bgColor = planecol[bcl];
}
function EndBall() {
gameFLG = 0;
loadFLG = 0;
ballbutton.style.posTop = 300;
ballbutton.style.posLeft = 280;
if (ballnum <= 0) {
endgame.style.posTop = 250;
endgame.style.posLeft = 260;
ballcol = 40; }
}
</script>
<!-- 案例代码1结束 -->
<!-- 案例代码2开始 -->
<script language=JavaScript>
with (document) {
write("<table id='bgIE' width='394' height='240' bgcolor='#33CC99' ><td></td></table>");
write("<table id='b00' width='40' height='16' bgcolor='#FFFF00' style='position:absolute; top:115; left:100'><td></td></table>");
write("<table id='b01' width='40' height='16' bgcolor='#FFFF00' style='position:absolute; top:115; left:145'><td></td></table>");
write("<table id='b02' width='40' height='16' bgcolor='#FFFF00' style='position:absolute; top:115; left:190'><td></td></table>");
write("<table id='b03' width='40' height='16' bgcolor='#FFFF00' style='position:absolute; top:115; left:235'><td></td></table>");
write("<table id='b04' width='40' height='16' bgcolor='#FFFF00' style='position:absolute; top:115; left:280'><td></td></table>");
write("<table id='b05' width='40' height='16' bgcolor='#FFFF00' style='position:absolute; top:115; left:325'><td></td></table>");
write("<table id='b06' width='40' height='16' bgcolor='#FFFF00' style='position:absolute; top:115; left:370'><td></td></table>");
write("<table id='b07' width='40' height='16' bgcolor='#FFFF00' style='position:absolute; top:115; left:415'><td></td></table>");
write("<table id='b08' width='40' height='16' bgcolor='#FFCF00' style='position:absolute; top:135; left:100'><td></td></table>");
write("<table id='b09' width='40' height='16' bgcolor='#FFCF00' style='position:absolute; top:135; left:145'><td></td></table>");
write("<table id='b10' width='40' height='16' bgcolor='#FFCF00' style='position:absolute; top:135; left:190'><td></td></table>");
write("<table id='b11' width='40' height='16' bgcolor='#FFCF00' style='position:absolute; top:135; left:235'><td></td></table>");
write("<table id='b12' width='40' height='16' bgcolor='#FFCF00' style='position:absolute; top:135; left:280'><td></td></table>");
write("<table id='b13' width='40' height='16' bgcolor='#FFCF00' style='position:absolute; top:135; left:325'><td></td></table>");
write("<table id='b14' width='40' height='16' bgcolor='#FFCF00' style='position:absolute; top:135; left:370'><td></td></table>");
write("<table id='b15' width='40' height='16' bgcolor='#FFCF00' style='position:absolute; top:135; left:415'><td></td></table>");
write("<table id='b16' width='40' height='16' bgcolor='#FF7F00' style='position:absolute; top:155; left:100'><td></td></table>");
write("<table id='b17' width='40' height='16' bgcolor='#FF7F00' style='position:absolute; top:155; left:145'><td></td></table>");
write("<table id='b18' width='40' height='16' bgcolor='#FF7F00' style='position:absolute; top:155; left:190'><td></td></table>");
write("<table id='b19' width='40' height='16' bgcolor='#FF7F00' style='position:absolute; top:155; left:235'><td></td></table>");
write("<table id='b20' width='40' height='16' bgcolor='#FF7F00' style='position:absolute; top:155; left:280'><td></td></table>");
write("<table id='b21' width='40' height='16' bgcolor='#FF7F00' style='position:absolute; top:155; left:325'><td></td></table>");
write("<table id='b22' width='40' height='16' bgcolor='#FF7F00' style='position:absolute; top:155; left:370'><td></td></table>");
write("<table id='b23' width='40' height='16' bgcolor='#FF7F00' style='position:absolute; top:155; left:415'><td></td></table>");
write("<table id='b24' width='40' height='16' bgcolor='#FF3F00' style='position:absolute; top:175; left:100'><td></td></table>");
write("<table id='b25' width='40' height='16' bgcolor='#FF3F00' style='position:absolute; top:175; left:145'><td></td></table>");
write("<table id='b26' width='40' height='16' bgcolor='#FF3F00' style='position:absolute; top:175; left:190'><td></td></table>");
write("<table id='b27' width='40' height='16' bgcolor='#FF3F00' style='position:absolute; top:175; left:235'><td></td></table>");
write("<table id='b28' width='40' height='16' bgcolor='#FF3F00' style='position:absolute; top:175; left:280'><td></td></table>");
write("<table id='b29' width='40' height='16' bgcolor='#FF3F00' style='position:absolute; top:175; left:325'><td></td></table>");
write("<table id='b30' width='40' height='16' bgcolor='#FF3F00' style='position:absolute; top:175; left:370'><td></td></table>");
write("<table id='b31' width='40' height='16' bgcolor='#FF3F00' style='position:absolute; top:175; left:415'><td></td></table>");
write("<table id='b32' width='40' height='16' bgcolor='#FF0000' style='position:absolute; top:195; left:100'><td></td></table>");
write("<table id='b33' width='40' height='16' bgcolor='#FF0000' style='position:absolute; top:195; left:145'><td></td></table>");
write("<table id='b34' width='40' height='16' bgcolor='#FF0000' style='position:absolute; top:195; left:190'><td></td></table>");
write("<table id='b35' width='40' height='16' bgcolor='#FF0000' style='position:absolute; top:195; left:235'><td></td></table>");
write("<table id='b36' width='40' height='16' bgcolor='#FF0000' style='position:absolute; top:195; left:280'><td></td></table>");
write("<table id='b37' width='40' height='16' bgcolor='#FF0000' style='position:absolute; top:195; left:325'><td></td></table>");
write("<table id='b38' width='40' height='16' bgcolor='#FF0000' style='position:absolute; top:195; left:370'><td></td></table>");
write("<table id='b39' width='40' height='16' bgcolor='#FF0000' style='position:absolute; top:195; left:415'><td></td></table>");
write("<div id='ball' style='position:absolute;'>");
write("<table width='4' height='8' bgcolor='#B0B0B0' style='position:absolute; left:0; top:0'><td></td></table>");
write("<table width='8' height='4' bgcolor='#B0B0B0' style='position:absolute; left:-1; top:2'><td></td></table>");
write("<table width='4' height='4' bgcolor='#FFFFFF' style='position:absolute; left:0; top:1'><td></td></table>");
write("</div>");
write("<table id='ballracket' width='40' height='4' bgcolor='#B0B0FF' style='position:absolute;'><td></td></table>");
write("<div id='ballbutton' style='position:absolute;'><form><input type='button' value='弹 球' onclick='initAll()'></form></div>");
write("<div id='endgame' style='position:absolute;'><font style='font-size:24px' color='#CC4444'>弹球结束</font></div>");
}
</script>
<!-- 案例代码2结束 -->
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -