<?xml version="1.0"?>
<!DOCTYPE vxml PUBLIC "-//BeVocal Inc//VoiceXML 2.0//EN"
 "http://cafe.bevocal.com/libraries/dtd/vxml2-0-bevocal.dtd">

<vxml version="2.0" xmlns="http://www.w3.org/2001/vxml">

<!-- *************************************************************** -->
<!-- * DEBUGGING                                                   * -->
<!-- *                                                             * -->
<!-- * Uncomment this meta tag, in order to send a logfile to      * -->
<!-- * your inbox when a call is made to your application.         * -->
<!-- *                                                             * -->
<!-- * Remember to edit the email address!                         * -->
<!-- *                                                             * -->
<!-- *************************************************************** -->

<!-- <meta name="maintainer" content="ian.bogost@lcc.gatech.edu" /> -->

<!-- *************************************************************** -->
<!-- * GENERAL STUFF                                               * -->
<!-- *                                                             * -->
<!-- * This link statement will speed up your debugging, by        * -->
<!-- *   allowing you to reload the file, while you're dialed into * -->
<!-- *   your application.  Just say "BeVocal Reload", or hit the  * -->
<!-- *   star key three times to force a reload.                   * -->
<!-- *                                                             * -->
<!-- * Remember to edit the "next" attribute to match the name of  * -->
<!-- *   this file!                                                * -->
<!-- *                                                             * -->
<!-- *************************************************************** -->

<link maxage="0" next="icecream.vxml">
	<grammar version="1.0">
		[
			(bevocal reload)
			(dtmf-star dtmf-star dtmf-star)
		]
	</grammar>
</link>
	
<script>
<![CDATA[
	var res;
	var vocab;
	var nouns;		
	var adjectives;
	var ADJ;
	var NOU;

	function getNode(vocab, tagname) {	
		return vocab.documentElement.getElementsByTagName(tagname).item(0);
	}
	
	function getChildNodes(vocab, tagname) {
		return getNode(vocab, tagname).childNodes;
	}
			
	// Initialize the Nodelists for each main part of speech.
	function init(vocabulary) {
		vocab = vocabulary;	
		nouns = getChildNodes(vocab, "nouns");
		adjectives = getChildNodes(vocab, "adjectives");

        // These are the possible codes a user can input
		ADJ = 47;         // for an adjective
		NOU = 84;         // for a noun
	}

	function rnd(len)
	{
		return(Math.round(Math.random()* len));
	}
	
	function word(nodelist)
	{		  
		return(nodelist.item(rnd(nodelist.length-1)));
	}
			
	function tts(code)
	{
		var l = word((code == ADJ) ? adjectives : nouns)
		var w = l.firstChild.nodeValue;
		bevocal.log("tts:word="+w);
		return w;
	}
	
	function checkCode(code)
	{
		bevocal.log("checkCode:code="+code);
		if (code == ADJ || code == NOU) return false;
		else return true;
	}
]]>
</script>  

<!-- The URL which refers to an XML file containing the vocabulary. -->
<var name="vocabularyURL" />
<var name="myWord"/>
<var name="myCode"/>
   
<!-- ******************************* -->
<!-- * FORM  - Welcome prompt.     * -->
<!-- ******************************* -->
	 
<form id="welcome">
	<block> 
		<prompt>Welcome to a very small ice cream creation game.</prompt>
		<assign name="document.vocabularyURL" expr="'icecream.grxml'"/>
		<goto next="#get_vocabulary"/>         
	</block>
</form>

<!-- **************************************************** -->
<!-- * FORM  - Get the vocabulary using the <data> tag, * -->
<!-- *        and initialize with that vocabulary.      * -->
<!-- **************************************************** -->
<form id="get_vocabulary">
	<data name="vocabulary" expr="document.vocabularyURL"/>
	<block>
		<script>init(vocabulary);</script>
		<goto next="#set_type"/>         
	
	</block>
</form>

<!-- ******************************* -->
<!-- * FORM  - Settings.	       * -->
<!-- ******************************* -->

<form id="set_type">
	<field name="code_num" type="digits"> 
		<prompt>
			Please say the access code written on your instructions.
		</prompt> 
		<filled> 
			<if cond="checkCode(code_num)"> 
           		<prompt>
             		Sorry, I don't recognize that code.
           		</prompt> 
           		<clear/>
           		<reprompt/>
         	<else/>
				<assign name="myCode" expr="code_num" />
            	<prompt>
             		Groovy. Your access code is 
		            <say-as type="number:digits"> <value expr="code_num"/> </say-as>
		            Let's get started.
	           </prompt>
	           <goto next="#instructions1"/>         
    	    </if> 		
		</filled> 
	</field> 
</form>
	 
<!-- ******************************* -->
<!-- * FORM  - Instructions 1.     * -->
<!-- ******************************* -->
	 
<form id="instructions1">
	<block> 
		<prompt>
			Here's how to play. I'm going to give you a word. 
			Once you have the word, commit it to memory or write it down. 
			Then I'll tell you what to do next.</prompt>
		<goto next="#play_game"/>         
	</block>
</form>

<!-- **************************************************** -->
<!-- * FORM  - Play the Game				            * -->
<!-- **************************************************** -->
<form id="play_game">
    <block>	
			<assign name="myWord" expr="tts(myCode)" />
			
			<prompt>Your word is 
           		<value expr="myWord"/>   
           		<break size="small"/>
           		Once again, your word is 
           		<value expr="myWord"/>   
           		<break size="small"/>
         	</prompt>
		<goto next="#instructions2"/>         
    </block>
</form>

<!-- ******************************* -->
<!-- * FORM  - Instructions 2.     * -->
<!-- ******************************* -->
	 
<form id="instructions2">
	<field name="understood" type="boolean">
		<prompt>
			Ok, you should have at least one other person with you calling in to get other words. 
			Once you have all the words, hang up and combine them into a phrase. 
			Now, using the ice cream and mixin ingredients, construct a flavor
			that best expresses the meaning of that phrase. Makes sense? 
			Remember, your word is 
           		<value expr="myWord"/>   
			Do you want me to repeat these instructions?
		</prompt>
		<filled>
			<if cond="understood">
				<goto next="#instructions2"/>
			<else/>
				<prompt>Ok, that's it! Optionally, once you've ordered, sit down somewhere and write a short story or poem about your creation on a sticky label. Post your creation name and story somewhere interesting. Goodbye!</prompt>
				<exit/>
			</if>
		</filled>
	</field>
</form>

</vxml>

