From ef56ac3105dbd72cc5989edef9bbbb3fedfe6449 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 4 Jan 2012 23:30:24 -0700 Subject: Demo is being reworked. Fixed comment handling. --- demo.stage | 86 +++++++++++++++++++++++++++++---------------------------- src/options.cpp | 2 ++ src/parser.l | 12 +++++--- 3 files changed, 54 insertions(+), 46 deletions(-) diff --git a/demo.stage b/demo.stage index e0e9768..5ba0c13 100644 --- a/demo.stage +++ b/demo.stage @@ -7,6 +7,11 @@ game.start = <>; global { + /** + * This is an example of a very general "travelling" command. It inspects + * the current situation to see what exits are available, and if the given + * exit is in the situation.exits dictionary it goes that way. + */ command: "go" dir { if exists(situation.exits) then @@ -19,6 +24,9 @@ global display('''You're not really sure how to do that...'''); } + /** + * A simple command that lists the currently visible exits. + */ command: "exits" { if exists(situation.exits) then @@ -45,6 +53,10 @@ global } } + /** + * Takes an item from the current situation, if it's there, and adds it to + * the user's inventory. + */ command: "take" item { if exists(situation.items) then @@ -60,6 +72,9 @@ global display("You don't see that anywhere."); } + /** + * Lists items that are in the user's inventory. + */ command: "inventory" { out = 'You are carrying: '; @@ -83,7 +98,15 @@ situation <> setup { player.inventory = []; - goto( <> ); + + display('''You awaken after a long, dreamless sleep to find yourself + lying on a hard, cold, deserted beach. You have no memory of how + you got here. After a few minutes your eyes adjust to the bright, + glinting daylight shinning off the crests of the waves in the ocean. + You don't seem to have anything with you but the clothes you're + wearing. (You also posses an eerily accurate innate sense of + direction.)'''); + goto( <> ); } enter @@ -91,77 +114,56 @@ situation <> } } -situation <> +situation <> { + /** + * This overrides the global go command for the east parameter. + */ + command: "go" "east" + { + display("Those rocks are far too sharp and jagged, you don't think you + could make it over them."); + } + setup { situation.exits = { - 'south': <>, - 'east': <> + 'west': <> }; - situation.items = ['postcard']; } enter { - display('''You are in the dining room, it's very nice and warm. There - is a big table and...stuff. Looks like the living room is south, and - the kitchen is to the east.'''); + display('''You're standing on a narrow stretch of beach. The ocean + sparkles to the north, there's a cliff face just to the south. The + beach extends westward. To the east are some jagged rocks.'''); } } -situation <> +situation <> { setup { situation.exits = { - 'north': <> + 'east': <>, + 'west': <> }; } enter { - display('''Living room!'''); } } -situation <> +situation <> { - command: "open" "cupboard" - { - if not situation.bCupboardOpen then - { - situation.bCupboardOpen = true; - if "pan" in situation.cupboardItems then - { - display("You open the cupboard, it's mostly empty. There is a - single frying pan inside."); - situation.cupboardItems -= "pan"; - situation.items += "pan"; - - } - else - { - display("You open the cupboard, it's empty."); - } - } - else - { - display("The cupboard is already open."); - } - } - setup { situation.exits = { - 'west': <> + 'east': <> }; - situation.bCupboardOpen = false; - situation.cupboardItems = ['pan']; - situation.items = []; } enter { - display('''You are standing in the kitchen. There is an electric - range, a microwave, cupboards, a fridge, and a window.'''); } } + diff --git a/src/options.cpp b/src/options.cpp index 23a98a8..f5fb127 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -25,10 +25,12 @@ void Options::parse( int argc, char *argv[] ) " - Simple, Textual, Adventure Game Environment"); opt.addHelpBanner("usage: " + Bu::String(argv[0]) + " [options] \n"); + opt.addOption( Bu::slot( this, &Options::version ), "version", "Show full version info." ); opt.addOption( Bu::slot( this, &Options::builtins ), "builtins", "List available builtins." ); + opt.addHelpOption('h', "help"); opt.setNonOption( Bu::slot( this, &Options::nonOption ) ); opt.parse( argc, argv ); diff --git a/src/parser.l b/src/parser.l index e0bc340..7957c53 100644 --- a/src/parser.l +++ b/src/parser.l @@ -55,14 +55,15 @@ false { yylval->bValue = false; return tokBool; } null { return tokNull; } "<<" { BEGIN( sitname ); } -[- a-zA-Z0-9]+ { yylval->sValue = new Bu::String( yytext ); return tokSituationName; } +[-_ a-zA-Z0-9]+ { yylval->sValue = new Bu::String( yytext ); return tokSituationName; } ">>" { BEGIN( INITIAL ); } . REJECT; -"//"[^\n]* {} +"//"[^\n]*\n? {} -"/\*" { BEGIN( comment ); } -"\*/" { BEGIN( INITIAL ); } +"/*" { BEGIN( comment ); } +"*/" { BEGIN( INITIAL ); } +[\n\r] {} . {} [a-zA-Z_][a-zA-Z0-9_]* { yylval->sValue = new Bu::String( yytext ); return tokIdent; } @@ -112,4 +113,7 @@ null { return tokNull; } yylloc->first_line = yylloc->last_line; } +\r { } +. { throw Bu::ExceptionBase("Invalid character found '%s'", yytext ); } + %% -- cgit v1.2.3