! Make your own Inform Adventure! ! Designed for beginners. ! Please read Inform's Designer Manual chapters 1 and 2. ! by Harry M. Hardjono 2/12/98 ! Inform is created by Graham Nelson. Thanks Graham! ! ! This program is filled with spaghetti codes elements: ! Global variables, jumps (gotos), repeating codes, ! stack overflow problems, abrupt terminations, ! and other things. :) ! ! Functions that you should modify: ! 1. [Main] - Easy ! 2. [Help] - Easy ! 3. [StoryBoard] - Hard ! You may need to use Global variables and custom routines. ! Global program variables Array buffer -->60; Array parse -->60; Global n = 0; ! General purpose variable ! Global user variables ! Modify these as you see fit. Global n3 = 0; ! n3 is variable for randomization. Global n4 = 0; ! n4 is the number of visits on node 4. !######################################################### ! [Main] is the first function executed by the program. ! You can modify the message here to display disclaimers. ! Alternatively, just call StoryBoard(). !--------------------------------------------------------- [Main; print "Choose your own Inform Adventure!^"; print "Proceed?^"; if (YesOrNo()) StoryBoard(); ]; !######################################################### ! [YesOrNo] returns true if the answer is "yes". ! It returns false if the answer is "no". !--------------------------------------------------------- [YesOrNo; for (::) { buffer->0 = 60; parse->0 = 1; print "Please type ~yes~ or ~no~> "; read buffer parse; if ((parse-->1 == 'yes') || (parse-->1 == #n$y)) rtrue; if ((parse-->1 == 'no') || (parse-->1 == #n$n)) rfalse; } ]; !######################################################### ! [Action] takes a parameter. You call it like this: ! Action(range); where range is an integer 1-9. ! It returns a digit. It returns 0 when text needs "Refresh" ! ! You don't have to touch this function at all. ! It automatically takes care of program administration ! and command actions. !--------------------------------------------------------- [Action range; for (::) { buffer->0 = 60; parse->0 = 1; n = -1; print "> "; read buffer parse; switch (parse-->1) { #n$0: n = 0; #n$1: if (range >= 1) n=1; else jump OutOfRange; #n$2: if (range >= 2) n=2; else jump OutOfRange; #n$3: if (range >= 3) n=3; else jump OutOfRange; #n$4: if (range >= 4) n=4; else jump OutOfRange; #n$5: if (range >= 5) n=5; else jump OutOfRange; #n$6: if (range >= 6) n=6; else jump OutOfRange; #n$7: if (range >= 7) n=7; else jump OutOfRange; #n$8: if (range >= 8) n=8; else jump OutOfRange; #n$9: if (range >= 9) n=9; else jump OutOfRange; 'help' : Help(); 'restart': StoryBoard(); ! Repeat too often, and the stack overflows. 'restore': restore SuccessRestore; print "Restore failed!^"; 'save' : save SuccessSave; print "Save failed!^"; 'quit' : print "Really quit?^"; ! Elegant programs do not use 'quit'. if (YesOrNo()) quit; 'xyzzy' : print "My head and tail are at my sides. What am I?^"; 'plugh' : print "Coin.^"; default: print "Type ~help~ for info.^"; } jump EndOfAction; .OutOfRange; print "The choices allowed are integers from 1 to ", range, ".^"; jump EndOfAction; .SuccessSave; print "Save successful.^"; jump EndOfAction; .SuccessRestore; print "Restore successful.^"; print "Wait a minute! If restore is successful, then this segment will not be executed, right?^"; jump EndOfAction; .EndOfAction; if (n >= 0) return n; } ]; !######################################################### ! [Help] is the help screen called when the user types ! "help" at the command prompt. You should customize it ! to include relevant information and credits. !--------------------------------------------------------- [Help; print "You can RESTART, SAVE, RESTORE, QUIT, or choose the appropriate action with a single digit number. Type ~0~ to repeat the text.^"; ]; !######################################################### ! [StoryBoard] is the heart of the story. ! As the name implies, this is where the program spends ! most of its execution time. ! ! Make sure labels are consistent. ! You don't need the Introduction, but it's nice to have. ! Make sure all switch cases is terminated by proper jumps ! or the program will terminate abruptly. ! Don't forget to include the default case for ! the redisplaying text on the switch command. ! Action(number) is called for user input where the ! number corresponds with the number of available choices. !--------------------------------------------------------- [StoryBoard; .Introduction; print "Hear ye! Hear ye! You can go to a bunch of nodes!^^"; .Node1Init; .Node1Display; print "This is Node 1.^"; print "You can go to these nodes:^"; print "1. Node 1^"; print "2. Node 2^"; print "3. Node 3^"; print "4. Node 4^"; switch (Action(4)) { 1: jump Node1Init; 2: jump Node2Init; 3: jump Node3Init; 4: jump Node4Init; default: jump Node1Display; } .Node2Init; .Node2Display; print "This is Node 2.^"; print "You can go to these nodes:^"; print "1. Node 2^"; print "2. Node 4^"; switch (Action(2)) { 1: jump Node2Init; 2: jump Node4Init; default: jump Node2Display; } .Node3Init; n3 = random (0,1); ! See Designer Manual for other Inform commands. .Node3Display; print "This is Node 3.^"; print "You can go to these nodes:^"; print "1. Node 1^"; if (n3) print "2. Node 2^"; else print "2. Node 3^"; switch (Action(2)) { 1: jump Node1Init; 2: if (n3) jump Node2Init; else jump Node3Init; default: jump Node3Display; } .Node4Init; n4++; ! Increment counter for each visit .Node4Display; print "This is Node 4.^"; print "Number of visit: ", n4, ".^"; print "You can go to these nodes:^"; print "1. Node 1^"; print "2. Node 3^"; print "3. Node 4^"; switch (Action(3)) { 1: jump Node1Init; 2: jump Node3Init; 3: jump Node4Init; default: jump Node4Display; } ];