Sample text adventure that can be compile with FreeBasic which is available on several platforms. . You could certainly add graphics and sound if you wanted to or use the code modified as a game engine. Have fun!

DECLARE FUNCTION score! ()
DECLARE FUNCTION whichway! ()
DECLARE FUNCTION bittest! (a!, b!)
DECLARE SUB describe (dir)
COMMON SHARED dchar$, n, s, e, w, u, d, false, true, cooked
COMMON SHARED done, quit, eaten, awake, turns, start, flames
COMMON SHARED ff, ew, nw, ne, sew, nonly, nsew, newud, sw, ns, donly
COMMON SHARED dn, ud, su
'
' Updated to work in basic
' By Computoman
' On 03/31/94
'
' This will work in any resolution making compatabilities with televisions
' livable.
'
' Approximate 1000 lines of code
'
REM initialize
REM constants
false = 0
true = -1
ff = 12
ew = 12
nw = 9
ne = 5
sew = 14
nonly = 1
nsew = 15
newud = 61
sw = 10
ns = 3
donly = 32
dn = 33
ud = 48
su = 18
'
n = 1
s = 2
e = 4
w = 8
u = 16
d = 32
'
DIM SHARED twopow(100)
twopow(n) = 1
twopow(s) = 2
twopow(e) = 4
twopow(w) = 8
twopow(u) = 16
twopow(d) = 32
'
location = 1
grandroom = 2
vestibule = 3
narrow1 = 4
lakeshore = 5
island = 6
brink = 7
iceroom = 8
ogreroom = 9
narrow2 = 10
pit = 11
crystal = 12
batscave = 13
steam = 14
deadend = 15
ladder = 16
maze = 17
flames = 18
'
m1 = 1
m2 = 2
m3 = 3
m4 = 4
m5 = 5
m6 = 6
m7 = 7
m8 = 8
m9 = 9
m10 = 10
m11 = 11
m12 = 12
m0dh = 1 + 12
m14 = 14
m15 = 15
m16 = 16
m17 = 17
m18 = 18
m19 = 19
'
x = start
mazeloc = 0
'
turns = 0
REM type
DIM SHARED room$(18), room(18), visited(18), ogreloc(18), thelocation(18)
FOR x = 1 TO 18
  READ room$(x)
  visited(x) = false
  ogreloc(x) = false
  thelocation(x) = false
NEXT x
DATA Start, Grandroom, Vestibule, Narrow1
DATA Lakeshore, Island, Brink, Iceroom
DATA Ogreroom, Narrow2, Pit, Crystal
DATA Batscave, Steam, Deadend, Ladder
DATA Maze, Flames
'
dchar$ = "NSEWUD"
cmnd$ = ""
turns = 0
done = false
quit = false
eaten = false
awake = false
readmsg = false
carrying = false
dropped = false
trapped = false
cooked = false
sameplace = false
'
REM start
GOSUB introduction
DO
  IF NOT sameplace THEN
    GOSUB wipe
  END IF
  sameplace = false
  visited(location) = true
  PRINT
  PRINT room$(location)
  PRINT
  SELECT CASE location
  CASE 1
    GOSUB pstart
  CASE 2
    GOSUB pgrandroom
  CASE 3
    GOSUB pvestibule
  CASE 4
    GOSUB pnarrow1
  CASE 5
    GOSUB plakeshore
  CASE 6
    GOSUB pisland
  CASE 7
    GOSUB pbrink
  CASE 8
    GOSUB piceroom
  CASE 9
    GOSUB pogreroom
  CASE 10
    GOSUB pnarrow2
  CASE 11
    GOSUB ppit
  CASE 12
    GOSUB pcrystal
  CASE 13
    GOSUB pbatscave
  CASE 14
    GOSUB psteam
  CASE 15
    GOSUB pdeadend
  CASE 16
    GOSUB pladder
  CASE 17
    GOSUB pmaze
  CASE 18
    GOSUB pflames
  CASE ELSE
    PRINT "There is no such location!"
  END SELECT
