VoiceXML Adventure Game - Mother of Perl | 6 | WebReference

VoiceXML Adventure Game - Mother of Perl | 6

To page 1To page 2To page 3To page 4To page 5current pageTo page 7
[previous] [next]

VoiceXML Adventure Game

Making Our Adventure Dynamic

Now that we have a working VoiceXML document that provides some dynamic capabilities, it's time to tie in into a back-end Perl script that provides true dynamic capabilities. For this first run of our dynamic Perl script, we'll develop a script that dynamically generates rooms. Each room will always have three doors. Because the script is random, there are many different possible combinations. Initially, users won't be able to interact with any of the objects in the rooms, they'll only be able to open doors. In Part III, we'll add this capability.


use CGI;
use strict;
my @rooms = (
             'large ball room',
	     'pool hall',
             'large red barn',
             'seven eleven',
             'funeral parlor',
             'windy room with bark walls',
             'dimly lit tunnel',
             'prison cell',
             'hospital waiting room',
             'underground parking garage',
             'circular stairwell',
             'janitors closet',
             'subway car',
             'lighthouse tower',
my @objects = (
               'full of clowns dressed in red',
               'full of smoke but no people',
               'with a dead horse on the floor',
               'with a broken slurpy machine. In the corner, a troll is sniffing the burritos',
               'with black curtains and something under the covers',
               'with padded walls',
               'with wood bark walls',
               'with flickering florescent lights',
               'with an oil spotted shag carpet',
               'full of mad raving lunatics',
               'with a man and his monkey',
               'full of monkeys',
               'with William Shatner singing tambourine man',
               'with a large hungry monkey',
               'full of drunken sailors',
               'full of blind dwarves',
               'full of Windows programmers',
               'with a man scratching his monkey'
my $q = new CGI;
print "Content-Type: text/xml\n\n";
sub prompt {
my $room   = $rooms[int(rand(scalar(@rooms)))];
my $object = $objects[int(rand(scalar(@objects)))];
   print <<VXML;
<?xml version="1.0"?>
<vxml version="1.0">
    <field name="answer">
            [dtmf-1 one first] {<option "door1">}
            [dtmf-2 two second] {<option "door2">}
            [dtmf-3 three third] {<option "door3">}
            [(touch the monkey)] {<option "monkey">}
            [dtmf-0 huh help what doh] {<option "help">}
	<audio>You are in a $room $object. There are three doors.</audio> 
        <submit next="http://www.textant.com/cgi-bin/room.pl"/>
      <nomatch count="1">
        <audio>Wrong door.</audio>
        <audio>To open the first door, press or say 1.</audio>
        <audio>To open the second door, press or say 2.</audio>
        <audio>To open the third door, press or say 3.</audio>
      <nomatch count="2">
        <audio>You fool! That is not a choice I am giving you.</audio>
        <audio>Press or say 1, 2, or 3.</audio>
      <nomatch count="3">
        <audio>Pretend you have a brain and press 1, 2, or 3.</audio>
      <noinput count="1">
        <audio>You need to select a door.</audio>
        <audio>Press or say 1, 2, or 3.</audio>
      <noinput count="2">
        <audio>If you do not press 1, 2, or 3, I am going to kill
        the monkey!</audio>
      <noinput count="3">
        <audio>Ok. That's it. The monkey is dead and it's your
        fault because you did not choose 1, 2, or 3.</audio>
      <noinput count="4">
        <audio>1, 2, or 3.</audio>
        <audio>Why are you asking for help?</audio>
        <audio>Go away.</audio>

To page 1To page 2To page 3To page 4To page 5current pageTo page 7
[previous] [next]


Produced by Jonathan Eisenzopf
All Rights Reserved. Legal Notices.
Created: March 8, 2001

URL: http://www.webreference.com/perl/tutorial/21/6.html