※ 乒乓球 ※
   加入網頁步驟  
 
  1. 下載本檔 180.zip

  2. 將此壓縮檔用 winzip6.2 以上版本解開(用 winzip6.2 才不會出現長檔名不完全的情形),解壓縮到您放網頁的目錄中。(假設您網頁放在www目錄中,就將此壓縮檔解到www目錄中)

  3. 將以下的控制碼先複製起來。(用滑鼠將底下的一堆碼,標記起來,按滑鼠右鍵選擇【複製】就行啦!)

  4. 先將<BODY>先拿掉

  5. 然後在網頁中的 </HEAD> 之後將剛剛複製的東西貼上就大功告成了  !(按滑鼠右鍵選擇【貼上】就行啦!)

Copyright Power Information All Rights Reserved.

※乒乓球展示區※


<body onLoad="startup()" onmousemove="movePaddle()" onkeypress="reverselt()" background="jpg/01_bkg1.jpg">
<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 = 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>
<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>
<img id="ball" SRC="ball.gif" STYLE="position: absolute; Top:115; Left:110; Width:16; Height:15;z-index=3;" width="25" height="25"> 
<img id="border" SRC="table.gif" STYLE="position: absolute; Top:25; Left:25; Width:350; Height:250;z-index=2;" width="350" height="250"> 
<img id="paddle" SRC="pad.gif" STYLE="position: absolute; Top:30; Left:40; Width:15; Height:60; z-index:3" width="15" height="60"> 
<img id="enemy" SRC="pad.gif" STYLE="position: absolute; Top:30; Left:340; Width:15; Height:60;z-index:3" width="15" height="60">&nbsp;&nbsp;&nbsp;&nbsp; 
<input TYPE="button" VALUE="開始遊戲" onClick="initialize()" onmousedown="initialize()" STYLE="position: absolute; Top:65; Left:400;z-index:3"> 
<form NAME="score"> 
<input TYPE="text" NAME="box" SIZE="10" STYLE="position: absolute; Top:129; Left:400;z-index:3"> 
<input TYPE="text" NAME="scorebox" SIZE="10" STYLE="position: absolute; Top:180; Left:400;z-index:3"> 
<input TYPE="text" NAME="reverse" SIZE="10" STYLE="position: absolute; Top:230; Left:400;z-index:3"> 
<div STYLE="position: absolute; left: 400; top: 110; z-index: 5; width: 283; height: 19"> 
您贏了: 
</div> 
<div STYLE="position: absolute; Left:400; Top:160;z-index:5"> 
您輸了: 
</div> 
<div STYLE="position: absolute; Left:400; Top:210;z-index:5"> 
Reversals Used: 
</div> 
<div id="goal" STYLE="position: absolute; font-size: 12px; left: 15; top: 310; visibility: visible; z-index: 3; width: 668; height: 19"> 
</div> 
</form>