Showing posts with label adventure. Show all posts
Showing posts with label adventure. Show all posts

Saturday, May 25, 2013

What Would You Like to Eat Today?


Oh man, it is so totally freeing not having to create those stale blog posts! Here are two more mini -games micro-games I whipped up later in the week. They're both related to food (no surprise, right?) and I think I'm really getting to master the whole choose-your-adventure-game-mode. I think it would be relatively achievable to write a storybook and have several different possible endings! How cool would that be? I also found out that it's actually pretty useful to create diagrams in a notebook before starting to code everything out. It's like drafting an essay or creating a plan so that everything makes sense and you don't have to waste time figuring those silly little details out. Ah, this is so much better and way more engaging! I hope you all give these games a try!

// here's my first version: 

var omelette = prompt("Good morning! Are you hungry for breakfast? The chickens and ducks laid a whole bunch of eggs, so we're planning to make omelettes for everyone. Do you eat meat?").toUpperCase();

switch(omelette) {
  case 'YES':
    var salmon = prompt("Do you eat fish?").toUpperCase();
    if(salmon === 'YES') {
      console.log("One smoked salmon and tomato omelette coming right up!");
    } else {
      console.log("We'll have your ham and cheese omelette plated in a jiffy!");
    }
    break;
  case 'NO':
      var dairy = prompt("Do you eat dairy?").toUpperCase();
    if(dairy === 'YES') {
      console.log("Well here's a cheesy mushroom and onion omelette... one of my favorites!");
    } else {
      console.log("Sorry, we don't have any omelettes for you!");
    }
    break;
  default:
    console.log("Say you don't like omelettes? Well we have some soggy oatmeal leftover from yesterday's brunch...");
}
     

// here's the second (and slightly more intricate) one: 

var hungry = prompt("So I see you're feeling a little hungry. Well, what time is it (BREAKFAST, LUNCH, or DINNER time)?").toUpperCase();

switch(hungry) {
  case 'BREAKFAST':
    var meat_breakfast = prompt("It's breakfast time! Do you eat meat?").toUpperCase();
    var dairy_breakfast = prompt("Do you eat dairy?").toUpperCase();
    if(meat_breakfast === 'YES' && dairy_breakfast === 'YES') {
      console.log("Have some bacon and eggs!");
    } else if(meat_breakfast === 'YES' && dairy_breakfast === 'NO') {
      console.log("Allergic to dairy? How about some sausage and hashbrowns?");
    } else if(meat_breakfast === 'NO' && dairy_breakfast === 'YES') {
      console.log("What about a tomato and spinach omelette?");
    } else {
      console.log("How about some fresh fruit?");
    }
    break;
  case 'LUNCH':
    var meat_lunch = prompt("Lunchtime! Do you eat meat?").toUpperCase();
    var dairy_lunch = prompt("What about dairy? Can you have milk? Eggs?").toUpperCase();
    if(meat_lunch === 'YES' && dairy_lunch === 'YES') {
      console.log("Alrighty, how about a ham and cheese sandwich? Does that sound good to you?");
    } else if(meat_lunch === 'YES' && dairy_lunch === 'NO') {
      console.log("Well what about just a tunafish sandwich?");
    } else if(meat_lunch === 'NO' && dairy_lunch === 'YES') {
      console.log("Grilled cheese for one! Coming right up!");
    } else {
      console.log("What about a classic PB and J sandwich? Does that sound good to you?");
    }
    break;
  case 'DINNER':
    var meat_dinner = prompt("Ah, the last and BEST meal of the day! Do you include meat in your diet?").toUpperCase();
    var dairy_dinner = prompt("How about dairy?").toUpperCase();
    if(meat_dinner === 'YES' && dairy_dinner === 'YES') {
      console.log("What about some pepperoni pizza?");
    } else if(meat_dinner === 'YES' && dairy_dinner === 'NO') {
      console.log("How about the classic spaghetti and meatballs? We'll hold the cheese, don't worry about that!");
    } else if(meat_dinner === 'NO' && dairy_dinner === 'YES') {
      console.log("In the mood for mac and cheese! I know I am!");
    } else {
      console.log("Well in that case, what about a nice refreshing kale salad?");
    }
    break;
  default:
    console.log("Hmm... you sure you're hungry?");
}


P.S. I started using canv.as and it is so freaking fun. Here's my page.

Saturday, April 27, 2013

J.S. Project: Choose Your Own Adventure! (Continued)


Here is my really lame and micro version of the choose-your-own-adventure game. It was inspired by this.

confirm("Ready to play this awesome game?");

var age = prompt("How old are you?");
    if (age > 18) {
        console.log("OK, you're allowed to play, but I'm not responsible for anything that goes wrong.");
    } else {
        console.log("Alllllright. Let's get on with the show, shall we?");
    }
 
// intro
console.log("You are a sloth in the middle of the rainforest. Your goal is to stay alive. Let the first trial begin");

console.log("You feel the sudden urge to use the bathroom.");

var userAnswer1 = prompt("Will you climb down from the safety of your tree to relieve yourself?");
if (userAnswer1 === "yes") {
    console.log("Oh no! A sunbear just appeared from out of nowhere! It seems like you're going to end up for dinner! Uh oh.");
} else {
    console.log("Oops. You just peed all over yourself. Gross.");
}

// feedback
var feedback = prompt("How was the game? I know it was a bit short, but please rate it from 1 - 10!");
if (feedback > 8) {
    console.log("So glad you liked it! Stay tuned for more!");
} else {
    console.log("Boo. You poop.");
}


P.S. Here's a vlog I created today! I'd totally appreciate it if you check it out!! :) 

Friday, April 26, 2013

J.S. Project: Choose Your Own Adventure!


Today, we're going to create a 'choose your own adventure' game. Exciting, right? It will have a basic story line, the opportunity for the user to make a couple of decisions, and a happy ending (hopefully).

01 / 07 : Let's use the confirm command to ask your user if they are ready to play.
    HINT - remember, to get the user to confirm something, the syntax looks like this:
        confirm("I understand confirm!");

// Check if the user is ready to play!
confirm("Are you ready to embark on this adventure of fun?");


02 / 07 : However before we start playing, we're going to check to see if the user is old enough to play! This step involves two bits of code. Declare a variable age using prompt. Make that age equal to the answer you prompt the user to give (ie. ask the user 'how old are you?'). Finally, create an if / else statement: if the user is less than 19, use console.log and tel the that they're allowed to play but you take no responsibility. Else, use console.log and give them an encouraging message to play on!
    HINT - recall the syntax for if / else statements:
        if (condition) {
            code code code;
        } else {
            code code code;
        }

var age = prompt("How old are you?");
    if (age < 18) {
        console.log("You're allowed to play, but I take no responsibility.");
    } else {
        console.log("Well, what are you waiting for? Let's get started already!");
    }


03 / 07 : We've gotta set up the scene for our story. Here's a short little introduction that we can use for now: Snow White and Batman were hanging out at the bus stop, waiting to go to the shops. There was a sale on and both needed some new threads. You've never really liked Batman. You walk up to him.
Let's print the intro using console.log. The intro is full of words... remember how words are called 'strings' in JavaScript? Don't forget how to properly use strings!
    HINT - don't forget to put quotes around the intro!

// introduction
console.log("Snow White and Batman were hanging out at the bus stop, waiting to go to the shops. There was a sale on and both needed some new threads. You've never really liked Batman. You walk up to him.");


04 / 07 : Our story is ready to move along! There's a scene and your user is about to talk to batman. Under your existing code, print out the storyline: "Batman glares at you." Then declare a variable userAnswer and make it equal a prompt that asks the user "Are you feeling lucky, punk?" (This will be the question that Batman asks your user).

console.log("Batman glares at you.");
var userAnswer = prompt("Are you feeling lucky, punk?");


05 / 07 : Now we've gotta create different scenarios using the if / else statements! Use an if / else statement to write out the last part of this game. If userAnswer is "yes", print out: "Batman hits you very hard. It's Batman and you're you! Of course Batman wins!" Otherwise, print out: "You did not say yes to feeling lucky. Good choice! You are a winner in the game of not getting beaten up by Batman."
    HINT - Remember: = is for assignment, and === is to check this are equal!

if (userAnswer === "yes") {
    console.log("Batman hits you very hard. It's Batman and you're you! Of course Batman wins!");
} else {
    console.log "You did not say yes to feeling lucky. Good choice! You are a winner in the game of not getting beaten up by Batman.");
}


06 / 07 : It's probably worthwhile to ask your user for feedback. Let's create a variable called feedback and prompt the user to rate your game out of 10. If the score is greater than 8, print out: "This is just the beginning of my game empire. Stay tuned for more!" Otherwise, print out: "I slaved away at this game and you gave me that score?! The nerve! Just you wait!"
    HINT - var feedback  = prompt("Message");

var feedback = prompt("Could you rate my game out of 10?");
    if (feedback > 8) {
        console.log("This is just the beginning of my game empire. Stay tuned for more!");
    } else {
        console.log("I slaved away at this game and you gave me that score?! The nerve! Just you wait!");
    }


07 / 07 : Congrats! You've just programmed your first game! Now it's your turn to program your own 'choose your own aventure game'.