Guest User

Untitled

a guest
Jun 18th, 2018
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.16 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. #
  3. # From the book...
  4. # WRITE YOUR OWN ADVENTURE PROGRAMS FOR YOUR MICROCOMPUTER
  5. # J. TYLER & L. HOWARTH
  6. # USBORNE GAMEWRITER'S GUIDE
  7. # ISBN 0 86020 741 2
  8. #
  9. # PORTED FROM BASIC TO RUBY BY
  10. # JOSHUA M. CLULOW
  11. # (josh@sysmgr.org)
  12. #
  13.  
  14. class HauntedHouse
  15.  
  16. def initialize
  17. @v = 25 # number of verbs
  18. @w = 36 # number of object words
  19. @g = 18 # number of 'gettable' objects
  20. @rr = [ # DIM R$(63)
  21. "SE", "WE", "WE", "SWE", "WE", "WE", "SWE", "WS",
  22. "NS", "SE", "WE", "NW", "SE", "W", "NE", "NSW",
  23. "NS", "NS", "SE", "WE", "NWUD", "SE", "WSUD", "NS",
  24. "N", "NS", "NSE", "WE", "WE", "NSW", "NS", "NS",
  25. "S", "NSE", "NSW", "S", "NSUD", "N", "N", "NS",
  26. "NE", "NW", "NE", "W", "NSE", "WE", "W", "NS",
  27. "SE", "NSW", "E", "WE", "NW", "S", "SW", "NW",
  28. "NE", "NWE", "WE", "WE", "WE", "NWE", "NWE", "W"
  29. ]
  30. @dd = [ # DIM D$(63)
  31. "DARK CORNER", "OVERGROWN GARDEN", "BY LARGE WOODPILE",
  32. "YARD BY RUBBISH", "WEEDPATCH", "FOREST", "THICK FOREST",
  33. "BLASTED TREE", "CORNER OF HOUSE", "ENTRANCE TO KITCHEN",
  34. "KITCHEN & GRIMY COOKER", "SCULLERY DOOR",
  35. "ROOM WITH INCHES OF DUST", "REAR TURRET ROOM",
  36. "CLEARING BY HOUSE", "PATH", "SIDE OF HOUSE", "BACK OF HALLWAY",
  37. "DARK ALCOVE", "SMALL DARK ROOM", "BOTTOM OF SPIRAL STAIRCASE",
  38. "WIDE PASSAGE", "SLIPPERY STEPS", "CLIFFTOP", "NEAR CRUMBLING WALL",
  39. "GLOOMY PASSAGE", "POOL OF LIGHT", "IMPRESSIVE VAULTED HALLWAY",
  40. "HALL BY THICK WOODEN DOOR", "TROPHY ROOM",
  41. "CELLAR WITH BARRED WINDOW", "CLIFF PATH",
  42. "CUPBOARD WITH HANGING COAT", "FRONT HALL", "SITTING ROOM",
  43. "SECRET ROOM", "STEEP MARBLE STAIRS", "DINING ROOM",
  44. "DEEP CELLAR WITH COFFIN", "CLIFF PATH", "CLOSET", "FRONT LOBBY",
  45. "LIBRARY OF EVIL BOOKS", "STUDY WITH DESK & HOLE IN WALL",
  46. "COBWEBBY ROOM", "VERY COLD CHAMBER", "SPOOKY ROOM",
  47. "CLIFF PATH BY MARSH", "RUBBLE STREWN VERANDAH", "FRONT PORCH",
  48. "FRONT TOWER", "SLOPING CORRIDOR", "UPPER GALLERY", "MARSH BY WALL",
  49. "MARSH", "SOGGY PATH", "BY TWISTED RAILING", "PATH THROUGH IRON GATE",
  50. "BY RAILINGS", "BENEATH FRONT TOWER", "DEBRIS FROM CRUMBLING FACADE",
  51. "FALLEN BRICKWORK", "ROTTING STONE ARCH", "CRUMBLING CLIFFTOP"
  52. ]
  53. @oo = [ nil, # DIM O$(W)
  54. "PAINTING", "RING", "MAGIC SPELLS", "GOBLET", "SCROLL", "COINS",
  55. "STATUE", "CANDLESTICK", "MATCHES", "VACUUM", "BATTERIES", "SHOVEL",
  56. "AXE", "ROPE", "BOAT", "AEROSOL", "CANDLE", "KEY", "NORTH", "SOUTH",
  57. "WEST", "EAST", "UP", "DOWN", "DOOR", "BATS", "GHOSTS", "DRAWER",
  58. "DESK", "COAT", "RUBBISH", "COFFIN", "BOOKS", "XZANFAR", "WALL",
  59. "SPELLS"
  60. ]
  61. @vv = [ nil, # DIM V$(V)
  62. "HELP", "CARRYING?", "GO", "N", "S", "W", "E", "U", "D", "GET",
  63. "TAKE", "OPEN", "EXAMINE", "READ", "SAY", "DIG", "SWING",
  64. "CLIMB", "LIGHT", "UNLIGHT", "SPRAY", "USE", "UNLOCK",
  65. "LEAVE", "SCORE"
  66. ]
  67. @cc = [ 0 ]
  68. @w.times { @cc << 0 } # DIM C(W)
  69. @ll = [ nil,
  70. 46, 38, 35, 50, 13, 18, 28, 42, 10, 25,
  71. 26, 4, 2, 7, 47, 60, 43, 32
  72. ]
  73. @ff = [ 0 ]
  74. @w.times { @ff << 0 } # DIM F(W)
  75. @ff[18] = 1
  76. @ff[17] = 1
  77. @ff[2] = 1
  78. @ff[26] = 1
  79. @ff[28] = 1
  80. @ff[23] = 1
  81. @llll = 60 # LL = 60
  82. @rm = 57 # RM = 57
  83. @mm = "OK" # M$ = "OK"
  84. @hh = [ nil, # DIM H$(14)
  85. "BATS ATTACKING!", "A MAGICAL BARRIER TO THE WEST",
  86. "YOU CAN'T CARRY A BOAT!", "YOU HAVE THE ",
  87. "USE THIS WORD WITH CARE - 'XZANFAR'", "*MAGIC OCCURS*",
  88. "DUG THE BARS OUT", "STUDY WITH SECRET ROOM", "YOU BROKE THE THIN WALL",
  89. "YOU SEE THICK FOREST AND CLIFF TO THE SOUTH",
  90. "IT CASTS A FLICKERING LIGHT", "YOU HAVE EVERYTHING",
  91. "RETURN TO THE GATE FOR FINAL SCORE",
  92. "WELL DONE - YOU HAVE FINISHED THE GAME"
  93. ]
  94. end
  95.  
  96. def play
  97. system("clear")
  98. puts "HAUNTED HOUSE"
  99. puts "-------------"
  100. puts "YOUR LOCATION"
  101. puts @dd[@rm]
  102. print "EXITS: "
  103. @rr[@rm].each_char { |x| print "#{x}, " }
  104. puts
  105. # line 180 ...
  106. (1..@g).each do |i|
  107. if @ll[i] == @rm and @ff[i] == 0 then
  108. puts "YOU CAN SEE #{@oo[i]} HERE"
  109. end
  110. end
  111. # ... line 200
  112. puts "========================="
  113. puts @mm
  114. @mm = "WHAT?"
  115. puts "WHAT WILL YOU DO NOW"
  116. # INPUT Q$ on line 230 ...
  117. @vb, @ob = 0, 0 # VB=0:WB=0
  118. @vstr, @wstr = gets.upcase.chomp.split(" ")
  119. @vb = @vv.index(@vstr) || 0
  120. @ob = @oo.index(@wstr) || 0
  121. # line 360 ...
  122. @mm = "THAT'S SILLY" if @wstr and @ob == 0
  123. @vb = @v + 1 if @vb == 0 # IF VB=0 THEN VB=V+1
  124. @mm = "I NEED TWO WORDS" unless @wstr and @vstr
  125. @mm = "YOU CAN'T #@vstr" if @vb > @v and @ob > 0
  126. @mm = "YOU DON'T MAKE SENSE" if @vb > @v and @ob == 0
  127. @mm = "YOU DON'T HAVE #@wstr" if @vb < @v and @ob > 0 and @cc[@ob] == 0
  128. # line 420 ...
  129. if @ff[26] == 1 and @rm == 13 and rand(4) != 3 and @vb != 21 then
  130. @mm = @hh[1]
  131. return
  132. end
  133. # line 430 ...
  134. if @rm == 44 and rand(3) == 1 and @ff[24] != 1 then
  135. @ff[27] = 1
  136. end
  137. @llll -= 1 if @ff[0] == 1 # IF F(0)=1 THEN LL=LL-1
  138. @ff[0] = 0 if @llll < 1
  139. # line 455 ... VERB DISPATCH ...
  140. self.send("verb#@vb") if @vb <= @v
  141. # line 470 ...
  142. @mm = "YOUR CANDLE IS WANING!" if @llll == 10
  143. @mm = "YOUR CANDLE IS OUT!" if @llll == 1
  144. puts
  145. end
  146.  
  147. private
  148. def gosub1580
  149. puts "PRESS RETURN TO CONTINUE"
  150. gets
  151. end
  152.  
  153. def verb1 # line 500 ...
  154. puts "WORDS I KNOW:"
  155. puts @vv[1..-1].join(", ")
  156. @mm = ""
  157. gosub1580
  158. end
  159.  
  160. def verb2 # line 570 ...
  161. puts "YOU ARE CARRYING:"
  162. t = []
  163. (1..@g).each do |i|
  164. if @cc[i] == 1 then
  165. t << @oo[i]
  166. end
  167. end
  168. puts t.join(", ")
  169. @mm = ""
  170. gosub1580
  171. end
  172.  
  173. def verb3 # line 640 ...
  174. @d = 0
  175. @d = @vb - 3 if @ob == 0
  176. @d = 1 if @ob == 19
  177. @d = 2 if @ob == 20
  178. @d = 3 if @ob == 21
  179. @d = 4 if @ob == 22
  180. @d = 5 if @ob == 23
  181. @d = 6 if @ob == 24
  182. @d = 1 if @rm == 20 and @d == 5
  183. @d = 3 if @rm == 20 and @d == 6
  184. @d = 2 if @rm == 22 and @d == 6
  185. @d = 3 if @rm == 22 and @d == 5
  186. @d = 1 if @rm == 36 and @d == 6
  187. @d = 2 if @rm == 36 and @d == 5
  188. if @ff[14] == 1 then
  189. @mm = "CRASH! YOU FELL OUT OF THE TREE!"
  190. @ff[14] = 0
  191. return
  192. end
  193. if @ff[27] == 1 and @rm == 52 then
  194. @mm = "GHOSTS WILL NOT LET YOU MOVE"
  195. return
  196. end
  197. if @rm == 45 and @cc[1] == 1 and @ff[34] == 0 then
  198. @mm = @hh[2]
  199. return
  200. end
  201. if (@rm == 26 and @ff[0] == 0) and (@d == 1 or @d == 4) then
  202. @mm = "YOU NEED A LIGHT"
  203. return
  204. end
  205. # line 820...
  206. if @rm == 54 and @cc[15] != 1 then
  207. @mm = "YOU'RE STUCK!"
  208. return
  209. end
  210. if @cc[15] == 1 and not ([53, 54, 55, 47].include? @rm) then
  211. @mm = @hh[3]
  212. return
  213. end
  214. if (@rm > 26 and @rm < 30) and @ff[0] == 0 then
  215. @mm = "TOO DARK TO MOVE"
  216. return
  217. end
  218. # line 850 ...
  219. @ff[35] = 0
  220. # .... still 850 ... HANDLE MOVING FROM ROOM TO ROOM
  221. @rr[@rm].each_char do |u|
  222. if u == "N" and @d == 1 and @ff[35] == 0 then
  223. @rm -= 8
  224. @ff[35] = 1
  225. elsif u == "S" and @d == 2 and @ff[35] == 0 then
  226. @rm += 8
  227. @ff[35] = 1
  228. elsif u == "W" and @d == 3 and @ff[35] == 0 then
  229. @rm -= 1
  230. @ff[35] = 1
  231. elsif u == "E" and @d == 4 and @ff[35] == 0 then
  232. @rm += 1
  233. @ff[35] = 1
  234. end
  235. end
  236. @mm = "OK"
  237. @mm = "CAN'T GO THAT WAY!" if @ff[35] == 0
  238. @mm = "GO WHERE?" if @d < 1
  239. if @rm == 41 and @ff[23] == 1 then
  240. @rr[49] = "SW"
  241. @mm = "THE DOOR SLAMS SHUT!"
  242. @ff[23] = 0
  243. end
  244. end
  245.  
  246. def verb10 # line 980 ...
  247. @mm = "I CAN'T GET #@wstr" if @ob > @g
  248. @mm = "IT ISN'T HERE" if @ll[@ob] != @rm
  249. @mm = "WHAT #@wstr?" if @ff[@ob] != 0
  250. @mm = "YOU ALREADY HAVE IT" if @cc[@ob] == 1
  251. if @ob > 0 and @ll[@ob] == @rm and @ff[@ob] == 0 then
  252. @cc[@ob] = 1
  253. @ll[@ob] = 65
  254. @mm = @hh[4] + @wstr
  255. end
  256. end
  257.  
  258. def verb12 # line 1030 ...
  259. if @rm == 43 and (@ob = 28 or @ob == 29) then
  260. @ff[17] = 0
  261. @mm = "DRAWER OPEN"
  262. end
  263. if @rm == 28 and @ob == 25 then
  264. @mm = "IT'S LOCKED"
  265. end
  266. if @rm == 38 and @ob == 32 then
  267. @mm = "THAT'S CREEPY!"
  268. @ff[2] = 0
  269. end
  270. end
  271.  
  272. def verb13 # line 1070 ...
  273. if @ob == 30 then
  274. @ff[18] = 0
  275. @mm = "SOMETHING HERE!"
  276. end
  277. if @ob == 31 then
  278. @mm = "THAT'S DISGUSTING!"
  279. end
  280. if @ob == 28 or @ob == 29 then
  281. @mm = "THERE IS A DRAWER"
  282. end
  283. if @ob == 33 or @ob == 5 then
  284. verb14 # GOSUB 1140
  285. end
  286. if @rm == 43 and @ob == 35 then
  287. @mm = "THERE IS SOMETHING BEYOND..."
  288. end
  289. if @ob == 32 then
  290. verb12 # GOSUB 1030
  291. end
  292. end
  293.  
  294. def verb14 # line 1140 ...
  295. if @rm == 42 or @ob == 33 then
  296. @mm = "THEY ARE DEMONIC WORKS"
  297. end
  298. if (@ob == 3 or @ob == 36) and @cc[3] == 1 and @ff[34] == 0 then
  299. @mm = @hh[5]
  300. end
  301. if @cc[5] == 1 and @ob == 5 then
  302. @mm = "THE SCRIPT IS IN AN ALIEN TONGUE"
  303. end
  304. end
  305.  
  306. def verb15 # line 1180 ...
  307. @mm = "OK '#@wstr'"
  308. if @cc[3] == 1 and @ob == 34 then
  309. @mm = @hh[6]
  310. if @rm != 45 then
  311. @rm = rnd(64)
  312. end
  313. end
  314. if @cc[3] == 1 and @ob == 34 and @rm == 45 then
  315. @ff[34] = 1
  316. end
  317. end
  318.  
  319. def verb16 # line 1220 ...
  320. if @cc[12] == 1 then
  321. @mm = "YOU MADE A HOLE"
  322. end
  323. if @cc[12] == 1 and @rm == 30 then
  324. @mm = @hh[7]
  325. @dd[@rm] = "HOLE IN WALL"
  326. @rr[@rm] = "NSE"
  327. end
  328. end
  329.  
  330. def verb17 # line 1250 ...
  331. if @cc[14] != 1 and @rm == 7 then
  332. @mm = "THIS IS NO TIME TO PLAY GAMES"
  333. end
  334. if @ob == 14 and @cc[14] == 1 then
  335. @mm = "YOU SWUNG IT"
  336. end
  337. if @ob == 13 and @cc[13] == 1 then
  338. @mm = "WHOOSH!"
  339. end
  340. if @ob == 13 and @cc[13] == 1 and @rm == 45 then
  341. @rr[@rm] = "WN"
  342. @dd[@rm] = @hh[8]
  343. @mm = @hh[9]
  344. end
  345. end
  346.  
  347. def verb18 # line 1300 ...
  348. if @ob == 14 and @cc[14] == 1 then
  349. @mm = "IT ISN'T ATTACHED TO ANYTHING!"
  350. end
  351. if @ob == 14 and @cc[14] != 1 and @rm == 7 and @ff[14] == 0 then
  352. @mm = @hh[10]
  353. @ff[14] = 1
  354. return
  355. end
  356. if @ob == 14 and @cc[14] != 1 and @rm == 7 and @ff[14] == 1 then
  357. @mm = "GOING DOWN"
  358. @ff[14] = 0
  359. end
  360. end
  361.  
  362. def verb19 # line 1340 ...
  363. if @ob == 17 and @cc[17] == 1 and @cc[8] == 0 then
  364. @mm = "IT WILL BURN YOUR HANDS"
  365. end
  366. if @ob == 17 and @cc[17] == 1 and @cc[9] == 0 then
  367. @mm = "NOTHING TO LIGHT IT WITH"
  368. end
  369. if @ob == 17 and @cc[17] == 1 and @cc[9] == 1 and @cc[8] == 1 then
  370. @mm = @hh[11]
  371. @ff[0] = 1
  372. end
  373. end
  374.  
  375. def verb20 # line 1380 ...
  376. if @ff[0] == 1 then
  377. @ff[0] = 0
  378. @mm = "EXTINGUISHED"
  379. end
  380. end
  381.  
  382. def verb21 # line 1400 ...
  383. if @ob == 26 and @cc[16] == 1 then
  384. @mm == "HISSSSS"
  385. end
  386. if @ob == 26 and @cc[16] == 1 and @ff[26] == 1 then
  387. @mm = "PFFT! GOT THEM"
  388. end
  389. end
  390.  
  391. def verb22 # line 1430 ...
  392. if @ob == 10 and @cc[10] == 1 and @cc[11] == 1 then
  393. @mm = "SWITCHED ON"
  394. @ff[24] = 1
  395. end
  396. if @ff[27] == 1 and @ff[24] == 1 then
  397. @mm = "WHIZZ-VACUUMED THE GHOSTS UP!"
  398. @ff[27] = 0
  399. end
  400. end
  401.  
  402. def verb23 # line 1460 ...
  403. if @rm == 43 and (@ob == 27 or @ob == 28) then
  404. verb12 # GOSUB 1030
  405. end
  406. if @rm != 28 or @ob != 25 or @ff[25] == 1 or @cc[18] == 0 then
  407. return
  408. end
  409. @ff[25] = 1
  410. @rr[@rm] = "SEW"
  411. @dd[@rm] = "HUGE OPEN DOOR"
  412. @mm = "THE KEY TURNS!"
  413. end
  414.  
  415. def verb24 # line 1490 ...
  416. if @cc[@ob] == 1 then
  417. @cc[@ob] = 0
  418. @ll[@ob] = @rm
  419. @mm = "DONE"
  420. end
  421. end
  422.  
  423. def verb25 # line 1510 ...
  424. s = 0
  425. @mm = ""
  426. (1..@g).each do |i|
  427. s += 1 if @cc[i] == 1
  428. end
  429. if s == 17 and @cc[15] != 1 and @rm != 57 then
  430. puts @hh[12]
  431. puts @hh[13]
  432. end
  433. if s == 17 and @rm == 57 then
  434. puts "DOUBLE SCORE FOR REACHING HERE!"
  435. s *= 2
  436. end
  437. puts "YOUR SCORE=#{s}"
  438. if s > 18 then
  439. puts @hh[14]
  440. end
  441. puts
  442. exit 0
  443. end
  444.  
  445. alias :verb4 :verb3
  446. alias :verb5 :verb3
  447. alias :verb6 :verb3
  448. alias :verb7 :verb3
  449. alias :verb8 :verb3
  450. alias :verb9 :verb3
  451. alias :verb11 :verb10
  452.  
  453. end
  454.  
  455.  
  456. hh = HauntedHouse.new
  457. hh.play while true
Add Comment
Please, Sign In to add comment