LOOP UNTIL quit OR done
GOSUB congradulations
END
wipe:
  CLS
RETURN
introduction:
  GOSUB wipe
  PRINT
  PRINT "Welcome to a mini-adventure!"
  PRINT
  PRINT "Your goal will to be to find a treasure"
  PRINT "and bring it to the starting point."
  PRINT
  PRINT "You will also get points for finding"
  PRINT "each location in the adventure."
  PRINT
  PRINT "Points will be deducted for various"
  PRINT "undesirable happenings: waking the"
  PRINT "ogre, getting eaten, getting toasted,"
  PRINT "etc."
  PRINT
  PRINT "I will guide you and be your eyes and"
  PRINT "ears.  I will describe your location"
  PRINT "and give you special instructions"
  PRINT "from time to time."
  PRINT
  INPUT "Press return to continue:", a$
  GOSUB wipe
  PRINT
  PRINT "Instructions continued:"
  PRINT
  PRINT "To command me,  tell me a direction"
  PRINT "to take - (N)orth, (S)outh, (E)ast,"
  PRINT "(W)est, (U)p, or (D)own."
  PRINT
  PRINT "Note: I only look at the first letter"
  PRINT "of the command so abbreviations"
  PRINT "are acceptable."
  PRINT
  PRINT "  When you are ready to begin your"
  PRINT "adventure, just press the 'return' key."
  INPUT " ", a$
  GOSUB wipe
RETURN
congradulations:
  IF NOT cooked THEN
    IF NOT quit THEN
      PRINT "Congradulations!"
      PRINT
      PRINT "You got the treasure in "; turns; " turns."
    END IF
    IF awake THEN
        PRINT "You woke the ogre!"
    END IF
    PRINT
    PRINT "You scored "; score; " points out"
    PRINT "of a maximum of 200 points."
    PRINT "So long for now, come again soon!"
  ELSE
    PRINT "Sorry, try again soon!"
    PRINT "You have reached the end of the game."
  END IF
  PRINT
  INPUT "Press enter to leave the game: ", a$
  GOSUB wipe
RETURN
noway:
  PRINT
  PRINT "You can not go in that direction."
RETURN
ogreaction:
  IF NOT awake THEN
    PRINT "This is the ogre's lair!"
    PRINT "If you are not careful you will"
    PRINT "wake him."
    IF (turns MOD 7) = 0 THEN
      awake = true
      PRINT "Now you have done it!"
      PRINT "You woke the ogre - better"
      PRINT "get out of here while you can."
    END IF
  ELSE
    PRINT "You would not listen to me would"
    PRINT "you?  You really better get out"
    PRINT "of here before you get eaten!"
    IF carrying THEN
      IF (turns MOD 2) = 0 THEN
        PRINT "Too bad!!  The ogre caught you"
        PRINT "and roasted you for dinner."
        PRINT "Better luck next time!!"
        eaten = true
        quit = true
      ELSE
        PRINT "Get out fast if you do not want"
        PRINT "to be a supper for the ogre!!"
      END IF
    ELSE
      IF (turns MOD 5) = 0 THEN
        PRINT "too bad - you have been eaten!"
        eaten = true
        quit = true
      END IF
    END IF
  END IF
RETURN
pstart:
  IF carrying THEN
    done = true
  ELSE
    PRINT "You are standing by a big hole in"
    PRINT "the ground,  It looks big enough"
    PRINT "to climb down."
    SELECT CASE whichway
    CASE 1, 2, 4, 8
      GOSUB noway
    CASE 16
      PRINT "You can not jump into the clouds!"
    CASE 32
      location = vestibule
    END SELECT
  END IF
