Author Topic: Modern-setting Text Adventure  (Read 3926 times)

0 Members and 1 Guest are viewing this topic.

Offline johannhowitzer

  • Forum Regular
  • Posts: 118
    • View Profile
Modern-setting Text Adventure
« on: July 11, 2021, 04:03:42 am »
Way back in my teenage days on an IBM 286 desktop computer, I encountered a program I didn't understand, called QBasic.  We also had an old Commodore 64 and some random BASIC programming books I'd been curious about, and so at some point I tried making a text adventure.  This was a genre of game I knew I could tackle, and being super into game design since I was in preschool, making mario levels on graph paper, me and my childhood friend Jason established our own "game company," selling 3.5 floppies to our friends at church of little games we made, for a dollar or two.

The two biggest super-triple-A-battery releases we had were a lights-out clone called Temporal Archer (you've got a field of soldiers in front of your castle, you're a time traveler, and your arrows have blast radius?  Also the soldiers come back to life if you hit them when they're dead??), and a text adventure about robots I named Spike and Rocky, after two robots I liked to draw at the time.  Spike was made of cubes and rectangles, while Rocky was made of spheres and cylinders.

The code was super spaghetti, the sort you'd see on Commodore 64 with a tangled mess of line numbers and GOTO statements, and the text adventure mostly ended up being cool drawings I was always making of levels, in a notebook I carried around.


Well, as the only game I've really sunk any time into these days is my Big Secret Project(tm), as you can imagine, I started thinking about what other little projects I could work on, stuff I could actually share with the QB64 community.  So I've dusted off what I can remember of that old text adventure, scrapped almost all of the concepts in favor of stuff I like more nowadays, and actually coded it fairly well.

The prologue is done, and I've got another chapter all mapped out, with a few more concepts waiting to be worked on.  The challenge of course in a text adventure is to make it comprehensible to the player without being able to actually see anything, yet still challenging and engaging, and descriptive enough to be immersive, but not enough to be overwhelmingly wordy.

Here you go!  It's pretty short, however the chapter I'm now working on is over five times as large.  Just see what you think, leave gameplay concerns / places you got stuck / etc in the thread - if you want to try this, just don't read the thread beforehand.  And as is the case with text adventure code, reading the code before playing will be very spoilery.

Code: QB64: [Select]
  1.  
  2. screen 12 ' 80 characters wide
  3.  
  4. const true = -1
  5. const false = 0
  6.  
  7. q = chr$(34) ' *** Double quote
  8.  
  9. color 15, 0
  10. cls , 0
  11.  
  12.  
  13.  
  14.  
  15. ' ===== Flags =====
  16.  
  17. ' ----- Standard flag values -----
  18.  
  19. const no_item   = 0 ' Most items will start in this state
  20. const have_item = 1
  21. const used_item = 2 ' Generally used when an item is no longer in the inventory, and can't be re-acquired
  22.  
  23. const door_closed = 0
  24. const door_open   = 1
  25.  
  26. ' ----- Inventory items -----
  27.  
  28. ' Listed first as they will be listed in constant-numerical order when "inv" is typed
  29.  
  30. const i_sh_deadflashlight = 1 ' No batteries
  31. const i_sh_flashlight     = 2 ' Has batteries
  32.  
  33. const i_sh_batteries      = 4
  34.  
  35. const i_sh_drawerkey      = 6 ' When used_item, the drawer has been opened
  36. const i_sh_keyring        = 7 ' Car keys
  37. const i_sh_papers         = 8 ' Papers containing addresses of three destinations
  38.  
  39. const total_items         = 11
  40.  
  41. ' ----- Non-inventory flags -----
  42.  
  43. ' Things such as doors, lights, any state the game needs to keep track of
  44.  
  45. const f_sh_drawertop    = 12 ' Number of times drawer has been opened
  46. const f_sh_drawermiddle = 13 ' Middle drawer state
  47. const f_sh_bonk         = 14 ' Whether the player has run into the bedroom door
  48. const f_sh_doorbedroom  = 15 ' Bedroom door state
  49. const f_sh_doorfront    = 16 ' Front door state
  50. const f_sh_clearingseen = 17 ' Player has noticed the clearing in the grass
  51.  
  52. const total_flags          = 17
  53.  
  54. dim shared flag(total_flags) as byte ' All flag states stored here
  55. dim shared item_name$(total_items)   ' Names of items, for inventory display
  56.  
  57. item_name$(i_sh_deadflashlight) = "Flashlight without power"
  58. item_name$(i_sh_flashlight)     = "Flashlight"
  59. item_name$(i_sh_batteries)      = "Pack of D batteries"
  60. item_name$(i_sh_drawerkey)      = "Small aluminum key"
  61. item_name$(i_sh_keyring)        = "Keyring with red bell fob"
  62. item_name$(i_sh_papers)      = "Assorted papers"
  63.  
  64. ' ----- Location references -----
  65.  
  66. ' On title screen, player can choose new or resume.
  67. ' If resume, loaded file will contain this location value, and the flag() array.
  68.  
  69. const loc_home_bedroom   = 1
  70. const loc_home_hall      = 2
  71. const loc_home_table     = 3
  72. const loc_home_machinery = 4
  73. const loc_home_path      = 5
  74. const loc_home_road      = 6
  75. const loc_home_clearing  = 7
  76. const loc_home_car       = 8
  77.  
  78. dim shared location as integer ' Current location reference value
  79.  
  80. ' ----- Input handling -----
  81.  
  82. dim shared i$      ' Player input
  83. dim shared verb$   ' Verb separated
  84. dim shared object$ ' Object of verb
  85.  
  86. ' *** Title menu here should allow loading a saved game
  87.  
  88. goto home_bedroom
  89.  
  90. ' *** Following branch is used when finished loading
  91.  
  92.    case loc_home_bedroom:   goto home_bedroom
  93.    case loc_home_hall:      goto home_hall
  94.    case loc_home_table:     goto home_table
  95.    case loc_home_machinery: goto home_machinery
  96.    case loc_home_path:      goto home_path
  97.    case loc_home_road:      goto home_road
  98.    case loc_home_clearing:  goto home_clearing
  99.    case loc_home_car:       goto home_car
  100.  
  101.  
  102.  
  103.  
  104.  
  105. ' --------------------------------------------------
  106. ' ===== THE SCENT OF ADVENTURE: The Safe House =====
  107. ' --------------------------------------------------
  108.  
  109.  
  110.  
  111. home_bedroom:
  112.  
  113. ?"You wake up in bed.  This is surprising to no one.  It is also not surprising"
  114. ?"that this is the beginning of the game; it's almost like this was written with"
  115. ?"very little planning.  You stand up slowly, it feels like forever since you"
  116. ?"were awake."
  117. ?
  118. ?"You feel like typing 'look' would give you more information about this room."
  119.  
  120. location = loc_home_bedroom
  121.    call get_input
  122.  
  123.    select case verb$
  124.       case "look"
  125.          select case object$
  126.             case ""
  127.                ?"You are in a simple bedroom, with a small bed against the east wall."
  128.                ?"Bright sunlight is visible through the south window, above a chest of drawers."
  129.                ?"There is a door to the north."
  130.                ?
  131.                ?"You ponder the four compass directions.  North, east, south, west.  Each one"
  132.                ?"has its own starting letter!  This is convenient, since moving around won't"
  133.                ?"require you to type the whole word.  Just one letter will do."
  134.                ?
  135.                ?"Oh, also, you can type a word after 'look,' to examine something more closely."
  136.  
  137.             case "bed"
  138.                if flag(i_sh_drawerkey) = no_item then
  139.                   ?"A white-painted four poster bed with a blue coverlet.  It's set about a foot"
  140.                   ?"above the floor-- oh!  The sunlight is glinting off something on the floor"
  141.                   ?"next to the bed.  It's a small aluminum key."
  142.                else
  143.                   ?"A white-painted four poster bed with a blue coverlet.  It's set about a foot"
  144.                   ?"above the floor."
  145.                end if
  146.  
  147.             case "door"
  148.                ?"It's made of sturdy-looking wood, but isn't painted or varnished."
  149.  
  150.             case "window"
  151.                ?"A single-shutter affair, unpainted, with no curtains."
  152.                ?"The glass is glass-colored."
  153.  
  154.             case "chest"
  155.                ?"The chest is painted light blue and has three drawers."
  156.                ?"The bottom one has a keyhole between the handles."
  157.  
  158.             case "keyhole"
  159.                ?"Seems to be made of aluminum."
  160.          end select
  161.  
  162.       case "get"
  163.          select case object$
  164.             case "batteries"
  165.                if flag(i_sh_batteries) = no_item and flag(f_sh_drawermiddle) = true then
  166.                   ?"You've got the batteries.  To see your items, type 'inv.'  Why 'inv'?"
  167.                   ?"It's an abbreviation.  It stands for 'investigate.'  You use it to"
  168.                   ?"'investigate' your inventory."
  169.                   flag(i_sh_batteries) = have_item
  170.                end if
  171.  
  172.             case "key"
  173.                if flag(i_sh_drawerkey) = no_item then
  174.                   ?"You've got the key.  To see your items, type 'inv.'  Why 'inv'?"
  175.                   ?"It's an abbreviation.  It stands for 'inventive.'  You've got to be 'inventive'"
  176.                   ?"when deciding how to use your inventory."
  177.                   flag(i_sh_drawerkey) = have_item
  178.                end if
  179.          end select
  180.  
  181.       case "open"
  182.          select case object$
  183.             case "drawer"
  184.                ?"There are so many drawers here!  Top, middle, bottom."
  185.                ?"Why, there is even one more than two drawers here!"
  186.  
  187.             case "top"
  188.                if flag(f_sh_drawertop) < 4 then
  189.                   ?"It slides open easily, but there's nothing inside, so you close it again."
  190.                   flag(f_sh_drawertop) = flag(f_sh_drawertop) + 1
  191.                else
  192.                   ?"It slides open easily, but there's NOTHING INSIDE SO YOU CLOSE IT AGAIN.  Gosh."
  193.                end if
  194.  
  195.             case "middle"
  196.                if flag(f_sh_drawermiddle) = false then
  197.                   ?"It slides open easily.  There is a pack of D batteries inside, enough to power"
  198.                   ?"a large flashlight.  You can carry a lot of stuff, why not get these?"
  199.                   ?"'Get.'  Hey, that's another thing you can type!"
  200.                   flag(f_sh_drawermiddle) = true
  201.                else
  202.                   ?"That drawer is already open."
  203.                end if
  204.  
  205.             case "bottom"
  206.                if flag(i_sh_drawerkey) = no_item then
  207.                   ?"It won't open.  If you do find the key, just try opening the drawer again,"
  208.                   ?"unlocking is part of opening a locked thing."
  209.                elseif flag(i_sh_drawerkey) = have_item then
  210.                   ?"The key fits awkwardly into the chintzy lock, which takes some fiddling to pop"
  211.                   ?"open.  The drawer slides open, but there's nothing inside.  Is this the true"
  212.                   ?"meaning of 'tutorial'?"
  213.                   ?
  214.                   ?"You close the drawer with the key inside, then lock it again, just to screw"
  215.                   ?"with the next guy.  Though I'm not sure how you even did that."
  216.                   flag(i_sh_drawerkey) = used_item
  217.                elseif flag(i_sh_drawerkey) = used_item then
  218.                   ?"You already locked the key inside, remember?"
  219.                end if
  220.  
  221.             case "door"
  222.                if flag(f_sh_doorbedroom) = door_open then
  223.                   ?"It's already open."
  224.                elseif flag(f_sh_doorbedroom) = door_closed and flag(f_sh_bonk) = false then
  225.                   ?"You turn the handle and pull the door open.  It swings soundlessly."
  226.                   ?"The scent of adventure wafts into the room."
  227.                   flag(f_sh_doorbedroom) = door_open
  228.                elseif flag(f_sh_doorbedroom) = door_closed and flag(f_sh_bonk) = true then
  229.                   ?"You turn the handle and pull the door open.  It protests vehemently, hinges"
  230.                   ?"creaking loudly and several long splinters snapping off.  But at least it's"
  231.                   ?"open.  The scent of adventure wafts into the room."
  232.                   flag(f_sh_doorbedroom) = door_open
  233.                end if
  234.          end select
  235.  
  236.       case "north"
  237.          if flag(f_sh_doorbedroom) = door_closed then
  238.             ?"I think the door felt that more than you did.  Doors tend to turn into doorways"
  239.             ?"when you do something to them... I think it starts with 'O'?"
  240.             ?"(And you should be specific about what you want to 'open,' too.)"
  241.             flag(f_sh_bonk) = true
  242.          elseif flag(f_sh_doorbedroom) = door_open then
  243.             ?"You step out into the hall.  The morning sunlight shining through the east"
  244.             ?"window reveals quite a bit of dust in the air.  You continue to the west end"
  245.             ?"of the hallway."
  246.             goto home_hall
  247.          end if
  248.  
  249.    end select
  250.  
  251.  
  252.  
  253. home_hall:
  254.  
  255. location = loc_home_hall
  256.    call get_input
  257.  
  258.    select case verb$
  259.       case "look"
  260.          select case object$
  261.             case ""
  262.                ?"You're in a narrow east-west hallway.  The sun is casting a shaft of blinding"
  263.                ?"light through the east window, and the floor is coated in a thin layer of dust,"
  264.                ?"which kicks up into the air as you move.  Through the north door you can see"
  265.                ?"a room with a large table; the south door reveals a dark room almost completely"
  266.                ?"occupied with some intimidating machinery.  East leads back to the bedroom."
  267.                ?"The door at the west end, which is much older-looking than the others,"
  268.                if flag(f_sh_doorfront) = door_closed then ?"is closed."
  269.                if flag(f_sh_doorfront) = door_open then ?"is open."
  270.  
  271.             case "floor"
  272.                ?"Like the bedroom, there is no carpet or other flooring here, just a rough"
  273.                ?"wooden floor covered in dust.  There were no footprints in the dust, you now"
  274.                ?"realize."
  275.  
  276.             case "dust"
  277.                ?"It just seems to be ordinary dust that would accumulate anywhere."
  278.  
  279.             case "machinery"
  280.                ?"There are many dials and buttons, but to get a closer look, you'll have to"
  281.                ?"walk into the room."
  282.          end select
  283.  
  284.       case "open"
  285.          select case object$
  286.             case "door"
  287.                if flag(f_sh_doorfront) = door_closed then
  288.                   ?"The door opens on a small flight of three steps made of grey concrete, and a"
  289.                   ?"dirt path leads from the steps to a gate in a wooden post fence, along a small"
  290.                   ?"road.  West across the road is a thick, colorful forest.  The grass next to"
  291.                   ?"the path is almost knee-high, and has gone to seed."
  292.                   ?
  293.                   ?"A rotted chunk of the door's latch breaks off and falls into the weeds next to"
  294.                   ?"the steps.  The door swings itself wide and rests against the side of the"
  295.                   ?"house."
  296.                   flag(f_sh_doorfront) = door_open
  297.                end if
  298.          end select
  299.  
  300.       case "north"
  301.          ?"You step into the north room."
  302.          goto home_table
  303.  
  304.       case "east"
  305.          ?"You return to the bedroom."
  306.          goto home_bedroom
  307.  
  308.       case "south"
  309.          ?"You peer cautiously into the room filled with machines.  You hadn't noticed it"
  310.          ?"out in the hall, but there's a very faint humming sound."
  311.          goto home_machinery
  312.  
  313.       case "west"
  314.          if flag(f_sh_doorfront) = door_open then
  315.             ?"You step out into the glorious sun.  It's a brisk fall day, but not cold."
  316.             goto home_path
  317.          end if
  318.  
  319.    end select
  320.  
  321.  
  322.  
  323. home_table:
  324.  
  325. location = loc_home_table
  326.    call get_input
  327.  
  328.    select case verb$
  329.       case "look"
  330.          select case object$
  331.             case ""
  332.                ?"This room has a large, rounded oak table against the north and west walls,"
  333.                ?"it's a bit too big for this room, and there are no chairs.  The north wall"
  334.                ?"has another small window, which is blocked by tall grass, so the room isn't"
  335.                ?"very brightly lit."
  336.  
  337.             case "table"
  338.                if flag(i_sh_deadflashlight) = no_item and flag(i_sh_papers) = no_item then
  339.                   ?"On the table, there are some scattered papers, as well as a large flashlight."
  340.                elseif flag(i_sh_deadflashlight) <> no_item and flag(i_sh_papers) = no_item then
  341.                   ?"On the table, there are some scattered papers."
  342.                elseif flag(i_sh_deadflashlight) = no_item and flag(i_sh_papers) <> no_item then
  343.                   ?"On the table, there is a large flashlight."
  344.                elseif flag(i_sh_deadflashlight) <> no_item and flag(i_sh_papers) <> no_item then
  345.                   ?"There's nothing on the table."
  346.                end if
  347.  
  348.             case "flashlight"
  349.                if flag(i_sh_deadflashlight) = no_item then
  350.                   ?"It looks heavy, and is made of black-painted metal."
  351.                end if
  352.  
  353.             case "papers"
  354.                if flag(i_sh_papers) = no_item then
  355.                   ?"There's a lot to take in here.  There are pages with lists of numbers, pages"
  356.                   ?"with indecipherable handwriting, maps of various places, a few pamphlets to"
  357.                   ?"local attractions, some receipts for small purchases, and a thin, almost"
  358.                   ?"used-up pad of tear-off legal stationery."
  359.                end if
  360.          end select
  361.  
  362.       case "get"
  363.          select case object$
  364.             case "flashlight"
  365.                if flag(i_sh_deadflashlight) = no_item then
  366.                   ?"You've got the flashlight.  It's lighter than you expected and doesn't work;"
  367.                   ?"checking the battery compartment, you find there are no batteries.  If you find"
  368.                   ?"some, using the batteries is clear enough.  Generally, if you 'use' something,"
  369.                   ?"you'll know how to use it and what to use it on."
  370.                   flag(i_sh_deadflashlight) = have_item
  371.                end if
  372.  
  373.             case "papers"
  374.                if flag(i_sh_papers) = no_item then
  375.                   ?"You pick up the mass of papers, hold them vertically, and shake them briskly"
  376.                   ?"against the table to form a neat stack.  A lot of this information seems"
  377.                   ?"random and probably useless, but in your situation, anything can help."
  378.                   ?"Perhaps some of this will make more sense later."
  379.                   flag(i_sh_papers) = have_item
  380.                end if
  381.          end select
  382.  
  383.       case "south"
  384.          ?"You return to the hallway."
  385.          goto home_hall
  386.  
  387.    end select
  388.  
  389.  
  390.  
  391. home_machinery:
  392.  
  393. location = loc_home_machinery
  394.    call get_input
  395.  
  396.    select case verb$
  397.       case "look"
  398.          select case object$
  399.             case ""
  400.                ?"It's surprisingly dark in here, there are no windows.  The only light is coming"
  401.                ?"from the buttons and the hallway.  There don't seem to be any lights to turn on"
  402.                ?"here, either - all of the walls are bare."
  403.                ?
  404.                ?"Around the sides of the room are industrial-looking metal consoles.  There are"
  405.                ?"less buttons and such than you expected.  In one corner of the floor, you can"
  406.                ?"barely make out a thick metal disk, about two feet in diameter.  There is a"
  407.                ?"matching disk mounted to the ceiling above it.  These are both connected to the"
  408.                ?"main bulk of the technology by rubber-coated cables, as thick as your arm."
  409.                ?"The light emanating from the buttons is dim, and all of the display screens"
  410.                ?"are off."
  411.                if flag(i_sh_flashlight) = have_item and flag(i_sh_keyring) = no_item then
  412.                   ?
  413.                   ?"On top of one of the consoles is a small keyring, with two identical keys and"
  414.                   ?"a red bell fob."
  415.                end if
  416.  
  417.             case "disk"
  418.                ?"It just looks like a slab of solid metal.  Moving your hand close, you can"
  419.                ?"sense a slight throbbing.  Otherwise, it betrays no sign of its purpose."
  420.  
  421.             case "buttons"
  422.                ?"The buttons are mostly about finger-sized, and various colors.  Nothing"
  423.                ?"resembles a keyboard.  There are a few labels here and there, but mostly"
  424.                ?"numbers and a few letters, nothing intelligible.  Whatever these do, you"
  425.                ?"haven't a ghost of a clue how to use them."
  426.  
  427.             case "keyring"
  428.                if flag(i_sh_keyring) = no_item then
  429.                   ?"The keyring itself is about an inch wide, the keys are small and made of brass."
  430.                   ?"The red bell is about the same size as the keys.
  431.               end if
  432.         end select
  433.  
  434.      case "get"
  435.         select case object$
  436.            case "keyring"
  437.               if flag(i_sh_keyring) = no_item then
  438.                  ?"You've got the keyring.  The keys being the same, it won't matter which one"
  439.                   ?"you use.  The bell tinkles merrily."
  440.                   flag(i_sh_keyring) = have_item
  441.                end if
  442.          end select
  443.  
  444.       case "north"
  445.          ?"You return to the hallway."
  446.          goto home_hall
  447.  
  448.    end select
  449.  
  450.  
  451.  
  452. home_path:
  453.  
  454. location = loc_home_path
  455.    call get_input
  456.  
  457.    select case verb$
  458.       case "look"
  459.          select case object$
  460.             case ""
  461.                ?"There's a good breeze going, the trees are swaying a bit, but there are no"
  462.                ?"other sounds.  The grass gets even taller a few yards on either side of the"
  463.                ?"path, obscuring your view of the countryside.  The fence beside the road is"
  464.                ?"a simple post fence made of narrow logs, with a gate leading to the road,"
  465.                ?"which is paved with coarse gravel.  Behind the small house is another forest."
  466.                ?"The sky is a steely blue, with a few large clouds."
  467.  
  468.             case "house"
  469.                ?"The house is raised off the ground, with a crawlspace underneath, choked with"
  470.                ?"grass and weeds.  It's a simple rectangular shape with a sloped roof,"
  471.                ?"unpainted, the outer walls covered in smooth wood paneling.  Despite the"
  472.                ?"obvious age of the gate and front door, the rest of the house appears very new,"
  473.                ?"showing no signs of wear."
  474.  
  475.             case "crawlspace"
  476.                ?"It's too overgrown to explore.  On the right side, you can see a stack of"
  477.                ?"cinderblocks supporting the part of the floor under the room with the machines."
  478.  
  479.             case "road"
  480.                ?"There are no signs of traffic, and no mailbox.  You can't see much of the road"
  481.                ?"from here, due to the tall grass."
  482.  
  483.             case "gate"
  484.                ?"The gate has no latch, only a rusty pair of hinges.  Wedged into the hinges"
  485.                ?"is a folded, weatherworn flyer with colorful printing."
  486.  
  487.             case "flyer"
  488.                ?"You read, 'Old Uncle Tommy's BONA FIDE Robot Bounties!  Redeem your old useless"
  489.                ?"robots for cash in hand!  Sentient toaster giving you lip?  Show it what for,"
  490.                ?"call Uncle Tommy today!"
  491.                ?
  492.                ?"You feel a twinge of sympathy for the poor robots."
  493.          end select
  494.  
  495.       case "close"
  496.          select case object$
  497.             case "door"
  498.                ?"Swinging the door shut, you can see the words 'SAFE HOUSE' painted in black"
  499.                ?"on the side of the house where it was.  At first it seems machine printed,"
  500.                ?"as it's in a very neat typeface, but looking closer, you can see brush strokes."
  501.                ?
  502.                ?"With the latch broken, the door swings open again in the breeze, clattering"
  503.                ?"loudly against the house.  That was probably audible for a mile or so."
  504.          end select
  505.  
  506.       case "east"
  507.          ?"You go back inside the house."
  508.          goto home_hall
  509.  
  510.       case "west"
  511.          ?"You hop spryly over the gate, landing at the shoulder of the gravel road with"
  512.          ?"a crunch.  It winds north and south, disappearing before long around the trees."
  513.          goto home_road
  514.  
  515.       case "south"
  516.          ?"A part of you wants to go exploring in the tall grass, but the cold, rational"
  517.          ?"side of you realizes there are more likely ways to answer your pressing"
  518.          ?"questions."
  519.  
  520.       case "north"
  521.          if flag(f_sh_clearingseen) = false then
  522.             ?"A part of you wants to go exploring in the tall grass, but the cold, rational"
  523.             ?"side of you realizes there are more likely ways to answer your pressing"
  524.             ?"questions."
  525.          elseif flag(f_sh_clearingseen) = true then
  526.             ?"Wading through the tall stalks of grass for a while, you eventually come across"
  527.             ?"a small patch that has been leveled by the presence of a car!  Only the part"
  528.             ?"covered by the car is flattened, so the car is walled on all sides by grass."
  529.             goto home_clearing
  530.          end if
  531.  
  532.    end select
  533.  
  534.  
  535.  
  536. home_road:
  537.  
  538. location = loc_home_road
  539.    call get_input
  540.  
  541.    select case verb$
  542.       case "look"
  543.          select case object$
  544.             case ""
  545.                ?"The road is narrow, and could only accommodate one vehicle.  The forest to"
  546.                ?"the west is very thick and overgrown, the leaves an assortment of brilliant"
  547.                ?"colors.  Here and there, the first leaves are falling.  To the east is the"
  548.                ?"house you awoke in, with high grass to either side.  On the north side of"
  549.                ?"the house, the grass seems to thin out, as if there's a clearing just out"
  550.                ?"of sight."
  551.                flag(f_sh_clearingseen) = true
  552.  
  553.             case "forest"
  554.                ?"You can't see anything interesting among the trees, it's far too crowded."
  555.  
  556.             case "road"
  557.                ?"The road is old and narrow, and paved with dirt and gravel.  Any vehicles"
  558.                ?"using this road would cause a lot of noise and leave a cloud of dust."
  559.  
  560.             case "house"
  561.                ?"The house looks especially out of place from here.  All the surroundings are"
  562.                ?"thickly grown and untended, but the house appears recently built."
  563.  
  564.             case "grass"
  565.                ?"Yes, there's definitely an open area among the grass to the north, some yards"
  566.                ?"away from the house."
  567.          end select
  568.  
  569.       case "north"
  570.          ?"You venture north along the road for a few minutes, the perfect fall day putting"
  571.          ?"a spring in your step, but all you find is more road and more forest.  Perhaps"
  572.          ?"it would be best to find a faster mode of travel.  You return to the gate."
  573.  
  574.       case "south"
  575.          ?"You venture south along the road for a few minutes, as it's excellent weather for"
  576.          ?"a walk, but there isn't much to see, as the road seems to go on endlessly."
  577.          ?"Perhaps it would be best to find a faster mode of travel.  You return to the gate."
  578.  
  579.       case "east"
  580.          ?"You vault back over the gate onto the path."
  581.          goto home_path
  582.  
  583.       case "west"
  584.          ?"You see no reason to venture into the forest."
  585.  
  586.    end select
  587.  
  588.  
  589.  
  590. home_clearing:
  591.  
  592. location = loc_home_clearing
  593.    call get_input
  594.  
  595.    select case verb$
  596.       case "look"
  597.          select case object$
  598.             case ""
  599.                ?"You are standing in tall grass, with a car in front of you.  It's difficult"
  600.                ?"to see much else."
  601.  
  602.             case "car"
  603.                ?"It's an old brown coupe, it seems in decent working order from here, the paint"
  604.                ?"is weatherbeaten but not peeing, and you can't see any rust.  What you can see"
  605.                ?"of the tires says they are probably fine.  You're on the driver's side,"
  606.                ?"the car is pointing toward where the road should be.  The seats are a tacky"
  607.                ?"yellow flannel, so on second thought, the car should probably be condemned."
  608.          end select
  609.  
  610.       case "open"
  611.          select case object$
  612.             case "door"
  613.                if flag(i_sh_keyring) <> have_item then
  614.                   ?"With some difficulty pushing the grass aside, you slowly work the driver's"
  615.                   ?"side soor open and climb inside.  There are no keys in the ignition, neither"
  616.                   ?"in the glove box or anywhere else that you can see, so you climb back out."
  617.                elseif flag(i_sh_keyring) = have_item then
  618.                   ?"With some difficulty pushing the grass aside, you slowly work the driver's"
  619.                   ?"side door open and climb inside, closing the door behind you.  It closes on"
  620.                   ?"some of the grass, but there's not much point trying to get it completely"
  621.                   ?"clear.  Taking out the keyring, you insert one of the keys and give it a turn."
  622.                   ?"The engine sputters a bit, but starts on the first try."
  623.                   ?
  624.                   if flag(i_sh_papers) <> have_item then
  625.                      ?"However, the road ahead is likely to be long and confusing, and you don't have"
  626.                      ?"a good idea of where to go from here.  It would be a good idea to form a basic"
  627.                      ?"plan first.  You kill the motor and get back out."
  628.                   elseif flag(i_sh_papers) = have_item then
  629.                      ?"You should be able to get the car to move west from here onto the road."
  630.                      ?"You have a mind to check out some of the places described among the papers"
  631.                      ?"you found."
  632.                      goto home_car
  633.                   end if
  634.                end if
  635.          end select
  636.  
  637.       case "north"
  638.          ?"There's no reason to search past this point."
  639.       case "east"
  640.          ?"There's no reason to search past this point."
  641.       case "west"
  642.          ?"There's no reason to search past this point."
  643.  
  644.       case "south"
  645.          ?"You navigate the tall grass again and make your way back to the house."
  646.          goto home_path
  647.  
  648.    end select
  649.  
  650.  
  651.  
  652. home_car:
  653.  
  654. location = loc_home_car
  655.    call get_input
  656.  
  657.    select case verb$
  658.       case "look"
  659.          select case object$
  660.             case ""
  661.                ?"You're sitting in an old brown car facing roughly west, surrounded by tall"
  662.                ?"grass.  The car is running, and presumably the road is through the grass"
  663.                ?"in front of you."
  664.          end select
  665.  
  666.       case "north"
  667.          ?"The grass is thick, and it would be awkward and pointless to try to move that way."
  668.       case "east"
  669.          ?"The grass is thick, and it would be awkward and pointless to try to move that way."
  670.       case "south"
  671.          ?"The grass is thick, and it would be awkward and pointless to try to move that way."
  672.  
  673.       case "west"
  674.          ?"It takes some pumping the gas to get the car through the grass ahead, but after"
  675.          ?"a minute or so of coaxing, you emerge, the front of the car pointed onto the"
  676.          ?"road.  Each of the pamphlets shows an interesting location and lists an address"
  677.          ?"with a small map.  There's a bigger travel map in the glovebox, so while"
  678.          ?"navigating might be a bit touch and go at first, you're confident you can"
  679.          ?"figure it out.  Type one of the following to drive there:"
  680.          ?
  681.          ?"'drive 1' - Newport Theater, 544 Old Elanise Road"
  682.          ?"'drive 2' - Kenworthy Historical Estate, 1202 *** Avenue"
  683.          ?"'drive 3' - David H. Christopher Public Library, 4 Vicksburgh Circle"
  684.          ?
  685.          ?"Currently, none of these locations are implemented in the game."
  686.          ?"You've completed the teaser!"
  687.          ?
  688.          ?"This is a side project to my main game development project, so I will be"
  689.          ?"continuing it as I feel motivated to.  Thanks for playing!"
  690.          ?
  691.          ?"Press enter to exit."
  692.          ?
  693.          input "> ", i$
  694.          system
  695.  
  696.    end select
  697.  
  698.  
  699.  
  700.  
  701.  
  702.  
  703. ' --------------------
  704. ' ===== Routines =====
  705. ' --------------------
  706.  
  707. sub templates
  708.  
  709. ' This sub is never called, it contains templates.
  710.  
  711. ' --- Text width ruler, at location select case indent ---
  712.  
  713. '        ?"         1         2         3         4         5         6         7         8
  714. '        ?"12345678901234567890123456789012345678901234567890123456789012345678901234567890"
  715.  
  716. ' --- Location template ---
  717.  
  718. 'home_bedroom:
  719.  
  720. location = loc_home_bedroom
  721.    call get_input
  722.  
  723.    select case verb$
  724.       case "look"
  725.          select case object$
  726.             case ""
  727.          end select
  728.  
  729.       case "get"
  730.  
  731.       case "use"
  732.  
  733.       case "open"
  734.  
  735.       ' Other verbs as needed
  736.  
  737.       case "north"
  738.       case "east"
  739.       case "south"
  740.       case "west"
  741.  
  742.    end select
  743.  
  744.  
  745.  
  746. function letter(c$)
  747.  
  748. letter = false
  749. n = asc(lcase$(c$))
  750. if n = 32 then letter = true
  751. if n => 48 and n <= 57  then letter = true
  752. if n => 97 and n <= 122 then letter = true
  753.  
  754.  
  755.  
  756. sub get_input
  757.  
  758. color 14, 0
  759. ?
  760. input "> ", i$
  761.  
  762.  
  763. ' Process input into verb and object
  764.  
  765. i$ = lcase$(i$)
  766.  
  767. ' Remove all non-letter, non-space characters
  768. for p = len(i$) to 1 step -1
  769.    if letter(mid$(i$, p, 1)) = false then i$ = left$(i$, p - 1) + right$(i$, len(i$) - p)
  770.  
  771. ' Remove leading spaces
  772. do while left$(i$, 1) = " "
  773.    i$ = right$(i$, len(i$) - 1)
  774.  
  775. ' Extract first word to verb$
  776. p = instr(i$ + " ", " ")
  777. verb$ = left$(i$, p - 1)
  778. i$ = right$(i$, len(i$) - p)
  779.  
  780. ' Remove leading spaces
  781. do while left$(i$, 1) = " "
  782.    i$ = right$(i$, len(i$) - 1)
  783.  
  784. ' Extract second word to object$, use empty string if none
  785. p = instr(i$ + " ", " ")
  786. object$ = left$(i$, p - 1)
  787.  
  788.  
  789. ' Verb shortcut replacement
  790.  
  791. select case verb$
  792.    case "n": verb$ = "north"
  793.    case "e": verb$ = "east"
  794.    case "s": verb$ = "south"
  795.    case "w": verb$ = "west"
  796.  
  797.    case "h": verb$ = "help"
  798.    case "l": verb$ = "look"
  799.    case "g": verb$ = "get"
  800.    case "o": verb$ = "open"
  801.    case "u": verb$ = "use"
  802.  
  803.  
  804. '? "["; verb$; "] ["; object$; "]"
  805. ?
  806. color 15, 0
  807.  
  808.  
  809.  
  810. ' Global commands - can be used from anywhere
  811.  
  812.    select case verb$
  813.       case "help"
  814.          ?"[h or help] - Show this information"
  815.          ?"[l or look] - Look around, or at something specific"
  816.          ?"[o or open] - Open something, keys will be used automatically"
  817.          ?"[u or use] - Use something, can generally replace other verbs"
  818.          ?"[g or get] - Pick up an item, type [inv] to see your items"
  819.          ?"[n, e, s, w, or north, east, south, west] - Move around"
  820.          ?"[nw, se, northwest, southeast, etc] - Move around some more"
  821.          ?
  822.          ?"These are only the most common commands.  Some situations will"
  823.          ?"require others.  However, you will never need more than a verb"
  824.          ?"followed by a thing."
  825.  
  826.       case "inv"
  827.          ?"--- INVENTORY ---"
  828.          for n = 1 to total_items
  829.             if flag(n) = have_item then ? item_name$(n)
  830.          next n
  831.  
  832.       case "use"
  833.          select case object$
  834.             case "batteries"
  835.                if flag(i_sh_batteries) = have_item and flag(i_sh_deadflashlight) = have_item then
  836.                   ?"You open the package and pop the batteries into the handle of the flashlight."
  837.                   ?"Testing the switch, it's now powered and will last as long as you'll need."
  838.                   flag(i_sh_batteries)      = used_item
  839.                   flag(i_sh_deadflashlight) = used_item
  840.                   flag(i_sh_flashlight)     = have_item
  841.                end if
  842.  
  843.          end select
  844.  
  845.       ' Looking at items in inventory
  846.  
  847.       case "look"
  848.          select case object$
  849.             case "flashlight"
  850.             case "batteries"
  851.             case "key"
  852.                ' Only one key in this intro chapter, but multiple keys possible later
  853.             case "keyring"
  854.             case "papers"
  855.                ' These papers may reveal more later on, so the text will depend on progress
  856.          end select
  857.    end select
  858.  
  859.  
  860.  
  861. sub save_game
  862. open "save.sav" for binary as #1
  863. put #1, 1, location
  864. put #1, , flag()
  865.  
  866.  
  867. sub load_game
  868. open "save.sav" for binary as #1
  869. get #1, 1, location
  870. get #1, , flag()
  871.  
« Last Edit: July 11, 2021, 04:05:18 am by johannhowitzer »

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Modern-setting Text Adventure
« Reply #1 on: July 11, 2021, 06:29:18 pm »
Very nicely done. Have always enjoyed text adventures. Imagining the scenery... Scribbling down a map... Only to get killed off by some hideous critter...

Looking forward to your next 'venture'....

Hmm... I noticed that 'quit' or 'exit' etc was not a valid instruction. Did you forget to include and "out" or were you being deliberately insidious? Moo Ha Ha...

J
Logic is the beginning of wisdom.

Offline johannhowitzer

  • Forum Regular
  • Posts: 118
    • View Profile
Re: Modern-setting Text Adventure
« Reply #2 on: July 11, 2021, 07:37:17 pm »
Nah, it's just not feature complete yet.  If you look at the code, you can see vestiges of a few simple systems, like examining inventory, and saving or loading games.  I'm throwing together a whole bunch of things at once here.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Modern-setting Text Adventure
« Reply #3 on: July 11, 2021, 08:28:02 pm »
Cool. I am familiar with that style of coding.... At times I throw so much together it ends up in a tangled mess... I like to call it abstract coding... lol

I have used several Interactive Fiction IDE's in the past, mainly to save time end effort... There are times I get the urge to tackle a text adventure in Basic.... I think, "Wow. That's a 'lot' of work...". Shelve it and kill off bad guys in Doom.... Maybe... Just maybe... I will pluck up enough courage to tackle one in Basic... lol

It's been 5 hours since my last caffeine intake....

J
Logic is the beginning of wisdom.

Offline johannhowitzer

  • Forum Regular
  • Posts: 118
    • View Profile
Re: Modern-setting Text Adventure
« Reply #4 on: July 11, 2021, 10:11:14 pm »
The way I'm doing this, it's pretty light on the actual coding, very easy to add more flavor text, the systems are all organized to minimize programming time and headaches, so the bulk of the work is making the game.  I've just been inspired enough that I've kept on designing and writing, and with the prologue playable, haven't got around to going back and finishing those systems.

Maybe I should make a quick tutorial video on coding text adventures this way.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Modern-setting Text Adventure
« Reply #5 on: July 11, 2021, 10:46:12 pm »
A tutorial you say? That... would be cool...
Logic is the beginning of wisdom.