'                  *************************************
'                  ***  "Create Your Own Adventure"  ***
'                  ***   from  The ZX81 Pocket Book  ***
'                  ***   by Trevor Toms.   (C) 1981  ***
'                  *************************************
Print At(3,30);"Test Adventure!"
Print
Print "       This mini-test Adventure uses 6 rooms. Room 1 is above  ground,"
Print "    and a lamp can be found there. The objective is to get the bar"
Print "    of gold out of the caves back above ground. The gold is hidden"
Print "    in cave 6 behind a rusty door (cave 4), which will not open."
Print "    Cave 5 contains a pool of oil. Obviously, you must fill the vase"
Print "    with oil and then oil the door! Once this has been done, you can"
Print "    open the door and reach the gold."
Print "       Markers 2 and 3 are used, as usual, to represent 'dark' rooms"
Print "    and lamp off/on respectively. Notice that when the 'lit' lamp"
Print "    (object number 2) is dropped, the lamp is marked as off, which"
Print "    prevents you from lighting the lamp then leaving it somewhere"
Print "    while you wander off."
Print "       Marker 5 is used to indicate when the door has been oiled, and"
Print "    marker 6 is set when the door is open."
Print
Print "                     Press any Key!"
'
Key=Inp(2)
Cls
'
Print At(3,7);"You should notice the way this Test-Adventure is created in"
Print "    order to assist you with producing your own games."
Print "       One item of importance is shown between rooms 1 & 2 and also"
Print "    4 & 6. In the first case there is no tunnel indicated in the"
Print "    room connection table between  rooms 1 & 2. Instead, an entry"
Print "    has been included in the Action table under the appropriate"
Print "    keyword (06). This is because I want to make sure that the"
Print "    'Darkness' marker is set whenever the keyword 'Down' is given"
Print "    from room number 1."
Print "       Similarly, there would be no point in entering a connection"
Print "    between rooms 4 & 6, since the door is supposed to block the path."
Print "    Consequently, an entry is found in the Action table (03 00 A04...)"
Print "    which checks marker 6 whenever 'South' is entered at room 4."
Print "       The rule is:- If you want to place some conditions on the"
Print "    player when he travels from one particular room to another,"
Print "    don't put an entry in the room connection table - use the Action"
Print "    table instead."
Print
Print "                        Press any Key!"
'
Key=Inp(2)
Cls
'
Gosub Initialisation
'
L100:    !  *  *  Describe Current Room Then Await New Command  *  *
Print
If S%(2)=0                      ! test if darkness
  Goto L200
Endif
If C%(2)>0                      ! darkness countdown
  C%(2)=C%(2)-1
Endif
If S%(3)<>0                     ! see if lamp is on
  Goto L200
Endif
Print Chr$(27);"p";
Print "  It is dark! Better get some light or you may be in trouble."
If C%(3)>0                      ! no lamp countdown
  C%(3)=C%(3)-1
