Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: adventure game

  1. #1
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    adventure game

    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

  • #2
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    You should be able to get the basic commands/concepts from this:
    Code:
    <!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.
    Feel free to e-mail me if I forget to respond ;)
    ohsosexybrit@gmail.com

  • #3
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Last edited by stalepie; 01-20-2009 at 02:03 PM.

  • #4
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,112
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Question Consideration and question ...

    '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?
    Seem like "What we have here is a failure to communicate." (Strother Martin to Paul Newman in "Cool Hand Luke")

  • #5
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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).

  • #6
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    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
    Feel free to e-mail me if I forget to respond ;)
    ohsosexybrit@gmail.com

  • #7
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <chooses jump>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •