anderson.fvgn
07-24-2009, 05:00 PM
I am having problems with some code I am trying to write. Let me explain what I am trying to do and then I will post the code.
I am trying to make a point and click javascript game. Basically what I want is to have one image displayed on screen at the start (room1.jpg). When you click on a door on that image, I have an onclick event to change the image to a new one that shows the door open (room1_a.jpg). What I want is that when you click the now open door, to display the next room in the game. The only solution I can think of is some sort of nested onclick event using several image maps, but I am fairly new to Javascript and I am not sure if that is possible. What it all comes down to is I want to display each incarnation of each room in the game in the same window without having to reload a new window for each room. I hope that makes sense, if not I can try and clarify. Below is the code I have so far. And as you can see all that does is display the open door when you click on the image. I have not done any of the image mapping yet.
Thank you in advance for any help anyone can provide.
<html>
<head>
<style type="text/css">
p {text-align:center}
</style>
<script type="text/javascript">
function room1()
{
document.getElementById("room1").src="room1_a.jpg";
alert("The door opens with a loud squeak."+'\n'+"You can feel a draft coming from the now open door.");
}
</script>
</head>
<body>
<p><img src="left.jpg" alt="Rules" /><img src="room1.jpg" alt="Entryway" id="room1" onClick="room1()";/><img src="bottom.jpg" alt="Messages" /></p>
</body>
</html>
I am trying to make a point and click javascript game. Basically what I want is to have one image displayed on screen at the start (room1.jpg). When you click on a door on that image, I have an onclick event to change the image to a new one that shows the door open (room1_a.jpg). What I want is that when you click the now open door, to display the next room in the game. The only solution I can think of is some sort of nested onclick event using several image maps, but I am fairly new to Javascript and I am not sure if that is possible. What it all comes down to is I want to display each incarnation of each room in the game in the same window without having to reload a new window for each room. I hope that makes sense, if not I can try and clarify. Below is the code I have so far. And as you can see all that does is display the open door when you click on the image. I have not done any of the image mapping yet.
Thank you in advance for any help anyone can provide.
<html>
<head>
<style type="text/css">
p {text-align:center}
</style>
<script type="text/javascript">
function room1()
{
document.getElementById("room1").src="room1_a.jpg";
alert("The door opens with a loud squeak."+'\n'+"You can feel a draft coming from the now open door.");
}
</script>
</head>
<body>
<p><img src="left.jpg" alt="Rules" /><img src="room1.jpg" alt="Entryway" id="room1" onClick="room1()";/><img src="bottom.jpg" alt="Messages" /></p>
</body>
</html>