home *** CD-ROM | disk | FTP | other *** search
/ PC Games 2 the Maxx / pcgames.zip / pcgames / MISC / ADVTUTR.ZIP / ADVENT3.DOC < prev    next >
Encoding:
Text File  |  1986-02-23  |  5.3 KB  |  124 lines

  1.  
  2.                     How to Write an Adventure
  3.              
  4. The Display Screen
  5.     
  6.     After you have loaded the arrays, you are ready to begin working on the 
  7. Display screen. This is the next major part of the adventure, and one of the 
  8. most inportant parts. The display, as stated earlier, can fall into one of two 
  9. general types...  
  10.     The Block display, made popular by Scott Adams, and used in a great many 
  11. adventures.  
  12.     The Interactive ficition display which is a narative of the situation.  
  13.     
  14.     Since the interactive fiction coding can become very tedious, we'll look 
  15. at the block display.  
  16.     
  17.     The first thing to do is display WHERE the adventurer is. That is done 
  18. very simply. I usually use the variable "L" to stand for the location where 
  19. the adventurer currently is. This is usually set to 1 in the initialization 
  20. sequence (back when you are loading the arrays). If you recall, we wrote all 
  21. of our room descriptions to fit into array ROOM$(X). So, to display where we 
  22. are, all we have to do is: 
  23.     
  24.          1000 PRINT "You see: ";ROOM$(L)
  25.     
  26.     Pretty simple. I think we all grasp the simplicity and elegance of the 
  27. technique.  
  28.     Next, we must display VISABLE OBJECTS. This should be quite simple. All 
  29. you have to do is compare the L(X) location of all your objects with the value 
  30. of L (the current location) and print any matches. That code is pretty simple 
  31. too.  It would look like this: 
  32.     
  33.          1010 PRINT"VISABLE OBJECTS:";:FOR X=1 TO OBJECTS:IF L(X)=L THEN
  34.                    PRINT OBJECT$(X)
  35.          1020 NEXT X
  36.  
  37.      Simple, and it will work... except
  38.     it
  39.     prints
  40.     the 
  41.     objects
  42.     in
  43.     a
  44.     column
  45.     like
  46.     this.
  47.          Hmmmmmm. Not too cool. Well, let's see what we can do to string the 
  48. objects out in neat lines, and while we are at it, put commas between the 
  49. items. While we're at it, it would also be nice if, given the possibility that 
  50. there are no visable objects, the program would print "NOTHING", so the 
  51. display doesn't look dumb. WOW! A mouthful, huh? Really it's very easy.  
  52.     
  53.          1010 Z=0:PRINT"VISABLE OBJECTS: ";:FOR X=1 TO OBJECTS:IF L(X)=L THEN
  54.                    PRINT OBJECT$(X);", ";:Z=Z+1
  55.          1020 NEXT:IF Z=0 THEN PRINT"NOTHING"
  56.     
  57.     All well and good... except. NOW, when we print the list, some of the 
  58. objects word wrap from one line to the next, and we have no idea where they 
  59. will be broken up. There is also a comma trailing the end of the list that 
  60. looks tacky. These problems are very easy to solve using two BASIC functions. 
  61. POS(0) and LEN(A$).
  62.     POS(0) returns the POSition of the cursor in the line. LEN(A$) returns the 
  63. length of A$. Using these two functions it is easy to first check the LENgth 
  64. of OBJECT$(X) and compare it with the POSition of the cursor. If it will fit, 
  65. print it. If not, print, then print it. I also check to see that there would 
  66. be space for the comma by comparing POS(0) with LEN(object$(X))+3. I am 
  67. assuming a screen width of 80 characters. If you are dealing with another 
  68. width, change the 79 to one less than your screen width. Note also how we
  69. handle getting rid of that darn trailing comma:
  70.     
  71.          1010 Z=0:PRINT"VISABLE OBJECTS:";
  72.          1020 FOR X=1 TO OBJECTS:IF L(X)<>L THEN 1060
  73.          1030 IF Z<>0 THEN PRINT", ";
  74.          1040 IF POS(0)+LEN(OBJECT$(X))+3>79 THEN PRINT
  75.          1050 PRINT OBJECT$(X);
  76.          1060 NEXT X:IF Z=0 THEN PRINT"NOTHING"
  77.     
  78.     SPECIAL NOTE TO C-64 PEOPLE: The POS command is NOT supported in C-64 
  79. BASIC. This can, however be programmed around. Change YOUR coding to the 
  80. following:
  81.           1030 IF Z<>0 THEN PRINT", ";:HL$=HL$+", "
  82.           1040 IF LEN(HL$)+LEN(OBJECT$(X))+3>39 THEN PRINT:HL$=""
  83.           1050 PRINT OBJECT$(X);:HL$=HL$+OBJECT$(X)
  84.           1060 NEXT X:HL$="":IF Z=0 THEN PRINT"NOTHING"
  85.  
  86.      The length of HL$ is used in the same way the POS command is used... to 
  87. determine just how far over we have printed. Use this coding technique anywhere 
  88. in this tutoral that the POS command is used.
  89.  
  90.      OK. So far, terrific. Lastly, we need to print the OBVIOUS EXITS... the 
  91. directions in which the adventurer can go. Remember, we stored those as 
  92. numbers in the D(X,Y) array. It is therefore easy to print that message. 
  93. Watch:
  94.          1070 PRINT"YOU CAN GO: ";:FOR X=1 TO 6
  95.          1080 IF D(L,X)=0 THEN 1150
  96.          1090 IF X=1 THEN PRINT"NORTH ";
  97.          1100 IF X=2 THEN PRINT"EAST ";
  98.          1110 IF X=3 THEN PRINT"SOUTH ";
  99.          1120 IF X=4 THEN PRINT"WEST ";
  100.          1130 IF X=5 THEN PRINT"UP ";
  101.          1140 IF X=6 THEN PRINT"DOWN ";
  102.          1150 NEXT X:PRINT
  103.     
  104.     The final print statement clears the append of the ";" at the end of the 
  105. last line printed.
  106.     Now, we have printed the display screen. The only thing left to do is 
  107. print a row of some character or the other under it to show that that is all 
  108. there is on the display. I tend to like the minus sign, so, simply put, add:
  109.     
  110.          1160 PRINT"-------------------------------------------------------"
  111.     
  112.     or however wide your display is.
  113.     
  114.     OK! So now the adventurer knows that the score is!!!!!! Next we have to 
  115. write the command parser, so he'll be able to tell the program what HE 
  116. wants... and that is the subject of chapter 4!
  117.     
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.