RETURN
pvestibule:
  PRINT "You are in the entrance to a cave"
  PRINT "of passageways.  There are halls"
  PRINT "leading off to the north, south,"
  PRINT "and east.  Above you is a tunnel"
  PRINT "leading to the surface."
  IF dropped THEN
    PRINT "to the north though a narrow crack,"
    PRINT "You can see the treasure. If you"
    PRINT "stretch your arm through you might"
    PRINT "reach it.  Do you want to try?"
    INPUT cmnd$
    IF UCASE$(cmnd$) = "Y" THEN
      carrying = true
      dropped = false
    END IF
  END IF
  SELECT CASE whichway
  CASE 1
    location = narrow1
  CASE 2
    location = grandroom
  CASE 4
    location = iceroom
  CASE 8, 32
    GOSUB noway
  CASE 16
    location = start
  END SELECT
RETURN
pgrandroom:
  PRINT "You are in a huge open room, with"
  PRINT "an immense expanse of ceiling."
  PRINT "A dark passage leads west and a"
  PRINT "narrow crawl leads downward."
  SELECT CASE whichway
  CASE 8
    location = brink
  CASE 32
    location = iceroom
  CASE 1, 2, 4, 16
    GOSUB noway
  END SELECT
RETURN
pnarrow1:
PRINT "You are in a narrow passage which"
  PRINT "continues to the north,   It is"
  PRINT "extremely narrow to the south."
  PRINT "A tight crawl also leads to the east"
  PRINT "A curious odor seeps through it."
  PRINT "I would think twice before trying"
  PRINT "to go that way."
  IF carrying THEN
    PRINT "The treasure will not fit through"
    PRINT "The crack going south. Do you want"
    PRINT "to leave it  here?"
    INPUT cmnd$
    IF UCASE$(LEFT$(cmnd$, 1)) = "Y" THEN
      dropped = true
      carrying = false
    END IF
  END IF
  SELECT CASE whichway
  CASE 1
    location = lakeshore
  CASE 4
    location = ogreroom
  CASE 2
    PRINT "It is too narrow to get through."
  CASE 8, 16, 32
    GOSUB noway
  END SELECT
RETURN
plakeshore:
  PRINT "You are on the shore of a vast"
  PRINT "underground lake.  Narrow passages"
  PRINT "wind away to the east and south."
  PRINT "A small island is visible in the"
  PRINT "center of the lake to the north."
  SELECT CASE whichway
  CASE 1
    location = island
  CASE 2
    location = narrow1
  CASE 4
    location = narrow2
  CASE 8, 16, 32
    GOSUB noway
  END SELECT
RETURN
pisland:
  PRINT "You are on a small island in the"
  PRINT "center of the huge underground lake."
  PRINT "Dark frigid waters surround you on"
  PRINT "all sides.  You can barely make out"
  PRINT "the shoreline to the south."
  PRINT "A small message is scratched in the"
  PRINT "dirt here.  It say: 'The treasure"
  PRINT "may be found in the maze.'"
  SELECT CASE whichway
  CASE 1, 4, 8, 16, 32
    GOSUB noway
  CASE 2
    location = lakeshore
  END SELECT
  readmsg = true
RETURN
pbrink:
  PRINT "You are on the brink of a steep"
  PRINT "incline.  The bottom of the pit"
  PRINT "is over fifty feet below you."
  PRINT "You probably could slide down"
  PRINT "safely, but I will not promise you"
  PRINT "that you could get back up."
  PRINT "To the west is a dark opening"
  PRINT "into a rubble-filled tunnel.  A"
  PRINT "vampire bat just flew out of it"
  PRINT "shrieking."
  SELECT CASE whichway
  CASE 1, 2, 4, 16
    GOSUB noway
  CASE 8
    location = ogreroom
  CASE 32
    location = pit
  END SELECT
RETURN
piceroom:
  PRINT "You are in a room whose walls are"
  PRINT "formed from a deep blue crystalline"
  PRINT "ice.  To the north a narrow tunnel"
  PRINT "an omnious growling sound may be"
  PRINT "heard.  To the east  a sparkling"
  PRINT "luminescence emanates from a broad"
  PRINT "opening.  To the west a passage"
  PRINT "leads back to the vestibule."
  SELECT CASE whichway
  CASE 4
    location = crystal
  CASE 1
    location = ogreroom
  CASE 8
    location = vestibule
  CASE 2, 16, 32
    GOSUB noway
  END SELECT
RETURN
generaltalk:
  PRINT "You are in a low room whose walls"
  PRINT "are covered with ominus dark"
  PRINT "gouts of dried blood.  The center"
  PRINT "of the room is dominated by a"
  PRINT "firepit, which contains burned"
  PRINT "out coals and a long spit suspended"
  PRINT "over it's center."
  PRINT "From one dark corner emanates a"
  PRINT "horrible growling noise like that"
  PRINT "of some unspeakable monster snoring"
  PRINT "during it's dream of rending you limb"
  PRINT "from limb and making you it's dinner!"
RETURN
pogreroom:
  GOSUB generaltalk
  GOSUB ogreaction
  IF NOT eaten THEN
    PRINT "There are exits to the east, west,"
    PRINT "north, and to the south."
    SELECT CASE whichway
    CASE 1
      location = narrow2
    CASE 2
      location = iceroom
    CASE 4
      location = batscave
    CASE 8
      location = narrow1
    CASE 16
      GOSUB noway
    CASE 32
      quit = true
      eaten = true
      PRINT "Oh no!!! You dummy!!!"
      PRINT "You just fell in the firepit"
      PRINT "and made such a ruckus that"
      PRINT "you woke the ogre. I hate to"
      PRINT "tell you this, but you are"
      PRINT "also trapped!"
      FOR i = 1 TO 5
        FOR j = 1 TO 100
          PRINT ".";
        NEXT j
      NEXT i
      PRINT
      PRINT "you have been added to the"
      PRINT "ogre's gourmet recipe library!"
      PRINT "Better luck next time."
    END SELECT
  END IF
RETURN
psameplace:
  PRINT "You have crawled around some"
  PRINT "twisted tunnels and wound up"
  PRINT "where you began."
  sameplace = true
RETURN
treasure:
  IF NOT carrying THEN
    IF readmsg THEN
      PRINT "The treasure is here!!"
      PRINT "Do you want to take it now?"
      INPUT cmnd$
      IF UCASE$(LEFT$(cmnd$, 1)) = "Y" THEN
        carrying = true
        dropped = false
      END IF
    ELSE
      PRINT "The light is extrmely dim here"
      PRINT "You better get out or risk"
      PRINT "falling into the pit."
    END IF
  END IF
RETURN
pmaze:
  mazeloc = m1
  DO UNTIL mazeloc = 0
  IF NOT sameplace THEN
    GOSUB wipe
    END IF
    sameplace = false
    PRINT
    SELECT CASE mazeloc
    CASE 1
      GOSUB pm1
    CASE 2
      GOSUB pm2
    CASE 3
      GOSUB pm3
    CASE 4
      GOSUB pm4
    CASE 5
      GOSUB pm5
    CASE 6
      GOSUB pm6
    CASE 7
      GOSUB pm7
    CASE 8
      GOSUB pm8
    CASE 9
      GOSUB pm9
    CASE 10
      GOSUB pm10
    CASE 11
      GOSUB pm11
    CASE 12
      GOSUB pm12
    CASE 13
      GOSUB pm0dh
    CASE 14
      GOSUB pm14
    CASE 15
      GOSUB pm15
    CASE 16
      GOSUB pm16
    CASE 17
      GOSUB pm17
    CASE 18
      GOSUB pm18
    CASE 19
      GOSUB pm19
    END SELECT
  LOOP
RETURN
pm1:
  PRINT "You are in a maze of featureless"
  PRINT "passages. From here you can go south,"
  PRINT "east, west, or up."
  SELECT CASE whichway
  CASE 2
    location = ladder
    mazeloc = 0
  CASE 4
    mazeloc = m2
  CASE 8
    mazeloc = m4
  CASE 16
    location = steam
    mazeloc = 0
  CASE 1, 32
    GOSUB noway
  END SELECT
RETURN
pm2:
  CALL describe(nw)
  SELECT CASE whichway
  CASE 1
    mazeloc = m1
  CASE 8
    GOSUB psameplace
  CASE 2, 4, 16, 32
    GOSUB noway
  END SELECT
RETURN
pm3:
  CALL describe(ne)
  SELECT CASE whichway
  CASE 1
    mazeloc = m1
  CASE 4
    GOSUB psameplace
  CASE 2, 8, 16, 32
    GOSUB noway
  END SELECT
RETURN
pm4:
  CALL describe(sew)
  SELECT CASE whichway
  CASE 2
    mazeloc = m7
  CASE 4
    mazeloc = m3
  CASE 8
    mazeloc = m5
  CASE 1, 16, 32
    GOSUB noway
  END SELECT
RETURN
pm5:
  CALL describe(nonly)
  SELECT CASE whichway
  CASE 1
    mazeloc = m1
  CASE 2, 4, 8, 16, 32
    GOSUB noway
  END SELECT
RETURN
pm6:
  CALL describe(ne)
  SELECT CASE whichway
  CASE 1
    mazeloc = m4
  CASE 4
    GOSUB psameplace
  CASE 2, 8, 16, 32
    GOSUB noway
  END SELECT
RETURN
pm7:
  CALL describe(nsew)
  SELECT CASE whichway
  CASE 1
    mazeloc = m5
  CASE 2
    mazeloc = m9
  CASE 4
    mazeloc = m6
  CASE 8
    mazeloc = m8
  CASE 16, 32
    GOSUB noway
  END SELECT
RETURN
pm8:
  CALL describe(nw)
  SELECT CASE whichway
  CASE 1
    mazeloc = m5
  CASE 8
    GOSUB psameplace
  CASE 2, 4, 16, 32
    GOSUB noway
  END SELECT
RETURN
pm9:
  CALL describe(sw)
  SELECT CASE whichway
  CASE 2
    mazeloc = m11
  CASE 8
    mazeloc = m10
  CASE 1, 4, 16, 32
    GOSUB noway
  END SELECT
RETURN
pm10:
  CALL describe(ns)
  SELECT CASE whichway
  CASE 1
    mazeloc = m8
  CASE 2
    GOSUB psameplace
  CASE 4, 8, 16, 32
    GOSUB noway
  END SELECT
RETURN
pm11:
  CALL describe(newud)
  SELECT CASE whichway
  CASE 1
    mazeloc = m9
  CASE 2
    GOSUB noway
  CASE 4
    mazeloc = m6
  CASE 8
    mazeloc = m10
  CASE 16
    mazeloc = m1
  CASE 32
    mazeloc = m12
  END SELECT
RETURN
pm12:
  CALL describe(dn)
  SELECT CASE whichway
  CASE 1
    mazeloc = m0dh
  CASE 32
    mazeloc = m16
  CASE 2, 4, 8, 16
    GOSUB noway
  END SELECT
RETURN
pm0dh:
  CALL describe(dn)
  SELECT CASE whichway
  CASE 1
    mazeloc = 14
  CASE 32
    mazeloc = m17
  CASE 2, 4, 8, 16
    GOSUB noway
  END SELECT
RETURN
pm14:
  CALL describe(dn)
  SELECT CASE whichway
  CASE 1
    mazeloc = m15
  CASE 32
    mazeloc = m18
  CASE 2, 4, 8, 16
    GOSUB noway
  END SELECT
RETURN
pm15:
  CALL describe(ud)
  SELECT CASE whichway
  CASE 16
    mazeloc = m1
  CASE 32
    mazeloc = m19
  CASE 1, 2, 4, 8
    GOSUB noway
  END SELECT
RETURN
pm16:
  CALL describe(ns)
  SELECT CASE whichway
  CASE 1
    mazeloc = m17
  CASE 2
    GOSUB psameplace
  CASE 4, 8, 16, 32
  END SELECT
RETURN
pm17:
  CALL describe(ns)
  SELECT CASE whichway
  CASE 1
    mazeloc = m18
  CASE 2
    mazeloc = m16
  CASE 4, 8, 16, 32
    GOSUB noway
  END SELECT
RETURN
pm18:
  CALL describe(ns)
  SELECT CASE whichway
  CASE 1
    mazeloc = m19
  CASE 2
    mazeloc = m17
  CASE 4, 8, 16, 32
    GOSUB noway
  END SELECT
RETURN
pm19:
  CALL describe(su)
  GOSUB treasure
  SELECT CASE whichway
  CASE 2
    mazeloc = m18
  CASE 16
    mazeloc = m15
  CASE 1, 4, 8, 32
    GOSUB noway
  END SELECT
RETURN
pnarrow2:
  PRINT "You are in a narrow passage."
  PRINT "To the west the passage opens out"
  PRINT "by a lake shore.  To the east it is"
  PRINT "even tighter.  You just might be"
  PRINT "able to squeeze through if you try"
  PRINT "real hard."
  PRINT "There is also a strange looking"
  PRINT "alcove in the south wall that seems"
  PRINT "to open into a very cark tunnel."
  SELECT CASE whichway
  CASE 8
    location = lakeshore
  CASE 4
    location = steam
  CASE 2
    location = ogreroom
  CASE 1, 16, 32
    GOSUB noway
  END SELECT
RETURN
ppit:
  PRINT "You are the bottom of a fifty"
  PRINT "foot pit.  The walls are just a"
  PRINT "hair too steep too climb.  The pit"
  PRINT "is empty exept for a few old"
  PRINT "dried bones - I can not tell if they"
  PRINT "are human or not!! In the center"
  PRINT "of the pit is a narrow shinny"
  PRINT "leading downward."
  SELECT CASE whichway
  CASE 32
    location = ladder
  CASE 16
    PRINT "If you climb that,"
    PRINT "you are sure to kill yourself!"
  CASE 1, 2, 4, 8
    GOSUB noway
  END SELECT
RETURN
pcrystal:
  PRINT "You are in the shining hall of crystal."
  PRINT "It is intensely cold, but also chillingly"
  PRINT "beautiful.  There are large glass"
  PRINT "formations rising from the floor"
  PRINT "as if they had grown there, yet"
  PRINT "delicately sculptured with multi-faceted"
  PRINT "radiant sides.  An intense white"
  PRINT "light shines brilliantly from the"
  PRINT "floor, which is also made of a"
  PRINT "mirror smooth lead crytal.  The light"
  PRINT "is almost blinding and the many"
  PRINT "reflections that it sets off amomg"
  PRINT "the crystal formations of the room"
  PRINT "make it almost impossible to tell"
  PRINT "where the room begins and where"
  PRINT "it ends."
  SELECT CASE whichway
  CASE 4
    location = maze
  CASE 1, 8
    location = ogreroom
  CASE 2, 16, 32
    GOSUB noway
  END SELECT
RETURN
pbatscave:
  PRINT "You are in a steep cavern filled"
  PRINT "with shrieking vampire bats.  They"
  PRINT "swoop and dive at you by the"
  PRINT "thousands.  If I were you, I would"
  PRINT "get out as quick as i could.  There"
  PRINT "are openings to the west and north."
  SELECT CASE whichway
  CASE 8
    location = ogreroom
  CASE 1
    location = steam
  CASE 2, 4, 16, 32
    GOSUB noway
  END SELECT
RETURN
psteam:
  PRINT "You have entered a hall filled with"
  PRINT "a stifling steamy vapor.  There are"
  PRINT "innumerable small geysers scattered"
  PRINT "about, each contributing it's own steam"
  PRINT "to the general mist."
  PRINT "To the west is a dark opening, as"
  PRINT "well as to the north.  Further out"
  PRINT "in the middle of the room is a dark"
  PRINT "opening in the floor into which some"
  PRINT "of the vapor seems to be seeping."
  SELECT CASE whichway
  CASE 8
    location = narrow2
  CASE 1
    location = deadend
  CASE 32
    location = maze
  CASE 2
    location = batscave
  CASE 4, 16
    GOSUB noway
  END SELECT
RETURN
pladder:
  PRINT "You are at the base of a huge ladder"
  PRINT "reaching up out of sight. It must"
  PRINT "extend up at least 500 feet, and it will"
  PRINT "tale someone brave in heart to scale"
  PRINT "it.  There also passages which"
  PRINT "lead north and down."
  SELECT CASE whichway
  CASE 1
    location = maze
  CASE 32
    location = flames
  CASE 16
    IF carrying THEN
      PRINT "You can not carry the treasure up the"
      PRINT "ladder - it is too heavy!"
    ELSE
      location = vestibule
    END IF
  CASE 2, 4, 8
    GOSUB noway
  END SELECT
RETURN
pflames:
  PRINT "Unfortunately you have fallen into"
  PRINT "an underground pit. It is the"
  PRINT "source of heat that produces"
  PRINT "the geysers in the steam room.  You"
  PRINT "have been toasted to a crisp to put"
  PRINT "it politely."
  cooked = true
  done = true
RETURN
pdeadend:
  PRINT "Dead end."
  PRINT "You might come back the way"
  PRINT "from whence you came."
  SELECT CASE whichway
  CASE 2
    location = steam
  CASE 1, 4, 8, 16, 32
    GOSUB noway
  END SELECT
RETURN

FUNCTION bittest (a, b)
  IF ((FIX(a / twopow(b))) MOD 2) = 1 THEN
    bivalt = true
  ELSE
    bivalt = false
  END IF
bittest = bivalt
END FUNCTION

SUB describe (dir) STATIC
  PRINT "You are in a maze of featureless"
  PRINT "passages.  There are exits visible"
  PRINT "in the following directions:"
  IF bittest(dir, n) = true THEN
    PRINT "N ";
  END IF
  IF bittest(dir, s) = true THEN
    PRINT "S ";
  END IF
  IF bittest(dir, e) = true THEN
    PRINT "E ";
  END IF
  IF bittest(dir, w) = true THEN
    PRINT "W ";
  END IF
  IF bittest(dir, u) = true THEN
    PRINT "U ";
  END IF
  IF bittest(dir, d) = true THEN
    PRINT "D ";
  END IF
  PRINT
END SUB

FUNCTION score
  sc = 0
  FOR atloc = start TO flames
    IF visited(atloc) = true THEN
      sc = sc + 10
    END IF
  NEXT atloc
  IF NOT quit THEN
    sc = sc + 30
  END IF
  IF cooked THEN
    sc = sc - 50
  END IF
  IF eaten THEN
    sc = sc - 50
  END IF
  IF awake THEN
    sc = sc - 25
  END IF
  score = sc
  END FUNCTION

FUNCTION whichway STATIC
turns = turns + 1
  ch$ = ""
  cmnd$ = ""
  DO
    DO
        PRINT
        INPUT "Which way: ", cmnd$
    LOOP UNTIL LEN(cmnd$) > 0
    ch$ = UCASE$(LEFT$(cmnd$, 1))
    SELECT CASE ch$
    CASE "N"
      wway = n
    CASE "S"
      wway = s
    CASE "E"
      wway = e
    CASE "W"
      wway = w
    CASE "U"
      wway = u
    CASE "D"
      wway = d
    CASE "Q"
      quit = true
      EXIT FUNCTION
    END SELECT
  LOOP UNTIL INSTR(dchar$, ch$) > 0
  PRINT
  whichway! = wway
END FUNCTION
Advertisements