! >BL The class Block provides for stackable building blocks. ! ! Note that with the "describe" routine missing, the game would still ! correctly describe stacks of blocks: just a little less elegantly. ! ---------------------------------------------------------------------------- Class Block with description "Just a child's building block, four inches on a side.", ! The parse_name routine below ensures that "take blocks" ! works correctly: parse_name [ i j; for (::) { j=NextWord(); if (j=='block' or 'cube' or 'building' or (self.name)) i++; else { if (j=='blocks' or 'cubes') { parser_action=##PluralFound; i++; } else return i; } } ], describe [ c d e; d = child(self); while (d~=0 && d ofclass Block) { c++; e=d; d=child(d); } if (c==0) rfalse; print "^There is a pile of building blocks here, "; while (c>=0) { print (address) e.name; ! Sneaky: print the "name" out if (c>0) print " on "; ! using its dictionary address c--; e=parent(e); } "."; ], before [ c; PutOn: if (second ofclass Block) { if (child(second)~=0 && child(second) ofclass Block) "There's no room on the top of one cube for two more, side by side."; } else print "(They're really intended to be piled on top of each other.)^"; c=second; while (c ofclass Block) c=parent(c); if (c~=location or mantelpiece) "Too unsteady a base."; ], after [ c stack; PutOn: stack=noun; while (parent(stack) ofclass Block) { stack=parent(stack); c++; } if (c<2) { if (Chris has general) rtrue; rfalse; } if (c==2) "The pile of three cubes is unsteady, but viable."; if (Chris has general) { Achieved(3); "^Expertly he keeps the pile of four cubes stable."; } stack=noun; while (parent(stack) ofclass Block) { c=stack; stack=parent(stack); move c to location; } "The pile of four cubes wobbles, wobbles, steadies... and suddenly collapses!"; Take: stack=child(noun); if (stack==0) rfalse; while (stack~=0) { c=stack; stack=child(stack); move c to location; } "Your pile of cubes is collapsed as a result."; ], has supporter; Block -> "green cube" with name "green"; Block -> "red cube" with name "red"; Block -> "yellow cube" with name "yellow"; Block -> "blue cube" with name "blue"; ! ----------------------------------------------------------------------------