Adventure Choices
by m4xout
HTML
<div>You are standing in a clearing</div>
<div id="question"></div>
<div id="answers"></div>
<div>What do you want to do?</div>
JavaScript
var db = [
{
"question":"You just woke up, the world is your oyster... What are you going to do first?",
"answers":[
{"title":"Something fun","response":1},
{"title":"Something healthy","response":2},
{"title":"Something fun and healthy":3},
{"title":"Something boring":4},
{"title":"Cheat","response":5},
{"title":"Start Over","response":0}
]
},
{
"question":"You are in the South, There is one exit",
"answers":[
{"title":"North","response":0}
]
},
{
"question":"You are in the North, There is one exit",
"answers":[
{"title":"South","response":0}
]
},
{
"question":"You are in the West, There are two exits.",
"answers":[
{"title":"East","response":0},
{"title":"West","response":5}
]
},
{
"question":"You are in the East, There is one exit",
"answers":[
{"title":"West","response":0}
]
},
{
"question":"You are the winner!",
"answers":[
{"title":"Start Over","response":0}
]
},
{
"question":"You are the winner!",
"answers":[
{"title":"Start Over","response":0}
]
}
];
var currentLocation = 0;
window.printCurrentLocation = function(){
document.getElementById("question").innerHTML = db[currentLocation].question;
var answers = "";
for(var i=0,l=db[currentLocation].answers.length;i<l;i++){
answers += "<p><button onclick='setLocation("+db[currentLocation].answers[i].response+")'>"+db[currentLocation].answers[i].title+"</button></p>";
}
document.getElementById("answers").innerHTML = answers;
}
window.setLocation = function(num) {
currentLocation = num;
window.printCurrentLocation();
}
window.printCurrentLocation();