...

View Full Version : adventure game



stalepie
01-20-2009, 06:25 AM
Hi, I'm just beginning JavaScript and wish to make a simple adventure game. The game won't require any typing or keyboard input, but rather the player selects from a list of choices and clicks on them, either clicking on a button or a link -- preferably a link, and this updates the text on screen. Example:

You are standing on a large rock overlooking a huge mountain range in northern Georgia. The ground below, in front of you, is 500 feet down.

1) Jump
2) Reconsider your "plans"
3) sit down and meditate

and if you select 2) it'll say:

"Good grief, what were you thinking, considering jumping off that rock! Of course you don't want to do that... but now what do you want to do?"

and then you get another selection of choices. Similar to the game Snatcher, if anyone here's ever played that. I just wanted to make a little game like this in JavaScript, and besides mousedown (I think?) I'm having trouble understanding what commands I may need.

Oh, I'll also need to save items, but I figure I can do that with if/else and variables... by saving items I mean, you get a key and when you are standing in front of a locked door, it gives you the option to use the key, when when you don't have the key, and you're standing in front of the same door, it doesn't show you that option.

thanks if anyone doesn't mind giving me a few pointers.

-matthew

itsallkizza
01-20-2009, 07:04 AM
You should be able to get the basic commands/concepts from this:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Example</title>
<style type="text/css">
.act_btn
{
width: 160px;
}
</style>
<script type="text/javascript">
// <![CDATA[

function take_action(act)
{
var msg;
switch (act)
{
case "jump" :
msg = "Good grief, what were you thinking, considering jumping off that rock! Of course you don\'t want to do that... but now what do you want to do?";
break;
case "reconsider" :
msg = "That might be a good idea...";
break;
case "meditate" :
msg = "You don\'t have nearly enough time for that!";
break;
}
alert(msg);
}

// ]]>
</script>
</head>
<body>

<h3>You are standing on a large rock overlooking a huge mountain range in northern Georgia. The ground below, in front of you, is 500 feet down.</h3>
<input class="act_btn" type="button" value="jump" onclick="take_action('jump')" /><br />
<input class="act_btn" type="button" value="reconsider your plans" onclick="take_action('reconsider')" /><br />
<input class="act_btn" type="button" value="sit down and meditate" onclick="take_action('meditate')" /><br />

</body>
</html>


The whole game-flow aspect is a bit more lofty of an idea though. I would suggest you spend a few weeks getting to know Javascript inside and out before attempting to make a full on text-adventure game.

stalepie
01-20-2009, 02:00 PM
Thanks! This is simple enough for me to understand, but what if I wanted to update the text on that page instead of showing it in alert messages? Like this: http://geocities.com/stalepie/game1.htm. The first one, "jump," takes you to a different page. The effect is right, but I didn't want to do my game like this, on many different pages. (The reason I'm not just doing it in HTML is because it needs to have item management).

By the way, this guy has a good Adventure game prototype in JavaScript, if anyone is interested:
http://www.madore.org/~david/sitemap.html
http://www.madore.org/~david/misc/adventure.html

That's much more complicated than what I'm doing however. It's more like Zork.

jmrker
01-20-2009, 02:24 PM
'itsallkizza's code should be easy enough to modify to write an 'document.getElementById('ScreenMessage').innerHTML=msg'
to some <DIV id="ScreenMessage"> or <SPAN id="ScreenMessage"> area on the screen to replace the alerts.

I have a confusion point on this statement:

The first one, "jump," takes you to a different page. The effect is right, but I didn't want to do my game like this, on many different pages. (The reason I'm not just doing it in HTML is because it needs to have item management).
How do you expect to 'jump' to a different page when you don't want to do it "on many different pages" in HTML? :eek:
Seem like "What we have here is a failure to communicate." (Strother Martin to Paul Newman in "Cool Hand Luke") :)

stalepie
01-20-2009, 02:38 PM
Oh, I do want to keep it all on one page. I meant that, if I weren't having to deal with items in the game, like keys, objects you pick up and use, etc., then I would just write everything in HTML, either doing multiple pages, or a maze of html anchors (jumping you up and down a single page).

itsallkizza
01-20-2009, 02:49 PM
You need to
a) spend a good deal of time getting to know html and javascript
b) framework your site on paper before getting down and dirty with the code

Knowing as little as you do about Javascript/html you're going to have all sorts of issues just diving in like this, and I foresee many more posts here on the forums asking us to make the game for you step by step. There are tons of JS resources/tutorials online (the best of which can be found in links here on this site).

I wish you luck in your game creation :)

stalepie
01-20-2009, 03:16 PM
<chooses jump>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum