Admin المدير
عدد المساهمات : 207 تاريخ التسجيل : 03/09/2008 الموقع : https://yorsha.yoo7.com
| موضوع: كود لعبة ( بينج بونج ) الثلاثاء يناير 20, 2009 5:50 pm | |
| - الكود:
-
[table cellSpacing=1 cellPadding=3 width="90%" align=center border=0][tr][td class=quote]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <!-- saved from url=(0056)http://www.dynamicdrive.com/dynamicindex12/pong/pong.htm --> <HTML><HEAD> <META http-equiv=Content-Type content="text/html; charset=windows-1256"> <SCRIPT> //Script Created by Michael Sigle //Use on your own site with images as long as you keep this script intact //Featured on Dynamicdrive.com //For full source code, visit Dynamicdrive.com
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 = 215 var place = pore - 1; if (point < 7) { if ((yp >= 15) && (yp <= 215)) paddle.style.posTop = yp - 6; else paddle.style.posTop = place } if (point >= 7) { if ((yp >= 15) && (yp <= 215)) paddle.style.posTop = yp + 13; else paddle.style.posTop = place } if ((yp < 27) || (yp > 258)) dy = dy * -1 if (point >= 15) paddle.style.posTop = sig if (xp >= 358){ escor = escor + .5 score.scorebox.value = " " +escor+ " " gameLose() return } if (xp <= 27) { pscor = pscor + .5 score.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 += dy ball.style.posLeft += dx
window.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) } else return } 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) } else return } function reverseIt() { if (reversal <= 9) { if (window.event.keyCode == 118){ dy = dy * -1 reversal = reversal + 1 score.reverse.value = reversal } if (window.event.keyCode == 104){ dx = dx * -1 reversal = reversal + 1 score.reverse.value = reversal } } } </SCRIPT> <META content="MSHTML 6.00.2900.2180" name=GENERATOR></HEAD> <BODY onmousemove=movePaddle() onkeypress=reverseIt() onload=startUp()><IMG id=ball style="Z-INDEX: 3; LEFT: 110px; WIDTH: 16px; POSITION: absolute; TOP: 115px; HEIGHT: 15px" src="pong_files/ball.gif"> <IMG id=border style="Z-INDEX: 2; LEFT: 25px; WIDTH: 350px; POSITION: absolute; TOP: 25px; HEIGHT: 250px" src="pong_files/table.gif"> <IMG id=paddle style="Z-INDEX: 3; LEFT: 40px; WIDTH: 15px; POSITION: absolute; TOP: 30px; HEIGHT: 60px" src="pong_files/pad.gif"> <IMG id=enemy style="Z-INDEX: 3; LEFT: 340px; WIDTH: 15px; POSITION: absolute; TOP: 30px; HEIGHT: 60px" src="pong_files/pad.gif"> <IMG id=bord style="Z-INDEX: 3; LEFT: 20px; WIDTH: 5px; POSITION: absolute; TOP: 25px; HEIGHT: 250px" src="pong_files/border1.gif"> <IMG id=borde style="Z-INDEX: 3; LEFT: 375px; WIDTH: 5px; POSITION: absolute; TOP: 25px; HEIGHT: 250px" src="pong_files/border1.gif"> <IMG id=bordit style="Z-INDEX: 3; LEFT: 25px; WIDTH: 350px; POSITION: absolute; TOP: 20px; HEIGHT: 5px" src="pong_files/border3.gif"> <IMG id=bordit style="Z-INDEX: 3; LEFT: 25px; WIDTH: 350px; POSITION: absolute; TOP: 275px; HEIGHT: 5px" src="pong_files/border3.gif"> <INPUT onmousedown=initialize() style="Z-INDEX: 3; LEFT: 400px; POSITION: absolute; TOP: 15px" onclick=initialize() type=button value=Serve> <FORM name=score><INPUT style="Z-INDEX: 3; LEFT: 400px; POSITION: absolute; TOP: 69px" size=10 name=box> <INPUT style="Z-INDEX: 3; LEFT: 400px; POSITION: absolute; TOP: 120px" size=10 name=scorebox> <INPUT style="Z-INDEX: 3; LEFT: 400px; POSITION: absolute; TOP: 190px" size=10 name=reverse> <DIV style="Z-INDEX: 5; LEFT: 400px; POSITION: absolute; TOP: 50px">Your Score:</DIV> <DIV style="Z-INDEX: 5; LEFT: 400px; POSITION: absolute; TOP: 100px">Opponent Score:</DIV> <DIV style="Z-INDEX: 5; LEFT: 400px; POSITION: absolute; TOP: 170px">Reversals Used:</DIV> <DIV id=win style="FONT-SIZE: 50px; Z-INDEX: 3; LEFT: 15px; VISIBILITY: hidden; POSITION: absolute; TOP: 290px">You Win!!!!</DIV> <DIV id=lose style="FONT-SIZE: 50px; Z-INDEX: 3; LEFT: 15px; VISIBILITY: hidden; POSITION: absolute; TOP: 290px">You Lose!!!!</DIV> <DIV id=goal style="FONT-SIZE: 12px; Z-INDEX: 3; LEFT: 15px; VISIBILITY: visible; POSITION: absolute; TOP: 290px">Move the mouse up and down to move your paddle(the one on the right). Click on "serve" to begin every time a point is scored (make sure you press down and let up the mouse button on the serve button). You have ten reversals, also. Press the H key at any time to reverse the horizontal movement, or press V to change the vertical movement. Game is to 15. Good Luck!! <P align=center><A href="<A href='http://dynamicdrive.com/">http://dynamicdrive.com/"><IMG</A> alt="Dynamic Drive" src="c" border=0><BR>Featured on</A></P></DIV></FORM></BODY></HTML>[/td][/tr][/table] | |
|