Things used in this project

Hardware components:
Echo
Amazon Alexa Amazon Echo
×1
Software apps and online services:
Screen%20shot%202015 07 20%20at%206.10.26%20pm
Amazon Web Services AWS Lambda
Dp image kit 02
Amazon Alexa Alexa Skills Kit

Code

Poke the Biscuit Source CodeJavaScript
// Alexa SDK Stuff

'use strict';
const Alexa = require('alexa-sdk');
const APP_ID = "Poke the Biscuit";

// This array is the list of random text that the user may hear when they poke the biscuit. It is mostly scrubbed so it doesn't spoil the surprise when you play.

const pokeTexts = [
    "You poked the biscuit.",
    "You poked the biscuit carefully.",
    "The biscuit has been poked."
    ];
    
// This array is the list of text that the user hears when they perform a special poke. The first text corresponds to a double poke, the second a triple poke, and so on. All text has been changed or redacted to preserve the surprise.
    
const pokeSpecialTexts = [
    "Double Poke",
    "Triple Poke",
    "Four Pokes",
    "Five Pokes",
    "Six Pokes",
    "Seven Pokes",
    "You summoned an octopus to poke the biscuit for you.",
    "Nine Pokes",
    ]

// This is the bulk of the code and where the logic happens!

const handlers = {

// This runs whenever the user launches the skill. It tells the game to initialize itself.

    'LaunchRequest': function () {
        this.emit('InitializeBiscuit');
    },
    
//These 3 handlers intercepts user intents other than help and stop. It checks if the game has actually just launched, and if it was then it bumps the user to game initialization. If not then it runs whatever logic the player expects it to run.

    'PokeIntent': function () {
        if(Object.keys(this.attributes).length === 0) {
            this.emit('InitializeBiscuit');
        }
        else this.emit('PokeBiscuit');
    },
    'SpecialIntent': function() {
        if(Object.keys(this.attributes).length === 0) {
            this.emit('InitializeBiscuit');
        }
        else this.emit('SpecialPoke');
    },
    'CheckStatusIntent': function() {
        if(Object.keys(this.attributes).length === 0) {
            this.emit('InitializeBiscuit');
        }
        else this.emit('CheckStatus');
    },

// This starts the game by setting the poke counter to 0 and the special timer to 4 pokes. It then says a welcome message.    
    
    'InitializeBiscuit': function () {
        this.attributes['timesPoked'] = 0;
        this.attributes['specialTimer'] = 4;
        const speechOutput = "Welcome to Poke the Biscuit. To poke the biscuit, just say poke the biscuit. What would you like to do now?";
        const repromptText = "What would you like to do now? If you need help, you can just say help.";
        this.emit(':ask', speechOutput, APP_ID, repromptText);
    },
    
// The main portion of the code. When the user says poke the biscuit, the skill increments the poke counter, decrements the special timer, and then constructs a response using a randomly chosen phrase and the current status of the player.

    'PokeBiscuit': function () {
        this.attributes['timesPoked'] += 1;
        var pluralBiscuit = "s";
        if (this.attributes['timesPoked'] == 1) pluralBiscuit = "";
        var specialText = "";
        if (this.attributes['specialTimer'] <= 0) {
            specialText = "Your special poke is ready. To use it, say activate special poke. ";
        }
        else {
            this.attributes['specialTimer'] -= 1;
        }
        const pokeText = pokeTexts[Math.floor(Math.random() * pokeTexts.length)];
        const speechOutput = pokeText + " You have poked the biscuit a total of " + this.attributes['timesPoked'].toString() + " time" + pluralBiscuit + ". " + specialText + "What would you like to do now?";
        const repromptText = "What would you like to do now? If you need help, you can just say help.";
        this.emit(':ask', speechOutput, APP_ID, repromptText);
    },
    
// The special poke is handled here. It checks whether the special is ready, and if so generates a random number of pokes and responds with the appropriate phrase. If it's not ready it gives and error and asks the user what to do again.
    
    'SpecialPoke': function () {
        var speechOutput = "";
        var repromptText = "";
        const pokeIndex = Math.floor(Math.random() * pokeSpecialTexts.length);
        if (this.attributes['specialTimer'] >= 1) {
            speechOutput = "Your special poke is not ready yet. What would you like to do now?";
            repromptText = "What would you like to do now? If you need help, you can just say help.";
            this.emit(':ask', speechOutput, APP_ID, repromptText);
        }
        else {
            this.attributes['timesPoked'] += 2 + pokeIndex;
            this.attributes['specialTimer'] = 2 + Math.floor(Math.random() * pokeIndex);
            speechOutput = pokeSpecialTexts[pokeIndex] + " You have poked the biscuit a total of " + this.attributes['timesPoked'].toString() + " times. What would you like to do now?";
            repromptText = "What would you like to do now? If you need help, you can just say help.";
            this.emit(':ask', speechOutput, APP_ID, repromptText);
        }
    },
    
// Checking how many times the biscuit was poked is like poking it except without the poking part. It also generates a card so the user can see how many times they poked the biscuit in the Alexa app.
    
    'CheckStatus': function () {
        var pluralBiscuit = "s";
        if (this.attributes['timesPoked'] == 1) pluralBiscuit = "";
        var specialText = "";
        if (this.attributes['specialTimer'] <= 0) {
            specialText = "Your special poke is ready. To use it, say activate special poke. ";
        }
        const cardOutput = "You have poked the biscuit a total of " + this.attributes['timesPoked'].toString() + " time" + pluralBiscuit + ". " + specialText;
        const speechOutput = cardOutput + " What would you like to do now?";
        const repromptText = "What would you like to do now? If you need help, you can just say help.";
        this.emit(':askWithCard', speechOutput, repromptText, APP_ID, cardOutput);
    },
    
// Here's the help section. It just dumps the help text on the user and then generates a card with it in case the user wants to read it.

    'AMAZON.HelpIntent': function () {
        const cardOutput = "Poke the Biscuit is a game about poking a biscuit. Your score is how many times you poked the biscuit. To poke the biscuit, say poke the biscuit. Every so often your special skill will be usable. When that happens, say activate special poke to use it. To check how many times you have poked the biscuit without poking the biscuit, you can always ask me how many times have I poked the biscuit. Finally, if you are done poking the biscuit, just say stop.";
        const speechOutput = cardOutput + " What would you like to do?";
        const repromptText = "What would you like to do now? You can say poke the biscuit to poke the biscuit or say help if you want to listen to the list of options again.";
        this.emit(':askWithCard', speechOutput, repromptText, APP_ID, cardOutput);
    },
    
// Any standard cancel or stop request triggers the end game logic.

    'AMAZON.CancelIntent': function () {
        this.emit('StopPoking');
    },
    'AMAZON.StopIntent': function () {
        this.emit('StopPoking');
    },

// End game logic here. It ends the game and tells the user their score.

    'StopPoking': function () {
        var pluralBiscuit = "s";
        if (this.attributes['timesPoked'] == 1) pluralBiscuit = "";
        const speechOutput = "You have poked the biscuit a total of " + this.attributes['timesPoked'].toString() + " time" + pluralBiscuit + ". I hope you enjoyed poking the biscuit.";
        this.emit(':tellWithCard', speechOutput, APP_ID, speechOutput);
    },
};

