Created
October 15, 2010 12:47
-
-
Save jclulow/628124 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# From the book... | |
# WRITE YOUR OWN ADVENTURE PROGRAMS FOR YOUR MICROCOMPUTER | |
# J. TYLER & L. HOWARTH | |
# USBORNE GAMEWRITER'S GUIDE | |
# ISBN 0 86020 741 2 | |
# | |
# PORTED FROM BASIC TO RUBY BY | |
# JOSHUA M. CLULOW | |
# (josh@sysmgr.org) | |
# | |
class HauntedHouse | |
def initialize | |
@v = 25 # number of verbs | |
@w = 36 # number of object words | |
@g = 18 # number of 'gettable' objects | |
@rr = [ # DIM R$(63) | |
"SE", "WE", "WE", "SWE", "WE", "WE", "SWE", "WS", | |
"NS", "SE", "WE", "NW", "SE", "W", "NE", "NSW", | |
"NS", "NS", "SE", "WE", "NWUD", "SE", "WSUD", "NS", | |
"N", "NS", "NSE", "WE", "WE", "NSW", "NS", "NS", | |
"S", "NSE", "NSW", "S", "NSUD", "N", "N", "NS", | |
"NE", "NW", "NE", "W", "NSE", "WE", "W", "NS", | |
"SE", "NSW", "E", "WE", "NW", "S", "SW", "NW", | |
"NE", "NWE", "WE", "WE", "WE", "NWE", "NWE", "W" | |
] | |
@dd = [ # DIM D$(63) | |
"DARK CORNER", "OVERGROWN GARDEN", "BY LARGE WOODPILE", | |
"YARD BY RUBBISH", "WEEDPATCH", "FOREST", "THICK FOREST", | |
"BLASTED TREE", "CORNER OF HOUSE", "ENTRANCE TO KITCHEN", | |
"KITCHEN & GRIMY COOKER", "SCULLERY DOOR", | |
"ROOM WITH INCHES OF DUST", "REAR TURRET ROOM", | |
"CLEARING BY HOUSE", "PATH", "SIDE OF HOUSE", "BACK OF HALLWAY", | |
"DARK ALCOVE", "SMALL DARK ROOM", "BOTTOM OF SPIRAL STAIRCASE", | |
"WIDE PASSAGE", "SLIPPERY STEPS", "CLIFFTOP", "NEAR CRUMBLING WALL", | |
"GLOOMY PASSAGE", "POOL OF LIGHT", "IMPRESSIVE VAULTED HALLWAY", | |
"HALL BY THICK WOODEN DOOR", "TROPHY ROOM", | |
"CELLAR WITH BARRED WINDOW", "CLIFF PATH", | |
"CUPBOARD WITH HANGING COAT", "FRONT HALL", "SITTING ROOM", | |
"SECRET ROOM", "STEEP MARBLE STAIRS", "DINING ROOM", | |
"DEEP CELLAR WITH COFFIN", "CLIFF PATH", "CLOSET", "FRONT LOBBY", | |
"LIBRARY OF EVIL BOOKS", "STUDY WITH DESK & HOLE IN WALL", | |
"COBWEBBY ROOM", "VERY COLD CHAMBER", "SPOOKY ROOM", | |
"CLIFF PATH BY MARSH", "RUBBLE STREWN VERANDAH", "FRONT PORCH", | |
"FRONT TOWER", "SLOPING CORRIDOR", "UPPER GALLERY", "MARSH BY WALL", | |
"MARSH", "SOGGY PATH", "BY TWISTED RAILING", "PATH THROUGH IRON GATE", | |
"BY RAILINGS", "BENEATH FRONT TOWER", "DEBRIS FROM CRUMBLING FACADE", | |
"FALLEN BRICKWORK", "ROTTING STONE ARCH", "CRUMBLING CLIFFTOP" | |
] | |
@oo = [ nil, # DIM O$(W) | |
"PAINTING", "RING", "MAGIC SPELLS", "GOBLET", "SCROLL", "COINS", | |
"STATUE", "CANDLESTICK", "MATCHES", "VACUUM", "BATTERIES", "SHOVEL", | |
"AXE", "ROPE", "BOAT", "AEROSOL", "CANDLE", "KEY", "NORTH", "SOUTH", | |
"WEST", "EAST", "UP", "DOWN", "DOOR", "BATS", "GHOSTS", "DRAWER", | |
"DESK", "COAT", "RUBBISH", "COFFIN", "BOOKS", "XZANFAR", "WALL", | |
"SPELLS" | |
] | |
@vv = [ nil, # DIM V$(V) | |
"HELP", "CARRYING?", "GO", "N", "S", "W", "E", "U", "D", "GET", | |
"TAKE", "OPEN", "EXAMINE", "READ", "SAY", "DIG", "SWING", | |
"CLIMB", "LIGHT", "UNLIGHT", "SPRAY", "USE", "UNLOCK", | |
"LEAVE", "SCORE" | |
] | |
@cc = [ 0 ] | |
@w.times { @cc << 0 } # DIM C(W) | |
@ll = [ nil, | |
46, 38, 35, 50, 13, 18, 28, 42, 10, 25, | |
26, 4, 2, 7, 47, 60, 43, 32 | |
] | |
@ff = [ 0 ] | |
@w.times { @ff << 0 } # DIM F(W) | |
@ff[18] = 1 | |
@ff[17] = 1 | |
@ff[2] = 1 | |
@ff[26] = 1 | |
@ff[28] = 1 | |
@ff[23] = 1 | |
@llll = 60 # LL = 60 | |
@rm = 57 # RM = 57 | |
@mm = "OK" # M$ = "OK" | |
@hh = [ nil, # DIM H$(14) | |
"BATS ATTACKING!", "A MAGICAL BARRIER TO THE WEST", | |
"YOU CAN'T CARRY A BOAT!", "YOU HAVE THE ", | |
"USE THIS WORD WITH CARE - 'XZANFAR'", "*MAGIC OCCURS*", | |
"DUG THE BARS OUT", "STUDY WITH SECRET ROOM", "YOU BROKE THE THIN WALL", | |
"YOU SEE THICK FOREST AND CLIFF TO THE SOUTH", | |
"IT CASTS A FLICKERING LIGHT", "YOU HAVE EVERYTHING", | |
"RETURN TO THE GATE FOR FINAL SCORE", | |
"WELL DONE - YOU HAVE FINISHED THE GAME" | |
] | |
end | |
def play | |
system("clear") | |
puts "HAUNTED HOUSE" | |
puts "-------------" | |
puts "YOUR LOCATION" | |
puts @dd[@rm] | |
print "EXITS: " | |
@rr[@rm].each_char { |x| print "#{x}, " } | |
puts | |
# line 180 ... | |
(1..@g).each do |i| | |
if @ll[i] == @rm and @ff[i] == 0 then | |
puts "YOU CAN SEE #{@oo[i]} HERE" | |
end | |
end | |
# ... line 200 | |
puts "=========================" | |
puts @mm | |
@mm = "WHAT?" | |
puts "WHAT WILL YOU DO NOW" | |
# INPUT Q$ on line 230 ... | |
@vb, @ob = 0, 0 # VB=0:WB=0 | |
@vstr, @wstr = gets.upcase.chomp.split(" ") | |
@vb = @vv.index(@vstr) || 0 | |
@ob = @oo.index(@wstr) || 0 | |
# line 360 ... | |
@mm = "THAT'S SILLY" if @wstr and @ob == 0 | |
@vb = @v + 1 if @vb == 0 # IF VB=0 THEN VB=V+1 | |
@mm = "I NEED TWO WORDS" unless @wstr and @vstr | |
@mm = "YOU CAN'T #@vstr" if @vb > @v and @ob > 0 | |
@mm = "YOU DON'T MAKE SENSE" if @vb > @v and @ob == 0 | |
@mm = "YOU DON'T HAVE #@wstr" if @vb < @v and @ob > 0 and @cc[@ob] == 0 | |
# line 420 ... | |
if @ff[26] == 1 and @rm == 13 and rand(4) != 3 and @vb != 21 then | |
@mm = @hh[1] | |
return | |
end | |
# line 430 ... | |
if @rm == 44 and rand(3) == 1 and @ff[24] != 1 then | |
@ff[27] = 1 | |
end | |
@llll -= 1 if @ff[0] == 1 # IF F(0)=1 THEN LL=LL-1 | |
@ff[0] = 0 if @llll < 1 | |
# line 455 ... VERB DISPATCH ... | |
self.send("verb#@vb") if @vb <= @v | |
# line 470 ... | |
@mm = "YOUR CANDLE IS WANING!" if @llll == 10 | |
@mm = "YOUR CANDLE IS OUT!" if @llll == 1 | |
puts | |
end | |
private | |
def gosub1580 | |
puts "PRESS RETURN TO CONTINUE" | |
gets | |
end | |
def verb1 # line 500 ... | |
puts "WORDS I KNOW:" | |
puts @vv[1..-1].join(", ") | |
@mm = "" | |
gosub1580 | |
end | |
def verb2 # line 570 ... | |
puts "YOU ARE CARRYING:" | |
t = [] | |
(1..@g).each do |i| | |
if @cc[i] == 1 then | |
t << @oo[i] | |
end | |
end | |
puts t.join(", ") | |
@mm = "" | |
gosub1580 | |
end | |
def verb3 # line 640 ... | |
@d = 0 | |
@d = @vb - 3 if @ob == 0 | |
@d = 1 if @ob == 19 | |
@d = 2 if @ob == 20 | |
@d = 3 if @ob == 21 | |
@d = 4 if @ob == 22 | |
@d = 5 if @ob == 23 | |
@d = 6 if @ob == 24 | |
@d = 1 if @rm == 20 and @d == 5 | |
@d = 3 if @rm == 20 and @d == 6 | |
@d = 2 if @rm == 22 and @d == 6 | |
@d = 3 if @rm == 22 and @d == 5 | |
@d = 1 if @rm == 36 and @d == 6 | |
@d = 2 if @rm == 36 and @d == 5 | |
if @ff[14] == 1 then | |
@mm = "CRASH! YOU FELL OUT OF THE TREE!" | |
@ff[14] = 0 | |
return | |
end | |
if @ff[27] == 1 and @rm == 52 then | |
@mm = "GHOSTS WILL NOT LET YOU MOVE" | |
return | |
end | |
if @rm == 45 and @cc[1] == 1 and @ff[34] == 0 then | |
@mm = @hh[2] | |
return | |
end | |
if (@rm == 26 and @ff[0] == 0) and (@d == 1 or @d == 4) then | |
@mm = "YOU NEED A LIGHT" | |
return | |
end | |
# line 820... | |
if @rm == 54 and @cc[15] != 1 then | |
@mm = "YOU'RE STUCK!" | |
return | |
end | |
if @cc[15] == 1 and not ([53, 54, 55, 47].include? @rm) then | |
@mm = @hh[3] | |
return | |
end | |
if (@rm > 26 and @rm < 30) and @ff[0] == 0 then | |
@mm = "TOO DARK TO MOVE" | |
return | |
end | |
# line 850 ... | |
@ff[35] = 0 | |
# .... still 850 ... HANDLE MOVING FROM ROOM TO ROOM | |
@rr[@rm].each_char do |u| | |
if u == "N" and @d == 1 and @ff[35] == 0 then | |
@rm -= 8 | |
@ff[35] = 1 | |
elsif u == "S" and @d == 2 and @ff[35] == 0 then | |
@rm += 8 | |
@ff[35] = 1 | |
elsif u == "W" and @d == 3 and @ff[35] == 0 then | |
@rm -= 1 | |
@ff[35] = 1 | |
elsif u == "E" and @d == 4 and @ff[35] == 0 then | |
@rm += 1 | |
@ff[35] = 1 | |
end | |
end | |
@mm = "OK" | |
@mm = "CAN'T GO THAT WAY!" if @ff[35] == 0 | |
@mm = "GO WHERE?" if @d < 1 | |
if @rm == 41 and @ff[23] == 1 then | |
@rr[49] = "SW" | |
@mm = "THE DOOR SLAMS SHUT!" | |
@ff[23] = 0 | |
end | |
end | |
def verb10 # line 980 ... | |
@mm = "I CAN'T GET #@wstr" if @ob > @g | |
@mm = "IT ISN'T HERE" if @ll[@ob] != @rm | |
@mm = "WHAT #@wstr?" if @ff[@ob] != 0 | |
@mm = "YOU ALREADY HAVE IT" if @cc[@ob] == 1 | |
if @ob > 0 and @ll[@ob] == @rm and @ff[@ob] == 0 then | |
@cc[@ob] = 1 | |
@ll[@ob] = 65 | |
@mm = @hh[4] + @wstr | |
end | |
end | |
def verb12 # line 1030 ... | |
if @rm == 43 and (@ob = 28 or @ob == 29) then | |
@ff[17] = 0 | |
@mm = "DRAWER OPEN" | |
end | |
if @rm == 28 and @ob == 25 then | |
@mm = "IT'S LOCKED" | |
end | |
if @rm == 38 and @ob == 32 then | |
@mm = "THAT'S CREEPY!" | |
@ff[2] = 0 | |
end | |
end | |
def verb13 # line 1070 ... | |
if @ob == 30 then | |
@ff[18] = 0 | |
@mm = "SOMETHING HERE!" | |
end | |
if @ob == 31 then | |
@mm = "THAT'S DISGUSTING!" | |
end | |
if @ob == 28 or @ob == 29 then | |
@mm = "THERE IS A DRAWER" | |
end | |
if @ob == 33 or @ob == 5 then | |
verb14 # GOSUB 1140 | |
end | |
if @rm == 43 and @ob == 35 then | |
@mm = "THERE IS SOMETHING BEYOND..." | |
end | |
if @ob == 32 then | |
verb12 # GOSUB 1030 | |
end | |
end | |
def verb14 # line 1140 ... | |
if @rm == 42 or @ob == 33 then | |
@mm = "THEY ARE DEMONIC WORKS" | |
end | |
if (@ob == 3 or @ob == 36) and @cc[3] == 1 and @ff[34] == 0 then | |
@mm = @hh[5] | |
end | |
if @cc[5] == 1 and @ob == 5 then | |
@mm = "THE SCRIPT IS IN AN ALIEN TONGUE" | |
end | |
end | |
def verb15 # line 1180 ... | |
@mm = "OK '#@wstr'" | |
if @cc[3] == 1 and @ob == 34 then | |
@mm = @hh[6] | |
if @rm != 45 then | |
@rm = rnd(64) | |
end | |
end | |
if @cc[3] == 1 and @ob == 34 and @rm == 45 then | |
@ff[34] = 1 | |
end | |
end | |
def verb16 # line 1220 ... | |
if @cc[12] == 1 then | |
@mm = "YOU MADE A HOLE" | |
end | |
if @cc[12] == 1 and @rm == 30 then | |
@mm = @hh[7] | |
@dd[@rm] = "HOLE IN WALL" | |
@rr[@rm] = "NSE" | |
end | |
end | |
def verb17 # line 1250 ... | |
if @cc[14] != 1 and @rm == 7 then | |
@mm = "THIS IS NO TIME TO PLAY GAMES" | |
end | |
if @ob == 14 and @cc[14] == 1 then | |
@mm = "YOU SWUNG IT" | |
end | |
if @ob == 13 and @cc[13] == 1 then | |
@mm = "WHOOSH!" | |
end | |
if @ob == 13 and @cc[13] == 1 and @rm == 45 then | |
@rr[@rm] = "WN" | |
@dd[@rm] = @hh[8] | |
@mm = @hh[9] | |
end | |
end | |
def verb18 # line 1300 ... | |
if @ob == 14 and @cc[14] == 1 then | |
@mm = "IT ISN'T ATTACHED TO ANYTHING!" | |
end | |
if @ob == 14 and @cc[14] != 1 and @rm == 7 and @ff[14] == 0 then | |
@mm = @hh[10] | |
@ff[14] = 1 | |
return | |
end | |
if @ob == 14 and @cc[14] != 1 and @rm == 7 and @ff[14] == 1 then | |
@mm = "GOING DOWN" | |
@ff[14] = 0 | |
end | |
end | |
def verb19 # line 1340 ... | |
if @ob == 17 and @cc[17] == 1 and @cc[8] == 0 then | |
@mm = "IT WILL BURN YOUR HANDS" | |
end | |
if @ob == 17 and @cc[17] == 1 and @cc[9] == 0 then | |
@mm = "NOTHING TO LIGHT IT WITH" | |
end | |
if @ob == 17 and @cc[17] == 1 and @cc[9] == 1 and @cc[8] == 1 then | |
@mm = @hh[11] | |
@ff[0] = 1 | |
end | |
end | |
def verb20 # line 1380 ... | |
if @ff[0] == 1 then | |
@ff[0] = 0 | |
@mm = "EXTINGUISHED" | |
end | |
end | |
def verb21 # line 1400 ... | |
if @ob == 26 and @cc[16] == 1 then | |
@mm == "HISSSSS" | |
end | |
if @ob == 26 and @cc[16] == 1 and @ff[26] == 1 then | |
@mm = "PFFT! GOT THEM" | |
end | |
end | |
def verb22 # line 1430 ... | |
if @ob == 10 and @cc[10] == 1 and @cc[11] == 1 then | |
@mm = "SWITCHED ON" | |
@ff[24] = 1 | |
end | |
if @ff[27] == 1 and @ff[24] == 1 then | |
@mm = "WHIZZ-VACUUMED THE GHOSTS UP!" | |
@ff[27] = 0 | |
end | |
end | |
def verb23 # line 1460 ... | |
if @rm == 43 and (@ob == 27 or @ob == 28) then | |
verb12 # GOSUB 1030 | |
end | |
if @rm != 28 or @ob != 25 or @ff[25] == 1 or @cc[18] == 0 then | |
return | |
end | |
@ff[25] = 1 | |
@rr[@rm] = "SEW" | |
@dd[@rm] = "HUGE OPEN DOOR" | |
@mm = "THE KEY TURNS!" | |
end | |
def verb24 # line 1490 ... | |
if @cc[@ob] == 1 then | |
@cc[@ob] = 0 | |
@ll[@ob] = @rm | |
@mm = "DONE" | |
end | |
end | |
def verb25 # line 1510 ... | |
s = 0 | |
@mm = "" | |
(1..@g).each do |i| | |
s += 1 if @cc[i] == 1 | |
end | |
if s == 17 and @cc[15] != 1 and @rm != 57 then | |
puts @hh[12] | |
puts @hh[13] | |
end | |
if s == 17 and @rm == 57 then | |
puts "DOUBLE SCORE FOR REACHING HERE!" | |
s *= 2 | |
end | |
puts "YOUR SCORE=#{s}" | |
if s > 18 then | |
puts @hh[14] | |
end | |
puts | |
exit 0 | |
end | |
alias :verb4 :verb3 | |
alias :verb5 :verb3 | |
alias :verb6 :verb3 | |
alias :verb7 :verb3 | |
alias :verb8 :verb3 | |
alias :verb9 :verb3 | |
alias :verb11 :verb10 | |
end | |
hh = HauntedHouse.new | |
hh.play while true | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment