PDA

View Full Version : Shooting Game


101
10-12-2002, 06:53 PM
I made this shooting game but i wish it to have the target moving about in a box (mabey a table of something) becuase other wise it moves about everywhere...like all over the text and then you keep highlighting the text when you try and hit it and so on...

Here is the code:

<html>
<head>
<title>
</title>

<style>
#b {position: absolute; cursor: hand}
</style>

<Script Language=JavaScript>

level = 750;

function Init() {
var xs = screen.availWidth/2;
var ys = screen.availHeight/2;
var x = Math.round(Math.random()*xs);
var y = Math.round(Math.random()*ys);
b.style.pixelLeft = x;
b.style.pixelTop = y;
timer = setTimeout("Init()",level);
}
var count = 0;
var right = 0;
function Right() {
alert("Nice Shot!");
right++;
}

function Count() { count++ }

function Score() {
count--;
pc = Math.round(eval(right*100 / count));
if (isNaN(pc)) { pc = 0 }
alert("Score\n\nShoots : "+ count+"\nHits : " + right +"\nPercentage(%) : "+pc+"");
}

</script>

</head>

<body onmousedown=Count() onload=Init()>

<center>
<b>Shoot The Target</b>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<select name=slc onchange="level=this.value">
<option value=2400 selected>Easy
<option value=1300>Medium
<option value=500>Hard
</select>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<b style="cursor:hand" onclick=Score()>Score</b>
</center>

<br>
<br>

<TABLE border=2 width=980 height=500>

<img src=Shoot.bmp id=b onmousedown=Right()>

</TABLE>

</body>
</html>

chrismiceli
10-12-2002, 07:15 PM
are there supposed to be pictures because I am clicking an x where a pic should be and there is no backroung, but other than that it is pretty cool for a short amount of code.

101
10-12-2002, 07:20 PM
Yea there are pictures but i did not add them becuase i havenot finished them yet but the x still works but like can you help me with the code.