Endif
Goto L1000                      ! wait for a command
'
L200:                           ! Describe room
Print Chr$(27);"q";
'
' *********************************************************************
' ********* No computed GOSUB's in GFA Basic. To be rewrited!!! *******
' ************ Room$="Room_Description_"+Mid$(Str$(Room%),2) **********
' ********* GOSUB UPPER$(Room$)'       ! print room description *******
' *********************************************************************
==> -Room_Description_1'   *  *  *  *  *  *  *  *  *  *  *  *  *
Print "  You are standing by a pothole."
Return
'
==> -Room_Description_2'   *  *  *  *  *  *  *  *  *  *  *  *  *
Print "  This is a vast cavern with passages leading"
Print "  East, South and West. A dim passage slopes"
Print "  upwards behind you."
Return
'
==> -Room_Description_3'   *  *  *  *  *  *  *  *  *  *  *  *  *
Print "  This cave contains only a pool of oil."
Return
'
==> -Room_Description_4'   *  *  *  *  *  *  *  *  *  *  *  *  *
Print "  Here is a giant rusty door."
Return
'
==> -Room_Description_5'   *  *  *  *  *  *  *  *  *  *  *  *  *
Print "  You are in the western alcove."
Return
'
==> -Room_Description_6'   *  *  *  *  *  *  *  *  *  *  *  *  *
Print "  You are in the treasure cave."
Return
'
F%=0                              ! reset flag
For X%=1 To O%                    ! print any objects here
If O%(X%)<>Room%
Goto L500
Endif
If F%<>0
Goto L400
Endif
Print
Print "  There is also :-"
F%=1
L400:
Print "   ";O$(X%)
L500:
Next X%
'
L1000:    !   *  *  *  *  *  Await New Command   *  *  *  *  *
T%=1                              ! first check automatics
Goto L2000
'
L1100: !  *  Await New Command But Conditional Table Not Scanned First  *
If C%(1)>0 Then                   ! countdown every command
C%(1)=C%(1)-1
Endif
If C%(4)>0 Then                   ! countdown every command
C%(4)=C%(4)-1
Endif
Print
Line Input "  What now :- ";Y$    ! input command
Y$=Upper$(Y$)
Cls
Print
Print "  What now :- ";Y$
Y%=0                              ! command scan
P$(2)="00"
For W%=1 To 2                     ! get up to two keywords
'
L1210:
Gosub L6000
If Y%>=Len(Y$)                  ! (check if all scanned
Goto L1300
Endif
If P$(W%)="00"                  ! was the keyword found
Goto L1210
Endif
Next W%                           ! next keyword
'
L1300:
If P$(1)<>"00" Then               ! was there at least one word?
Goto L1600
Endif
Print "  Pardon?"                 ! print this if nothing found
Goto L100                         ! try again !!!
'
L1600:      !  *  *  *  *  *  Check For Movement  *  *  *  *  *
Z%=1                              ! now scan movement table
'
L1620:
T$=Mid$(M$(Room%),Z%,2)           ! get matching keyword
If T$="00" Then                   ! check if end of entry
Goto L1900
Endif
If T$<>P$(1) Then                 ! see if it matches word 1
Goto L1700
Endif
Room%=Val(Mid$(M$(Room%),Z%+2,2))
Goto L100                         ! continue in new room
'
L1700:
Z%=Z%+4                           ! try next match
Goto L1620
'
L1900:
T%=0                              ! set "Action Table" flag
==>  Match%=0'                            (no match found yet
'
==> -L2000'  *  *  *  *  *   Check For Conditionals   *  *  *  *  *
==>  Cp%=0'                               (table subscript number
'
==> -L2100
Cp%=Cp%+1
==>  IF T%=0 THEN GOTO L2300'             (see if scanning Action
==>  E$=C$(Cp%)'                          (get from Conditionals
Goto L2600
'
==> -L2300
==>  IF Cp%<=A% THEN GOTO L2400'           (have all been scanned?
==>  IF Match%<>0 THEN GOTO L1000'        (has a match been found?
==>  PRINT "  You can't";'               (else print this massage
==>  IF VAL(P$(1))<13 THEN PRINT " go that way";
Print "."
==>  GOTO L100'                          (try again
'
==> -L2400
==>  IF MID$(A$(Cp%),1,2)<>P$(1) THEN GOTO L2100' (check if it matches key 1
==>  Y$= MID$(A$(Cp%),3,2)'               (get keycode 2
==>  IF Y$<>"00" AND Y$<>P$(2) THEN GOTO L2100
==>  E$= MID$(A$(Cp%),5)'                 (get conditions/actions
'
==> -L2600'  *  *  *  *  *  *   Conditions   *  *  *  *  *  *
==>  E%=1'                                (now scan further conditions
'
==> -L2700
==>  IF MID$(E$,E%,1)="." THEN GOTO L3000'(full-stop ends conditions
==>  N%= VAL( MID$(E$,E%+1,2))'            (get parameter
Condition$="Condition_"+Mid$(E$,E%,1)
==>  GOSUB UPPER$(Condition$)'           (evaluate if true/false
==>  IF NOT Ok% THEN GOTO L2100
E%=E%+3
Goto L2700
'
==> -Condition_A'  *  *  nn is the Current Room Number   *  *  *
Ok%=(N%=Room%)
Return
'
==> -Condition_B'  *  Object nn is Here (or Being Carried)  *  *
Ok%=(O%(N%)=Room% Or O%(N%)<0)
Return
'
==> -Condition_C'  * Object is not Here (or Being Carried)  *  *
Ok%=(O%(N%)<>Room% And O%(N%)>=0)
Return
'
==> -Condition_D'  *  *    Object nn is Being Carried    *  *  *
Ok%=(O%(N%)<0)
Return
'
==> -Condition_E'  *  *  *  *   Marker S(nn) is Set   *  *  *  *
Ok%=(S%(N%)=1)
Return
'
==> -Condition_F'  *  *  *  *  Marker S(nn) is Not Set   *  *  *
Ok%=(S%(N%)=0)
Return
'
==> -Condition_G'  *  *   Countdown C(nn) Has Reached Value 1  *
Ok%=(C%(N%)=1)
Return
'
==> -Condition_H'  *  Random Number From 1-99 is Less Than nn  *
Ok%=(Rnd(99)+1<N%)
Return
'
==> -L3000'  *  *  *  *  *  *  *  Actions  *  *  *  *  *  *  *  *
==>  Match%=1'                             (now perform Actions
E%=E%+1
'
==> -L3100
==>  IF MID$(E$,E%,1)="." THEN GOTO L2100' (all done?
==>  IF MID$(E$,E%+1,1)<>"." THEN N%= VAL( MID$(E$,E%+1,2))' (get any parameter
==>  Break%=0'                            (return line number
Actions$="Action_"+Mid$(E$,E%,1)
==>  GOSUB UPPER$(Actions$)'             (perform Action
Break$="L"+Mid$(Str$(Break%),2)
==>  IF Break%<>0 THEN GOTO Break$'       (goto relevant line
==>  E%=E%+3'                              next Action
Goto L3100
'
==> -Action_A'   * * *  Print List of Objects Caried * * *
Print
Print "  You are holding:-"
F%=1
For X%=1 To O%
==>  IF O%(X%)>=0 THEN GOTO L4070
Print "   ";O$(X%)
F%=0
==> -L4070
Next X%
==>  IF F%<>0 THEN PRINT "   NOTHING!"
Break%=100
Return
'
==> -Action_B'   *  *  *  *   Carry Object nn   *  *  *  *
==>  IF S%(1)<5 THEN GOTO L4140
Print "  You can not carry more."
==> -L4120
Break%=100
Return
==> -L4140
==>  IF O%(N%)=-1 THEN GOTO L4180
O%(N%)=-1
S%(1)=S%(1)+1
Return
==> -L4180
Print "  You already have it."
Goto L4120
'
==> -Action_C'  *  *  *  *   Put Down Object nn   *  *  *  *
==>  IF O%(N%)=-1 THEN GOTO L4240
Print "  You don't have ";O$(N%)
Break%=100
Return
'
==> -L4240
O%(N%)=Room%
S%(1)=S%(1)-1
Return
'
==> -Action_D'  *  *  *   Display Text Message nn   *  *  *
Print
Action_messages$="Action_message_"+Mid$(Str$(N%),2)
==>  GOSUB UPPER$(Action_Messages$)
Return
'
==> -Action_E'  *  *  *  *   Set Marker S(nn)   *  *  *  *
S%(N%)=1
Return
'
==> -Action_F'  *  *  *   *   Unset Marker S(nn)   *   *  *  *
S%(N%)=0
Return
'
==> -Action_G'  *  *    Set Countdown C(nn) to Value mm   *  *
C%(N%)=Val(Mid$(E$,E%+3,2))
E%=E%+2
Return
'
==> -Action_H'  *  *  *    Swap Objects nn and nn+1    *  *  *
Swap O%(N%),O%(N%+1)
Return
'
==> -Action_I'  *   Set Object nn into Current Room Number   *
O%(N%)=Room%
Return
'
==> -Action_J'  *   *   Set Object nn Room Number to 00   *  *
==>  IF O%(N%)<0 THEN S%(1)=S%(1)-1
O%(N%)=0
Return
'
==> -Action_K'  *  *   Set Current Room Number to nn   *  *  *
==>  Room%=N%'    *  *   (i.e. Forced Move to Room nn)   *  *  *
Return
'
==> -Action_L'  *  *   Print "OKAY" and Await a New Command  *
Print "  OKAY."
'
==> -Action_M'  *  *  *  *    Await a New Command   *  *  *  *
Break%=1000
Return
'
==> -Action_N'  *  Await a New Command, but the Conditional  *
==>  Break%=1100'*  Table is not Scanned First    *  *  *  *  *
Return
'
==> -Action_O'  *  Describe Current Room Then Await New Command.
Break%=100
Return
'
==> -Action_P'  *  *  *  *  *  Abandon the Game   *  *  *  *  *
Input "  Are you sure? ";W$
W$=Upper$(W$)
==>  IF CHR$( ASC(W$))<>"Y" THEN GOTO Action_O
'
==> -Action_Q'  *  *  *  *  *    Stop the Game    *  *  *  *  *
End
'
==> -Action_R'  *  *  *  *  *  *   Load Data   *  *  *  *  *  *
Gosub Data_name
Open "I",#1,N$
Input #1,O%
Input #1,Room%
For X%=1 To O%
Input #1,O%(X%)
Next X%
For X%=1 To 10
Input #1,S%(X%)
Next X%
For X%=1 To 5
Input #1,C%(X%)
Next X%
Close
Break%=100
Cls
Return
'
==> -Action_S'  *  *  *  *  *  *   Save Data   *  *  *  *  *  *
Gosub Data_name
Open "O",#1,N$
Print #1,O%
Print #1,Room%
For X%=1 To O%
Print #1,O%(X%)
Next X%
For X%=1 To 10
Print #1,S%(X%)
Next X%
For X%=1 To 5
Print #1,C%(X%)
Next X%
Close
Break%=100
Cls
Return
'
==> -Data_Name'  *  *  *  *   Input Data-File Name   *  *  *  *
Cls
Print
Files "*.DAT"
Print
Print
==>   IF MID$(E$,E%,1)="R" THEN E$="LOAD " ELSE E$="SAVE "
Print
==>   INPUT "       Input Name of Data File to ";E$;" (no extension!): ";N$
N$=N$+".dat"
Print
Return
'
==> -L6000'  *  *  *  *  *  *   Remove word   *  *  *  *  *  *
==>  W$="    "'                          (first four letters
==>  P$(W%)="00"'                         (set "not found" reply
==>  GOSUB L6600'                        (find first character
==>  IF Finish%<>0 THEN RETURN '          (test if end of command
==>  FOR Q%=1 TO 4'                       (get four letters
==>  MID$ (W$,Q%,1)= MID$(Y$,Y%,1)
==>  GOSUB L6500'                        (check if word end
==>  IF Finish%<>0 THEN EXIT TO L6100
Next Q%
==> -L6080
==>  GOSUB L6500'                        (look for end of word
==>  IF Finish%=0 THEN GOTO L6080
==> -L6100
==>  IF W$="    " THEN RETURN '          (no word entered
==>  FOR Q%=1 TO V%'                       (scan vocabulary table
==>  IF W$= MID$(V$(Q%),3) THEN EXIT TO L6200
Next Q%
==>  RETURN '                            (not found in table
'
==> -L6200
==>  P$(W%)= MID$(V$(Q%),1,2)'             (get keyword code number
Return
'
==> -L6500
==>  Y%=Y%+1'                              (check for end of wors
Finish%=(Y%>Len(Y$))
==>  IF Finish%<>0 THEN RETURN
==>  Finish%=( MID$(Y$,Y%,1)=" ")'         (don't forget the space
Return
'
==> -L6600
==>  Y%=Y%+1'                              (look for end of word
Finish%=(Y%>Len(Y$))
==>  IF Finish%<>0 THEN RETURN
==>  IF MID$(Y$,Y%,1)=" " THEN GOTO L6600' (dont forget the space
Return
'
==> -Action_Message_1'  *  *  *  *  *  *  *  *  *  *  *  *  *  *
Print "  The door is shut fast."
Return
'
==> -Action_Message_2'  *  *  *  *  *  *  *  *  *  *  *  *  *  *
Print "  The door is open."
Return
'
==> -Action_Message_3'  *  *  *  *  *  *  *  *  *  *  *  *  *  *
Print "  It is already alight."
Return
'
==> -Action_Message_4'  *  *  *  *  *  *  *  *  *  *  *  *  *  *
Print "  With a grunt you manage to open the door."
Return
'
==> -Action_Message_5'  *  *  *  *  *  *  *  *  *  *  *  *  *  *
Print "  It is too stiff for you to open."
Return
'
==> -Action_Message_6'  *  *  *  *  *  *  *  *  *  *  *  *  *  *
Print "  You did it. Well done."
Return
'
==> -Action_Message_7'  *  *  *  *  *  *  *  *  *  *  *  *  *  *
Print "  You can't get past the door."
Return
'
==> -Action_Message_8'  *  *  *  *  *  *  *  *  *  *  *  *  *  *
Print "  It is empty. Why not fill it with some liquid!"
Return
'
==> -Action_Message_9'  *  *  *  *  *  *  *  *  *  *  *  *  *  *
Print "  You see nothing special."
Return
'
==> -Action_Message_10'  *  *  *  *  *  *  *  *  *  *  *  *  *  *
Print "  Oil can loosen rusty hinges."
Return
'
==> -Action_Message_11'  *  *  *  *  *  *  *  *  *  *  *  *  *  *
Print "  Use your brains, 'wise' guy."
Return
'
'
==> -Initialisation'  *  *  *  *  *  *  *  *  *  *  *  *  * *  *
'
Room%=1
==>   O%=5:V%=29:R%=6:C%=3:A%=29
Dim S%(10),C%(5),P$(2)
Dim O%(O%),O$(O%),V$(V%),M$(R%),C$(C%+1),A$(A%)
For X%=1 To O%
Read O%(X%),O$(X%)
Next X%
For X%=1 To V%
Read V$(X%)
Next X%
For X%=1 To R%
Read M$(X%)
Next X%
For X%=1 To C%
Read C$(X%)
Next X%
C$(C%+1)=".N."
For X%=1 To A%
Read A$(X%)
Next X%
Return
'
'  Objects     *  *  *  *  *  *  *  *  *  *  *  *  *
Data 1,"a Lamp"
Data 0,"a lighted Lamp"
Data 5,"a Ming Vase"
Data 0,"a Vase of Oil"
Data 6,"a Bar of Gold"
'  Vocabulary   *  *  *  *  *  *  *  *  *  *  *  *  *
Data "01N   ","01NORT"
Data "02E   ","02EAST"
Data "03S   ","03SOUT"
Data "04W   ","04WEST"
Data "05U   ","05UP  "
Data "06D   ","06DOWN"
Data "13TAKE","14DROP"
Data "15VASE","16GOLD"
Data "17DOOR","18OPEN"
Data "19LAMP","20LIGH"
Data "21FILL","22OIL "
Data "23INVE","24QUIT","25LOOK"
Data "26LOAD","27SAVE"
Data "28EXAM","29HELP"
'  Room Connection Table   *  *  *  *  *  *  *  *  *
Data "00","02030304040500"
Data "040200","010200"
Data "020200","010400"
'  Conditional Table
Data "A04E06.D02N."'        (room 4 and marker 6 is set-the door is open
Data "A04F06.D01N."'        (room 4 and  M6 is not set -the door is shut
Data "A01D05.D06Q."'        (room carrying object 5-got out with the gold
'  Keyword Action Table   *  *  *  *  *  *  *  *  *  *
Data "1319B01.B01L."'       (take lamp - object 01
Data "1419B01.C01L."'       (drop lamp
Data "1319B02.B02E03L."'    (take lit lamp-object 02-set lamp marker 3
Data "1419B02.C02F03L."'    (drop lit lamp-unsets lamp marker 3
Data "2000D01.H01E03L."'    (light lamp-swaps objects 1&2,sets lamp M3
Data "2000B02.D03M."'       (light lamp-object 2 already here,displ 03"
Data "0600A01.E02K02O."'    (DOWN when at room 1,so set  "dark" marker
'                           (2 and continue at room number 2
Data "0500A02.F02K01O."'    (UP when at room 2, so unset "dark" marker
'                           (2 and continue at room number 1
Data "1315B03.B03L."'       (take vase
Data "1415B03.C03L."'       (drop vase
Data "1316B05.B05L."'       (take gold
Data "1416B05.C05L."'       (drop gold
Data "2100B03A03.H03L."'    (fill vase-must have object 3 and be in
'                           (room 3-swaps objects 3 & 4
Data "2200A04D04.H03E05L."' (oil door - must have object 4(a full vase)
'                           (and be in room 4 - "empties" bottle and
'                           (sets mark 5
Data "1800A04E05.D04E06M."' (open door - must be oiled i.e. marker 5
'                           (must be set and at room 4, Sets M6.
Data "1800A04F05.D05M."'    (open door when not oiled. Displ. mess. 5.
Data "0300A04F06.D07M."'    (SOUTH when marker 6 not set - i.e. door
'                           (not open.
Data "0300A04E06.K06O."'    (SOUTH at door when open (marker 6 is set)
'                           (Continues at room 6.
Data "2815B03.D08N."'       (examine vase-object here/displ text no. 8
Data "1315B04.B04L."'       (take full vase
Data "1415B04.C04L."'       (drop full vase
Data "2800C03.D09N."'       (examine anything else/display  text no. 9
Data "2900A03.D10N."'       (help in room 3/ display text no. 10
Data "2900.D11N."'          (help anywhere else/display text no. 11
Data "2300.A."'             (give inventory
Data "2400.P."'             (quit
Data "2500.O."'             (look to see where we are
Data "2600.R."'             (load game data
Data "2700.S."'             (save game data
