Phiên bản đầy đủ: jsB@nk » Trò chơi » Kĩ năng » Ping pong
URL: https://www.javascriptbank.com/ping-pong-index.html
Trò chơi ping pong sử dụng hình ảnh.
Phiên bản đầy đủ: jsB@nk » Trò chơi » Kĩ năng » Ping pong
URL: https://www.javascriptbank.com/ping-pong-index.html
<SCRIPT>window.onerror=new Function("return true")var dx;var dy;var scor = 0;var dod;var pscor = 0;var escor = 0;var point;var los;var reversal = 0;function startUp(){score.scorebox.value = " "score.box.value= " "score.reverse.value = " "}function initialize(){dx = 2;dy = 2;los = Math.round(21 * Math.random()) + 1;point = 0;hefr = Math.round(200 * Math.random()) + 35;vred = Math.round(100 * Math.random()) + 100;ball.style.posTop = hefr;ball.style.posLeft = vred;moveBall()}function moveBall(){var xp = ball.style.posLeft;var yp = ball.style.posTop;var sig = paddle.style.posTop;var gis = paddle.style.posLeft;var hit = document.elementFromPoint(xp,yp);var pore = 215var place = pore - 1; if (point < 7){if ((yp >= 15) && (yp <= 215))paddle.style.posTop = yp - 6;elsepaddle.style.posTop = place}if (point >= 7){if ((yp >= 15) && (yp <= 215))paddle.style.posTop = yp + 13;elsepaddle.style.posTop = place}if ((yp < 27) || (yp > 258))dy = dy * -1if (point >= 15)paddle.style.posTop = sigif (xp >= 358){escor = escor + .5score.scorebox.value = " " +escor+ " "gameLose()return}if (xp <= 27){pscor = pscor + .5score.box.value = " " +pscor+ " "gameWin()return}if (hit != null){if (hit.id == "paddle"){dx = dx * -1;point = point + 1}else if (hit.id == "enemy") {dx = dx * -1;}}ball.style.posTop += dyball.style.posLeft += dxwindow.setTimeout("moveBall()", 1, "JavaScript");}function movePaddle(){var ypos = window.event.y;if ((ypos >= 15) && (ypos <= 230))enemy.style.posTop = ypos;}function gameLose(){if (escor >= 15){goal.style.visibility = "hidden"lose.style.visibility = "visible"alert("Sorry, please try again. You lost by the score of " +escor+ " to " +pscor+ ".")history.go(-1)}elsereturn}function gameWin(){if (pscor >= 15){goal.style.visibility = "hidden"win.style.visibility = "visible"alert("Congrats, you won!!!. You won by the score of " +pscor+ " to " +escor+ ".")history.go(-1)}elsereturn}function reverseIt(){if (reversal <= 9){if (window.event.keyCode == 118){dy = dy * -1reversal = reversal + 1score.reverse.value = reversal}if (window.event.keyCode == 104){dx = dx * -1reversal = reversal + 1score.reverse.value = reversal}}}</SCRIPT><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->
<BODY onLoad="startUp()" onmousemove="movePaddle()" onKeypress="reverseIt()"><IMG id="ball" SRC="ball.gif" STYLE="position: absolute; Top:115; Left:110; Width:16; Height:15;z-index=3;"><IMG id="border" SRC="table.gif" STYLE="position: absolute; Top:25; Left:25; Width:350; Height:250;z-index=2;"><IMG id="paddle" SRC="pad.gif" STYLE="position: absolute; Top:30; Left:40; Width:15; Height:60; z-index:3"><IMG id="enemy" SRC="pad.gif" STYLE="position: absolute; Top:30; Left:340; Width:15; Height:60;z-index:3"><IMG id="bord" SRC="border1.gif" STYLE="position: absolute; Top:25; Left:20; Width:5; Height:250;z-index:3"><IMG id="borde" SRC="border1.gif" STYLE="position: absolute; Top:25; Left:375; Width:5; Height:250;z-index:3"><IMG id="bordit" SRC="border3.gif" STYLE="position: absolute; Top:20; Left:25; Width:350; Height:5;z-index:3"><IMG id="bordit" SRC="border3.gif" STYLE="position: absolute; Top:275; Left:25; Width:350; Height:5;z-index:3"><INPUT TYPE="button" VALUE="Serve" onClick="initialize()" onmousedown="initialize()" STYLE="position: absolute; Top:15; Left:400;z-index:3"><FORM NAME="score"><INPUT TYPE="text" NAME="box" SIZE="10" STYLE="position: absolute; Top:69; Left:400;z-index:3"><INPUT TYPE="text" NAME="scorebox" SIZE="10" STYLE="position: absolute; Top:120; Left:400;z-index:3"><INPUT TYPE="text" NAME="reverse" SIZE="10" STYLE="position: absolute; Top:190; Left:400;z-index:3"><DIV STYLE="position: absolute; Left:400; Top:50;z-index:5">Your Score:</DIV><DIV STYLE="position: absolute; Left:400; Top:100;z-index:5">Opponent Score:</DIV><DIV STYLE="position: absolute; Left:400; Top:170;z-index:5">Reversals Used:</DIV><DIV id="win" STYLE="position: absolute; font-size: 50px; Left:15; Top:290; visibility:hidden;z-index:3">You Win!!!!</DIV><DIV id="lose" STYLE="position: absolute; font-size: 50px; Left:15; Top:290; visibility:hidden;z-index:3">You Lose!!!!</DIV><DIV id="goal" STYLE="position: absolute; font-size: 12px; width: 100%; Top:290; visibility:visible;z-index:3"></DIV></body><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->