In this tutorial, we will show you how to start and make an simple "Choose Your Own Adventure Game" on JavaScript. NOTE: To test the game, I recommend you use: http://www.writecodeonline.com/js
To get started, make your story up, now that you have that made you can finally start with the actual game. Well, not yet... you still need your intro log-in stuff.
AGE RESTRICTION
Most games have an age-restriction, let's just say for testing purposes that your game can only be played by people 14 years old or over. To make that happen, you're gonna need to know how to use "prompt", "if", and "else". Here is the code I made up:
var myAge = prompt("What is your age?");
if(myAge>=14){
confirm("You may pass...");
}
else{
alert("You may play, but I am not responsible for your actions during or after the game, get your parents permission first");
}
So basically I am saying "Declare the variable 'myAge' to the answer you will give me to the statement 'What is your age?', then if the variable 'myAge' is greater or equal (>=) to 14, you may pass, but anything else, you have to get your parents permission first".
That's the simplest way I can put it.
Introduction for the game.
This game is a text game, no graphics, we will get to that later on in some advanced tutorials, with that in mind; we can proceed...
The introduction is just simply the name of the game and who made it, and maybe a back-story if you want it... Here is mine:
alert("Welcome to Gaillard's Kingdom!");
alert("The choose your own adventure game!");
confirm("Are you ready?");
alert("Good let's begin!");
That is just basically making popup screens one after the other, saying the stuff inside the 'alert' and 'confirm' commands (if you don't know what they are be sure to take a look at my last posts). So that is our introduction, I'm sure yours would be better though.
The Game
The actual is basically just questions and answers, but coding wise; it's variables and prompts. Here is a short "Choose your own adventure" game I whipped up in a few minutes:
alert("Here comes BatSpider");
var answerOne = prompt("What do you do? Type 1 for Dance, Type 2 for Fight, Type 3 for Run Away");
if(answerOne==="1"){
alert("You start dancing, he gets in the mood and starts dancing too");
alert("You beat the game!");
}
else if(answerOne==="2"){
alert("You stay to fight");
alert("BatSpider kills you");
alert("You loose...");
}
else if(answerOne==="3"){
alert("You Run Away");
alert("You didn't win or loose, you big baby");
confirm("You should go back");
}
else{
confirm("I didn't quite understand you...");
alert("Try Again Later");
}
That's about it ^^^^ copy all of that and paste it in: http://www.writecodeonline.com/js to play the game (:
Hope this helped - Rick "Rixel" (TekBird).