Skip to content

Instantly share code, notes, and snippets.

@ronsims2
Created January 11, 2015 20:31
Show Gist options
  • Save ronsims2/a47d6b7bfa3daea0f347 to your computer and use it in GitHub Desktop.
Save ronsims2/a47d6b7bfa3daea0f347 to your computer and use it in GitHub Desktop.
Adventure Engine // source http://jsbin.com/vuvexa
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Adventure Engine" />
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
(function(w){
/**********
GLOBALS ARE A BAD IDEA, but they are so easy to use, we will reorganize these in an advanced lesson
Game uses flash fram model to organize scene/level concepts
*********/
var hasLantern = false;//Need to see in Dark Forest
var hasForestKey = false; //Nee to get into Dark Forest Temple
var matches = 5; //Can use these to temporarily look in dark places
var money = 0;
var hearts = 5;
var enemy1 = "Grublor";
var enemy2 = "Stolak";
var enemy3 = "Smoke Bhort";
var ForestTempleBoss = "King Malvox";
function rollDice(){
var diceNumber = Math.random() * 12 + 1;
diceNumber = Math.floor(diceNumber);
return diceNumber;
}
//can use odd and even numbers to distinguish differnt enemy names
function fightEnemy(name){
var fightRoll = rollDice();
if (fightRoll >= 6) {
return true;
}
return false;
}
function playScreen1(){
var screen1Text = "The princess is not going to save herself, where will you start? \r\n" +
"A) Venture into the Dark Forest. \r\n" +
"B) Vist the Dark Forest Temple \r\n" +
"C) Quit";
function checkScreen1(choice){
if (choice === "A") {
playScreen2();
return true;
}
if (choice === "B") {
alert("You need a key to get in the Dark Forest Temple, maybe you should look for one in the forest");
playScreen1();
return true;
}
if (choice === "C") {
//Returning false halts execution
console.log(arguments);
return false;
}
}
var screen1Choice = prompt(screen1Text);
checkScreen1(screen1Choice);
}
function playScreen2(){
var screen2Question = "The forest is dark, you will need a latern to find anything, what will you do? \r\n";
if (hasLantern) {
screen2Question = "Keep your sword ready, the light of the lantern has shown you the true danger ahead, what will you do next? \r\n";
}
var screen2Text = screen2Question +
"A) Look for a lantern\r\n" +
"B) Look for the Key\r\n" +
"C) Quit";
function checkScreen2(choice){
console.log("matches", matches);
if (choice === "A") {
if (hasLantern) {
alert("You can't find something you already have, look for the key already!");
playScreen2();
return true;
}
else {
var lanternRoll = rollDice();
if (matches) {
matches--;
if (lanternRoll > 6){
hasLantern = true;
alert("You found a lantern!, Now you don't have to keep burning your fingers with those pesky matches \r\n" +
"You have " + matches + " matches left.");
}
else {
alert("Ouch, you burned your finger and waste one of your precious matches. \r\n" +
"You'd better hurry up and find the lattern quickly, you only have " + matches + " left.");
}
playScreen2();
return true;
}
else {
alert("You don't have anymore matches left and you can't see anything. You have been lost to the forest's darkness.");
return false;
}
}
}
if (choice === "B") {
if (hasLantern || hasMatches) {
if (!hasLantern) {
//use a match if there is no lantern
matches--;
}
var keyRoll = rollDice();
if (keyRoll < 5) {
//fight enemy
var enemy = enemy1;
if (keyRoll % 2) {
enemy = enemy2;
}
var fightMsg = "A " + enemy + " has appeared, prepare for battle.";
alert(fightMsg);
var fightResult = fightEnemy(enemy);
if (fightResult) {
var reward = 5;
alert("You fought valiantly, you earned " + reward + " gems.");
money += reward;
}
else {
hearts--;
if (hearts){
alert("You faught hard, but you sustained some damage before you vanquished your foe. You have " + hearts + " hearts left.");
}
else {
alert("The" + enemy + "was too strong, you suffered the ultimate defeat - GAME OVER.");
return false;
}
}
playScreen2();
return true;
}
else {
if (keyRoll === 6 || keyRoll === 9 || keyRoll === 12) {
//Found key
var msg = "Congratulation, you found they temple key!";
if (!hasLantern) {
msg += " I hope you have a lantern, there aren't enough matches in the world to make it through the temple.";
}
alert(msg);
playScreen3();
return true;
}
else {
var msg2 = "Drats, you have been looking, but you have yet to find the temple key.";
if (!hasLantern) {
msg2 = "No luck yet, you'd better find the key soon, you only have " + matches + "left";
}
alert(msg2);
}
}
}
else {
alert("You don't have a lantern or matches and have been swallowed by the dark, you are doomed to wander in the darkness of the forest forever.");
return false;
}
playScreen2();
return true;
}
if (choice === "C") {
//Returning false halts execution
console.log(arguments);
return false;
}
}
var screen2Choice = prompt(screen2Text);
checkScreen2(screen2Choice);
}
function playScreen3(){
var screen3Text = "Choose your fate:\r\n" +
"A) Got to next screen\r\n" +
"B) Got to the screen after the next screen\r\n" +
"C) Quit";
alert("screen three");
}
function main(){
var continuGame = true;
continueGame = playScreen1();
if (continueGame){
}
console.log('end of main loop.');
//If we get here the player quit
alert("Couldn't take it huh? Maybe next time.");
return false;
}
main();
})(window);
</script>
<script id="jsbin-source-javascript" type="text/javascript">(function(w){
/**********
GLOBALS ARE A BAD IDEA, but they are so easy to use, we will reorganize these in an advanced lesson
Game uses flash fram model to organize scene/level concepts
*********/
var hasLantern = false;//Need to see in Dark Forest
var hasForestKey = false; //Nee to get into Dark Forest Temple
var matches = 5; //Can use these to temporarily look in dark places
var money = 0;
var hearts = 5;
var enemy1 = "Grublor";
var enemy2 = "Stolak";
var enemy3 = "Smoke Bhort";
var ForestTempleBoss = "King Malvox";
function rollDice(){
var diceNumber = Math.random() * 12 + 1;
diceNumber = Math.floor(diceNumber);
return diceNumber;
}
//can use odd and even numbers to distinguish differnt enemy names
function fightEnemy(name){
var fightRoll = rollDice();
if (fightRoll >= 6) {
return true;
}
return false;
}
function playScreen1(){
var screen1Text = "The princess is not going to save herself, where will you start? \r\n" +
"A) Venture into the Dark Forest. \r\n" +
"B) Vist the Dark Forest Temple \r\n" +
"C) Quit";
function checkScreen1(choice){
if (choice === "A") {
playScreen2();
return true;
}
if (choice === "B") {
alert("You need a key to get in the Dark Forest Temple, maybe you should look for one in the forest");
playScreen1();
return true;
}
if (choice === "C") {
//Returning false halts execution
console.log(arguments);
return false;
}
}
var screen1Choice = prompt(screen1Text);
checkScreen1(screen1Choice);
}
function playScreen2(){
var screen2Question = "The forest is dark, you will need a latern to find anything, what will you do? \r\n";
if (hasLantern) {
screen2Question = "Keep your sword ready, the light of the lantern has shown you the true danger ahead, what will you do next? \r\n";
}
var screen2Text = screen2Question +
"A) Look for a lantern\r\n" +
"B) Look for the Key\r\n" +
"C) Quit";
function checkScreen2(choice){
console.log("matches", matches);
if (choice === "A") {
if (hasLantern) {
alert("You can't find something you already have, look for the key already!");
playScreen2();
return true;
}
else {
var lanternRoll = rollDice();
if (matches) {
matches--;
if (lanternRoll > 6){
hasLantern = true;
alert("You found a lantern!, Now you don't have to keep burning your fingers with those pesky matches \r\n" +
"You have " + matches + " matches left.");
}
else {
alert("Ouch, you burned your finger and waste one of your precious matches. \r\n" +
"You'd better hurry up and find the lattern quickly, you only have " + matches + " left.");
}
playScreen2();
return true;
}
else {
alert("You don't have anymore matches left and you can't see anything. You have been lost to the forest's darkness.");
return false;
}
}
}
if (choice === "B") {
if (hasLantern || hasMatches) {
if (!hasLantern) {
//use a match if there is no lantern
matches--;
}
var keyRoll = rollDice();
if (keyRoll < 5) {
//fight enemy
var enemy = enemy1;
if (keyRoll % 2) {
enemy = enemy2;
}
var fightMsg = "A " + enemy + " has appeared, prepare for battle.";
alert(fightMsg);
var fightResult = fightEnemy(enemy);
if (fightResult) {
var reward = 5;
alert("You fought valiantly, you earned " + reward + " gems.");
money += reward;
}
else {
hearts--;
if (hearts){
alert("You faught hard, but you sustained some damage before you vanquished your foe. You have " + hearts + " hearts left.");
}
else {
alert("The" + enemy + "was too strong, you suffered the ultimate defeat - GAME OVER.");
return false;
}
}
playScreen2();
return true;
}
else {
if (keyRoll === 6 || keyRoll === 9 || keyRoll === 12) {
//Found key
var msg = "Congratulation, you found they temple key!";
if (!hasLantern) {
msg += " I hope you have a lantern, there aren't enough matches in the world to make it through the temple.";
}
alert(msg);
playScreen3();
return true;
}
else {
var msg2 = "Drats, you have been looking, but you have yet to find the temple key.";
if (!hasLantern) {
msg2 = "No luck yet, you'd better find the key soon, you only have " + matches + "left";
}
alert(msg2);
}
}
}
else {
alert("You don't have a lantern or matches and have been swallowed by the dark, you are doomed to wander in the darkness of the forest forever.");
return false;
}
playScreen2();
return true;
}
if (choice === "C") {
//Returning false halts execution
console.log(arguments);
return false;
}
}
var screen2Choice = prompt(screen2Text);
checkScreen2(screen2Choice);
}
function playScreen3(){
var screen3Text = "Choose your fate:\r\n" +
"A) Got to next screen\r\n" +
"B) Got to the screen after the next screen\r\n" +
"C) Quit";
alert("screen three");
}
function main(){
var continuGame = true;
continueGame = playScreen1();
if (continueGame){
}
console.log('end of main loop.');
//If we get here the player quit
alert("Couldn't take it huh? Maybe next time.");
return false;
}
main();
})(window);
</script></body>
</html>
(function(w){
/**********
GLOBALS ARE A BAD IDEA, but they are so easy to use, we will reorganize these in an advanced lesson
Game uses flash fram model to organize scene/level concepts
*********/
var hasLantern = false;//Need to see in Dark Forest
var hasForestKey = false; //Nee to get into Dark Forest Temple
var matches = 5; //Can use these to temporarily look in dark places
var money = 0;
var hearts = 5;
var enemy1 = "Grublor";
var enemy2 = "Stolak";
var enemy3 = "Smoke Bhort";
var ForestTempleBoss = "King Malvox";
function rollDice(){
var diceNumber = Math.random() * 12 + 1;
diceNumber = Math.floor(diceNumber);
return diceNumber;
}
//can use odd and even numbers to distinguish differnt enemy names
function fightEnemy(name){
var fightRoll = rollDice();
if (fightRoll >= 6) {
return true;
}
return false;
}
function playScreen1(){
var screen1Text = "The princess is not going to save herself, where will you start? \r\n" +
"A) Venture into the Dark Forest. \r\n" +
"B) Vist the Dark Forest Temple \r\n" +
"C) Quit";
function checkScreen1(choice){
if (choice === "A") {
playScreen2();
return true;
}
if (choice === "B") {
alert("You need a key to get in the Dark Forest Temple, maybe you should look for one in the forest");
playScreen1();
return true;
}
if (choice === "C") {
//Returning false halts execution
console.log(arguments);
return false;
}
}
var screen1Choice = prompt(screen1Text);
checkScreen1(screen1Choice);
}
function playScreen2(){
var screen2Question = "The forest is dark, you will need a latern to find anything, what will you do? \r\n";
if (hasLantern) {
screen2Question = "Keep your sword ready, the light of the lantern has shown you the true danger ahead, what will you do next? \r\n";
}
var screen2Text = screen2Question +
"A) Look for a lantern\r\n" +
"B) Look for the Key\r\n" +
"C) Quit";
function checkScreen2(choice){
console.log("matches", matches);
if (choice === "A") {
if (hasLantern) {
alert("You can't find something you already have, look for the key already!");
playScreen2();
return true;
}
else {
var lanternRoll = rollDice();
if (matches) {
matches--;
if (lanternRoll > 6){
hasLantern = true;
alert("You found a lantern!, Now you don't have to keep burning your fingers with those pesky matches \r\n" +
"You have " + matches + " matches left.");
}
else {
alert("Ouch, you burned your finger and waste one of your precious matches. \r\n" +
"You'd better hurry up and find the lattern quickly, you only have " + matches + " left.");
}
playScreen2();
return true;
}
else {
alert("You don't have anymore matches left and you can't see anything. You have been lost to the forest's darkness.");
return false;
}
}
}
if (choice === "B") {
if (hasLantern || hasMatches) {
if (!hasLantern) {
//use a match if there is no lantern
matches--;
}
var keyRoll = rollDice();
if (keyRoll < 5) {
//fight enemy
var enemy = enemy1;
if (keyRoll % 2) {
enemy = enemy2;
}
var fightMsg = "A " + enemy + " has appeared, prepare for battle.";
alert(fightMsg);
var fightResult = fightEnemy(enemy);
if (fightResult) {
var reward = 5;
alert("You fought valiantly, you earned " + reward + " gems.");
money += reward;
}
else {
hearts--;
if (hearts){
alert("You faught hard, but you sustained some damage before you vanquished your foe. You have " + hearts + " hearts left.");
}
else {
alert("The" + enemy + "was too strong, you suffered the ultimate defeat - GAME OVER.");
return false;
}
}
playScreen2();
return true;
}
else {
if (keyRoll === 6 || keyRoll === 9 || keyRoll === 12) {
//Found key
var msg = "Congratulation, you found they temple key!";
if (!hasLantern) {
msg += " I hope you have a lantern, there aren't enough matches in the world to make it through the temple.";
}
alert(msg);
playScreen3();
return true;
}
else {
var msg2 = "Drats, you have been looking, but you have yet to find the temple key.";
if (!hasLantern) {
msg2 = "No luck yet, you'd better find the key soon, you only have " + matches + "left";
}
alert(msg2);
}
}
}
else {
alert("You don't have a lantern or matches and have been swallowed by the dark, you are doomed to wander in the darkness of the forest forever.");
return false;
}
playScreen2();
return true;
}
if (choice === "C") {
//Returning false halts execution
console.log(arguments);
return false;
}
}
var screen2Choice = prompt(screen2Text);
checkScreen2(screen2Choice);
}
function playScreen3(){
var screen3Text = "Choose your fate:\r\n" +
"A) Got to next screen\r\n" +
"B) Got to the screen after the next screen\r\n" +
"C) Quit";
alert("screen three");
}
function main(){
var continuGame = true;
continueGame = playScreen1();
if (continueGame){
}
console.log('end of main loop.');
//If we get here the player quit
alert("Couldn't take it huh? Maybe next time.");
return false;
}
main();
})(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment