...

View Full Version : JavaScript Game - Onclick Not Working...



stophon4
06-29-2004, 01:44 PM
Hey, I am having a problem with a javascript game (http://stophon4.com/shoot/game.htm) I made. It works great except for the fact that sometimes when you shoot a target it doesn't always turn into a check mark. What am I doing wrong?

Stophon4 - Stophon4.com (http://stophon4.com)

SpiritualStorms
06-29-2004, 02:51 PM
I tried clicking the links you gave above, and they dont work.

SpiritualStorms
06-29-2004, 04:01 PM
Actually, i turns into a mark. You just have to like hit the middle of the target. i got all 4. Not a bad game.

stophon4
06-29-2004, 09:41 PM
Well sometimes it doesn't, and sometimes it does, but it always does if you hit it in the center, weird...

SpiritualStorms
06-30-2004, 08:37 AM
Well, if you deconstruct the code for us, someone might be able to help you.

stophon4
06-30-2004, 01:57 PM
OK, here's the code for level three, it usually only happens on this level :(


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Shooting Game - Level 2 - Stophon4.com</TITLE>
<Style type='text/css'>
BODY {
overflow: hidden;
cursor: url("test.ani");
background-color: blue;
}
</STYLE>
<SCRIPT type='text/javascript'>
var xpos = 50;
var ypos = 50;
var hits = 0;

function walk(){
xpos++;
xpos++;
xpos++;
target.style.left = xpos;
target2.style.left = xpos;
target3.style.left = xpos;
target4.style.left = xpos;
if(xpos >= 1500){
end();
}else{
window.setTimeout("walk();",1);
}
}
function hit(){
hits++;
if(hits == 4){
window.setTimeout("end();",1000);
}
}
function end(){
if(hits == 0){
alert("Your percentage is 0% !");
alert("That Stinks!!");
}else if(hits == 1){
alert("Your percentage is 25% !");
alert("Come On! You can do better than that!");
}else if(hits == 2){
alert("Your percentage is 50% !");
alert("Your half as good as you should be!");
}else if(hits == 3){
alert("Your percentage is 75% !");
alert("3/4, That's not good enough!");
}else if(hits == 4){
alert("Your percentage is 100% !");
alert("You got a perfect score! Congratulations!");
alert("Here we go on level three!");
}
if(hits == 4){
document.location = "game3.htm";
}else{
var contin = confirm("Play Again?");
if(contin){
document.location.reload();
}else if(!contin){
document.location = "http://www.stophon4.com";
}
}
}
</SCRIPT>
</HEAD>
<BODY OnLoad="walk()">
<img src='targets.gif' id='target' Style='top:5%;;left:100;position:absolute;visibility:visible;' Onclick='hit();this.src = "done.gif";'>
<img src='targets.gif' id='target2' Style='top:25%;;left:100;position:absolute;visibility:visible;' Onclick='hit();this.src = "done.gif";'>
<img src='targets.gif' id='target3' Style='top:45%;;left:100;position:absolute;visibility:visible;' Onclick='hit();this.src = "done.gif";'>
<img src='targets.gif' id='target4' Style='top:65%;;left:100;position:absolute;visibility:visible;' Onclick='hit();this.src = "done.gif";'>
</BODY>
</HTML>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum