Inform - Resources - Examples

Back to List

Inventory
Complete

Backward
Forward

Plain
Coloured
Gaudy

This code
in plain text

Browsing Toyshop.inf

Building Blocks (lines 554-643)

554  ! >BL  The class Block provides for stackable building blocks.
555  !
556  !   Note that with the "describe" routine missing, the game would still
557  !   correctly describe stacks of blocks: just a little less elegantly.
558  ! ----------------------------------------------------------------------------
559   
560  Class  Block
561    with description "Just a child's building block, four inches on a side.",
562   
563         !   The parse_name routine below ensures that "take blocks"
564         !   works correctly:
565   
566         parse_name
567         [ i j;
568           for (::)
569           {   j=NextWord();
570               if (j=='block' or 'cube' or 'building' or (self.name)) i++;
571               else
572               {   if (j=='blocks' or 'cubes')
573                   {   parser_action=##PluralFound; i++; }
574                   else return i;
575               }
576           }
577         ],
578   
579         describe
580         [ c d e;
581             d = child(self);
582             while (d~=0 && d ofclass Block)
583             {   c++; e=d; d=child(d); }
584             if (c==0) rfalse;
585             print "^There is a pile of building blocks here, ";
586             while (c>=0)
587             {   print (address) e.name;  ! Sneaky: print the "name" out
588                 if (c>0) print " on ";   ! using its dictionary address
589                 c--; e=parent(e);
590             }
591             ".";
592         ],
593         before
594         [ c;
595           PutOn:
596             if (second ofclass Block)
597             {   if (child(second)~=0 && child(second) ofclass Block)
598                     "There's no room on the top of one cube for two more, side 
599                      by side.";
600             }
601             else
602                 print "(They're really intended 
603                        to be piled on top of each other.)^";
604             c=second; while (c ofclass Block) c=parent(c);
605             if (c~=location or mantelpiece) "Too unsteady a base.";
606         ],
607         after
608         [ c stack;
609           PutOn:
610             stack=noun;
611             while (parent(stack) ofclass Block) { stack=parent(stack); c++; }
612             if (c<2)
613             {   if (Chris has general) rtrue;
614                 rfalse;
615             }
616             if (c==2) "The pile of three cubes is unsteady, but viable.";
617             if (Chris has general)
618             {   Achieved(3);
619                 "^Expertly he keeps the pile of four cubes stable.";
620             }
621             stack=noun;
622             while (parent(stack) ofclass Block)
623             {   c=stack; stack=parent(stack); move c to location; }
624             "The pile of four cubes wobbles, wobbles, steadies... and suddenly 
625              collapses!";
626           Take:
627             stack=child(noun); if (stack==0) rfalse;
628             while (stack~=0)
629             { c=stack; stack=child(stack); move c to location; }
630             "Your pile of cubes is collapsed as a result.";
631         ],
632    has  supporter;
633   
634  Block -> "green cube"
635    with name "green";
636  Block -> "red cube"
637    with name "red";
638  Block -> "yellow cube"
639    with name "yellow";
640  Block -> "blue cube"
641    with name "blue";
642   
643  ! ----------------------------------------------------------------------------


Last updated 23 June 2004. This site is no longer supported; information may be out of date.
Maintained as a historical archive by the Interactive Fiction Technology Foundation. Copyright 1993-2018 IFTF, CC-BY-SA unless otherwise noted.
This page was originally managed by Graham Nelson (graham@gnelson.demon.co.uk) assisted by C Knight.