// More Alexa-SDK stuff that makes Alexa work magically. :)

exports.handler = function (event, context) {
    const alexa = Alexa.handler(event, context);
    alexa.APP_ID = APP_ID;
    // To enable string internationalization (i18n) features, set a resources object.
    alexa.registerHandlers(handlers);
    alexa.execute();
};
Poke the Biscuit Intent SchemaJSON
All the ways that a user can interact with the skill. I used some default Amazon intents like help to save time.
{
  "intents": [
    {
      "intent": "PokeIntent"
    },
    {
      "intent": "SpecialIntent"
    },
    {
      "intent": "CheckStatusIntent"
    },
    {
      "intent": "AMAZON.HelpIntent"
    },
    {
      "intent": "AMAZON.StopIntent"
    },
    {
      "intent": "AMAZON.CancelIntent"
    }
  ]
}
Poke the Biscuit Sample UtterancesPlain text
Examples of what a user can say. While the skill says longer versions of phrases like "poke the biscuit" a short sharp "poke" is enough to poke the biscuit.
PokeIntent poke
PokeIntent poke biscuit
PokeIntent poke the thing
PokeIntent pokey
PokeIntent poke my biscuit
PokeIntent poke the biscuit
PokeIntent click
PokeIntent click biscuit
PokeIntent click the biscuit
SpecialIntent activate special poke
SpecialIntent use special poke
SpecialIntent special poke
SpecialIntent activate super poke
SpecialIntent use super poke
SpecialIntent super poke
SpecialIntent activate skill
SpecialIntent use skill
SpecialIntent activate special
SpecialIntent use special
SpecialIntent special
CheckStatusIntent status
CheckStatusIntent what is my status
CheckStatusIntent what's my status
CheckStatusIntent how am i doing
CheckStatusIntent check status
CheckStatusIntent check my status
CheckStatusIntent how many times have i poked the biscuit
CheckStatusIntent how many pokes
CheckStatusIntent how many times did i poke

Credits

Puffsona2
Wing

Teacher, Crafter, Maker, Singer, Dancer, Lv3 Cat / Lv4 Social Justice Bard. Award winning sheep. Pronouns depend on number of corvids present.

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Iron-Rich Foods!
Easy
  • 58
  • 3

A necessary skill for all people with iron deficiencies. It's always hard to find foods that are rich in iron. Until now. Just ask Alexa!

Movie Quotes Trivia
Easy
  • 24
  • 2

Full instructions

Test your knowledge of great movies by matching five famous movies quotes. It will be great fun activities among famaly and friends.

Wise Quotes
Easy
  • 133
  • 3

Full instructions

More than 100 wise quotes to empower you everyday.

Wildlife Facts Skill
Easy
  • 53
  • 2

Learn more about wildlife animals with more than 200 interesting facts with this Alexa skill.

Compost Helper Alexa Skill
Easy
  • 152
  • 3

Use Alexa to find out if a household item can be added to your compost.

Ferrari Facts
Easy
  • 272
  • 4

Full instructions

learn about the most expensive cars in the world with Ferrari Facts you you will know some interesting facts that you probably didn't hear a

Add projectSign up / Login