home *** CD-ROM | disk | FTP | other *** search
/ Interplay's Learn to Program Basic (Review Copy) / Learn to Program Basic Review Copy (Interplay)(June 23, 1998).ISO / pc / ltpbasic / projects / quest.bas < prev    next >
Encoding:
BASIC Source File  |  1998-02-21  |  14.9 KB  |  706 lines

  1. Rem - Quest -
  2. Rem 
  3. Rem By Richard!
  4.  
  5. Dim Dir$(8)
  6.  
  7. Dim RoomDesc$(24,3)
  8. Dim RoomMonster(24)
  9. Dim RoomExit(24,8)
  10. Dim RoomContent(24)
  11.  
  12. Dim MonsterName$(10)
  13. Dim MonsterHP(10)
  14. Dim MonsterSpeed(10)
  15. Dim MonsterDamage(10)
  16. Dim MonsterItem(10)
  17.  
  18. Dim WeaponName$(7)
  19. Dim WeaponPower(7)
  20. Dim WeaponSpeed(7)
  21.  
  22. Dim LeverMsg$(5,4)
  23. Dim Lever(5)
  24. Dim Passage$(5,2)
  25.  
  26. Dim passable(8)
  27. Dim DirOrder(8)
  28. Dim DirKey$(8)
  29.  
  30. Dim action$(3)
  31.  
  32. clear$ = ""
  33.  
  34. Rem Set up to clear the top of the screen
  35. for t = 1 to 40*3
  36. clear$ = clear$ + " "
  37. next t
  38.  
  39. Rem Read in the 8 cardinal directions
  40. for direction = 1 to 8
  41. read Dir$(direction)
  42. next direction
  43.  
  44. Rem Read all in all of the room data from the DATA tables
  45. for room = 1 to 24
  46. read RoomDesc$(room, 1)
  47. read RoomDesc$(room, 2)
  48. read RoomDesc$(room, 3)
  49. read RoomMonster(room)
  50. for exit = 1 to 8
  51. read RoomExit(room, exit)
  52. next exit
  53. read RoomContent(room)
  54. next room
  55.  
  56. Rem Read in info about the five levers
  57. for lev = 1 to 5
  58. read LeverMsg$(lev,1)
  59. read LeverMsg$(lev,2)
  60. read LeverMsg$(lev,3)
  61. read LeverMsg$(lev,4)
  62. Lever(lev) = 0
  63. next lev
  64.  
  65. Rem Read in info on the passageways
  66. for pass = 1 to 5
  67. read Passage$(pass,1)
  68. read Passage$(pass,2)
  69. next pass
  70.  
  71. Rem Read in the info for all of the monsters
  72. for monster = 1 to 10
  73. read MonsterName$(monster)
  74. read MonsterHP(monster)
  75. read MonsterSpeed(monster)
  76. read MonsterDamage(monster)
  77. read MonsterItem(monster)
  78. next monster
  79.  
  80. Rem Finally, read in the weapon information
  81. for weapon = 1 to 7
  82. read WeaponName$(weapon)
  83. read WeaponPower(weapon)
  84. read WeaponSpeed(weapon)
  85. next weapon
  86.  
  87. Rem read in data used in printing out the keypad
  88. for order = 1 to 8
  89. read DirOrder(order)
  90. next order
  91.  
  92. for order = 1 to 8
  93. read DirKey$(order)
  94. next order
  95.  
  96. Rem Set up text colors
  97. colorText = 20
  98. colorKey = 15
  99. colorHilite = 7
  100.  
  101. Rem Give the introduction, if needed
  102. cls
  103. introloop:
  104. TextColor(colorText)
  105. input "Would you like an introduction (y/n)?",ans$
  106. if ans$<>"y" and ans$<>"n" then goto introloop
  107. if ans$="n" then goto skipintro
  108. print "You are Throg, feared goblin warrior!"
  109. print "A group of elves, dwarves and gnomes"
  110. print "have foolishly built a castle on"
  111. print "Goblin territory."
  112. print "Your chieftain has given you the"
  113. print "honor of removing these creatures"
  114. print "from Goblin lands."
  115. Gosub WaitForKey
  116. Cls
  117. print "Your objective is to slay the High"
  118. print "Elf King who is locked away inside"
  119. print "the castle.  Improve yourself by"
  120. print "fighting creatures and getting"
  121. print "better weapons.  When you"
  122. print "encounter a creature, numbers"
  123. print "will pop up on your screen - the"
  124. print "faster you hit them, the better"
  125. print "your chances of hitting."
  126. Gosub WaitForKey
  127. skipintro:
  128.  
  129. Rem Generate random stats, set up player data
  130. str = random(15,20)
  131. dex = random(15,20)
  132. con = random(15,20)
  133. hp = con
  134. xp = 0
  135. level = 1
  136. curitem = 1
  137. room = 1
  138. dir = 0
  139. numactions = 1
  140. actiondone = 1
  141.  
  142. while 1
  143. Gosub PrintStatus
  144. Rem If a move was made, print the room description and check
  145. Rem for a monster.
  146. if actiondone then
  147. gosub PrintRoomDescription
  148. If RoomMonster(room) <> 0 then
  149. If RoomMonster(room) < 100 then
  150. If random(0,5) = 1 then Gosub HandleMonster
  151. Else
  152. Gosub HandleMonster
  153. endif
  154. Endif
  155. Endif
  156.  
  157. actiondone = 0
  158.  
  159. Rem Get an action key
  160. a$ = ""
  161. while a$ = ""
  162. a$ = inkey$
  163. wend
  164.  
  165. Rem is there a lever/switch/button here?
  166. if a$ = "u" and usable <> -1 then
  167. actiondone = 1
  168. if Lever(usable) <> 0 then
  169. Lever(usable) = 0
  170. else
  171. Lever(usable) = 1
  172. endif
  173. Position 0,11
  174. print LeverMsg$(usable,3)
  175. Gosub WaitForKey
  176. endif
  177.  
  178. Rem Was this a movement key?  If so, move
  179. if a$ >= "1" and a$ <= "9" then
  180. for t = 1 to 8
  181. if a$ = DirKey$(t) then
  182. if passable(DirOrder(t)) >= 0 then
  183. actiondone = 1
  184. room = passable(DirOrder(t))
  185. endif
  186. endif
  187. next t
  188. endif
  189. wend
  190. end
  191.  
  192. Rem Add an action to the stringlist
  193. AddAction:
  194. action$(numactions) = add$
  195. numactions = numactions + 1
  196. return
  197.  
  198. Rem Print a single direction keypad number
  199. PrintDirection:
  200. if passable(dir) >= 0 then
  201. TextColor(colorHilite)
  202. else
  203. TextColor(colorKey)
  204. endif
  205. print DirKey$(DirOrder(dir));" ";
  206. TextColor(colorText)
  207. if dir = 8 then print action$(1)
  208. if dir = 3 then print action$(2)
  209. if dir = 5 then print action$(3)
  210. if dir = 4 then print "  ";
  211. return
  212.  
  213. PrintRoomDescription:
  214. Rem Set up screen
  215. cls
  216. color 20
  217. FillRect 0,0 to 40,47
  218. color 10
  219. FillRect 41,0 to 319,47
  220. color 11
  221. FillRect 0,48 to 319,111
  222. color 12
  223. FillRect 0,112 to 319,206
  224. color 61
  225. FillRect 0,207 to 319,239
  226. color 14
  227. FillRect 0,144 to 0,160
  228.  
  229. Rem Print the general room description
  230. Position 0,4
  231. TextColor(colorText)
  232. print RoomDesc$(room,1)
  233. print RoomDesc$(room,2)
  234. print RoomDesc$(room,3)
  235.  
  236. Rem Clear out the action list string
  237. for t = 1 to 3
  238. action$(t) = ""
  239. next t
  240. numactions = 1
  241.  
  242. Rem Print out the "special exits"
  243. for z = 1 to 8
  244. if RoomExit(room,z) >= 100 and RoomExit(room,z) <> 999 then
  245. num = int((RoomExit(room,z)/100))
  246. a$ = ""
  247. if Lever(num) <> 0 then
  248. a$ = Passage$(num,2)
  249. passable(z) = RoomExit(room,z)+1 - ((num)*100)
  250. else
  251. a$ = Passage$(num,1)
  252. passable(z) = -1
  253. endif
  254. a$ = a$ + " lies to the "
  255. if len(a$)+len(Dir$(z)) > 40 then
  256. print a$
  257. print Dir$(z)
  258. else
  259. print a$;Dir$(z)
  260. endif
  261. else
  262. if RoomExit(room,z) <> 999 then
  263. passable(z) = RoomExit(room,z)+1
  264. else
  265. passable(z) = -1
  266. endif
  267. endif
  268. next z
  269.  
  270. Rem Print out any special levers/switches/buttons
  271. usable = -1
  272. if RoomContent(room) >= 100 then
  273. num = (RoomContent(room)-100)+1
  274. Print LeverMsg$(num,Lever(num)+1)
  275. add$ = "  <U>se "+LeverMsg$(num,4)
  276. gosub AddAction
  277. usable = num
  278. endif
  279.  
  280. Position 0,0
  281. print Clear$
  282. Position 0,0
  283. Rem Print out the keypad directions
  284. for z = 1 to 8
  285. dir = DirOrder(z)
  286. gosub PrintDirection
  287. next z
  288. Gosub PrintStatus
  289. return
  290.  
  291. Rem Print the player's status
  292. PrintStatus:
  293. Position 0,13
  294. TextColor 20
  295. print "Str:";str;" Dex:";dex;" HP:";hp;"/";con;" XP:";xp;"  "
  296. TextColor 7
  297. print WeaponName$(curitem);
  298. TextColor 20
  299. print "/Power:";
  300. TextColor 7
  301. print WeaponPower(curitem);
  302. TextColor 20
  303. print " Speed:";
  304. TextColor 7
  305. print WeaponSpeed(curitem);"   "
  306. TextColor 20
  307. return
  308.  
  309. Rem If there's a monster, handle combat
  310. HandleMonster:
  311. id = RoomMonster(room)+1
  312. if id >= 100 then id = id - 100
  313.  
  314. mname$ = MonsterName$(id)
  315. mdamage = MonsterDamage(id)
  316. mspeed = MonsterSpeed(id)
  317. mhp = MonsterHP(id)
  318. mitem = MonsterItem(id)
  319. pspeed = int((dex / 4) + WeaponSpeed(curitem))
  320. pdamage = int(str / 4)
  321. ratio = pspeed / mspeed
  322. experience = 0
  323. timetohit = ratio * 650 * (id + 1)
  324.  
  325. cls
  326. Color 101
  327. FillRect 0,0 to 319,239
  328. TextColor 7
  329. Print "- - Combat - -"
  330. Print "You see a ";mname$
  331. Gosub WaitForKey
  332.  
  333. Rem combat loop - keep going while both the monster and the
  334. Rem Player have hit points
  335. While hp > 0 and mhp > 0
  336. Print "It has ";mhp;" hits, you have ";hp;" hits."
  337. curtimer = timer()
  338. sequence = 0
  339. go = 1
  340. While go
  341. target = Random(0,9)
  342. target$ = str$(target)
  343. Print "Press <";target$;"> "
  344. a$ = ""
  345. while a$ = ""
  346. a$ = inkey$
  347. Wend
  348.  
  349. if a$ <> target$ then
  350. Rem The player presses the wrong key.  Extra damage!
  351. Go = 0
  352. damage = random(0,mdamage) + 5
  353. hp = hp - damage
  354. Print "You mess up your maneuver -"
  355. Print "The ";mname$;" hits you for ";damage;" points"
  356. else
  357. Rem If the player pressed the right key, then either
  358. Rem the maneuever is complete or it isn't
  359. sequence = sequence + 1
  360. if sequence >= id then
  361. Go = 0
  362. timeittook = timer() - curtimer
  363. if timeittook > timetohit then
  364. Rem Player hit the keys, but not in time...
  365. damage = random(0,mdamage)
  366. hp = hp - damage
  367. Print "You took to long... the ";mname$;" hits for ";damage
  368. else
  369. Rem Player hit the keys within the time limit...
  370. damage = random(1,pdamage) + WeaponPower(curitem)
  371. mhp = mhp - damage
  372. go = 0
  373. Print "You HIT for ";damage;" points"
  374. experience = experience + id + 1
  375. Endif
  376. Endif
  377. Endif
  378. Wend
  379. Wend
  380.  
  381. Rem Is the monster vanquished?  If so, if the monster
  382. Rem Gad a better weapon, give it to the player.  Then,
  383. Rem divy out the experience.
  384.  
  385. if hp <= 0 then
  386. cls
  387. color 61 'Navy Intel Blue
  388. FillRect 0,176 to 319,239
  389. Position 0,11
  390. TextColor 7 'Sorta White
  391. Print "You got killed by a ";mname$;"."
  392. Print "You had ";xp;" experience points."
  393. Gosub PrintStatus
  394. end
  395. Endif
  396.  
  397. if mhp <= 0 then
  398. Print "You vanquish the creature."
  399. if RoomMonster(room) >= 100 then RoomMonster(room) = 0
  400. if mitem > curitem then
  401. curitem = mitem
  402. Print "You pick up a handy ";WeaponName$(curitem)
  403. endif
  404. if random(0,3) = 1 then
  405. Print "You find a healing potion, and quaff it."
  406. hp = con
  407. endif
  408. Print "You gained ";experience;" experience points."
  409. Gosub GainExperience
  410.  
  411. Rem Did the player get the king?
  412. if id = 10 then
  413. Banner "You WON!"
  414. end
  415. Endif
  416. Endif
  417.  
  418. rem Gosub PrintStatus
  419. Gosub WaitForKey
  420. Gosub PrintRoomDescription
  421. Return
  422.  
  423. Rem Every 40 experience points, give the player
  424. Rem more speed or strength, and more hit points
  425. GainExperience:
  426.  
  427. xp = xp + experience
  428. if xp >  level*40 then
  429. Rem Allow for gaining multiple levels
  430. for levgain = 1 to (experience/40)+1
  431. level = level + 1
  432. event = random(0,1)
  433. if event = 0 then
  434. Print "You grow stronger!"
  435. str = str + 2
  436. endif
  437. if event = 1 then
  438. Print "You get quicker!"
  439. dex = dex + 2
  440. endif
  441. hpadd = random(1,6)
  442. Print "You gain ";hpadd;" constitution points."
  443. hp = hp + hpadd
  444. con = con + hpadd
  445. next levgain
  446. endif
  447. return
  448.  
  449. Rem Wait for a keypress
  450. WaitForKey:
  451. Print "Press <SPACE> to continue"
  452. While Inkey$ <> " "
  453. Wend
  454. Return
  455.  
  456. Rem Directions
  457. data "SouthWest", "South", "SouthEast"
  458. data "West", "East", "NorthWest"
  459. data "North", "NorthEast"
  460.  
  461. Rem Room Data
  462. Rem Room 0 - outside
  463. data "You are standing next to the moat"
  464. data "of a large castle.  A trail"
  465. data "goes around both ways."
  466. data 0
  467. data 999,999,999,001,007,999,108,999
  468. data 0
  469. Rem Room 1 - outside
  470. data "You are in the southwest corner"
  471. data "of the castle, outside the moat."
  472. data "The trail goes north and east."
  473. data 1
  474. data 999,999,999,999,000,999,002,999
  475. data 0
  476. Rem Room 2 - outside
  477. data "You are west of the castle,"
  478. data "standing outside the moat."
  479. data "The trail goes north and south."
  480. data 1
  481. data 999,001,999,999,999,999,003,999
  482. data 0
  483. Rem Room 3 - outside
  484. data "You are northwest of the castle,"
  485. data "standing outside the moat."
  486. data "The trail goes south and east."
  487. data 2
  488. data 999,002,999,999,004,999,999,999
  489. data 0
  490. Rem Room 4 - outside w/ lever
  491. data "You are north of the castle,"
  492. data "near the moat.  The trail"
  493. data "continues east and west."
  494. data 100
  495. data 999,999,999,003,005,999,999,999
  496. data 100
  497. Rem Room 5 - outside
  498. data "You are northeast of the castle,"
  499. data "near a moat.  The trail goes"
  500. data "on to the west and south."
  501. data 1
  502. data 999,006,999,004,999,999,999,999
  503. data 0
  504. Rem Room 6 - outside
  505. data "You are east of the castle."
  506. data "A moat is nearby.  The trail"
  507. data "goes north and south."
  508. data 2
  509. data 999,007,999,999,999,999,005,999
  510. data 0
  511. Rem Room 7 - outside
  512. data "You are southeast of the"
  513. data "castle.  The trail goes"
  514. data "to the west and north."
  515. data 1
  516. data 999,999,999,000,999,999,006,999
  517. data 0
  518. Rem Room 8 - Castle Entrance
  519. data "You are in the entrance"
  520. data "to the castle.  Hallways"
  521. data "go north and northeast."
  522. data 2
  523. data 999,100,999,999,999,999,012,013
  524. data 0
  525. Rem Room 9 - Castle Alcove
  526. data "You are in a small,"
  527. data "dimly-lit room.  A door"
  528. data "goes out to the north."
  529. data 3
  530. data 999,999,999,999,999,999,013,999
  531. data 0
  532. Rem Room 10 - Corridor
  533. data "This dark, stone corridor"
  534. data "goes to a door to the east."
  535. data "The courtyard is north."
  536. data 2
  537. data 999,999,999,999,011,999,014,999
  538. data 0
  539. Rem Room 11 - Kitchen
  540. data "This kitchen is filled with"
  541. data "knives and pieces of meat."
  542. data "There's a door to the west."
  543. data 101
  544. data 999,999,999,010,999,999,999,999
  545. data 101
  546. Rem Room 12 - Courtyard
  547. data "This is a bright green courtyard"
  548. data "with grass and flowers.  Trails"
  549. data "go north, south and east."
  550. data 2
  551. data 999,008,999,999,013,999,016,999
  552. data 0
  553. Rem Room 13 - Courtyard
  554. data "This is a courtyard, with bushes cut"
  555. data "in the shapes of animals.  Paths go"
  556. data "west, southwest, south and east."
  557. data 3
  558. data 008,009,999,012,014,999,999,999
  559. data 0
  560. Rem Room 14 - Gazebo
  561. data "This white gazebo has trails going off"
  562. data "in many directions.  Trails go west,"
  563. data "south, east, north and northeast."
  564. data 2
  565. data 999,010,999,013,015,999,018,019
  566. data 0
  567. Rem Room 15 - Dining Room
  568. data "This dining room contains wooden"
  569. data "tables and chairs.  A doorway"
  570. data "west goes back to the courtyard."
  571. data 4
  572. data 999,999,999,014,999,999,999,999
  573. data 0
  574. Rem Room 16 - Courtyard
  575. data "Wind blows through the trees"
  576. data "surrounding this courtyard path."
  577. data "The path winds south and east."
  578. data 2
  579. data 999,012,999,999,017,999,999,999
  580. data 0
  581. Rem Room 17 - Courtyard
  582. data "Shrubs and bushes line the path"
  583. data "through the courtyard.  The"
  584. data "path continues east and west."
  585. data 2
  586. data 999,999,999,016,018,220,999,999
  587. data 0
  588. Rem Room 18 - Courtyard
  589. data "You are at a corner in the"
  590. data "courtyard in the middle of the"
  591. data "castle. You can go south and west."
  592. data 2
  593. data 999,014,999,017,999,999,999,999
  594. data 0
  595. Rem Room 19 - Hallway
  596. data "Empty suits of armor line this"
  597. data "passageway deeper into the"
  598. data "castle.  A hall goes southwest."
  599. data 5
  600. data 014,999,999,999,999,999,323,999
  601. data 0
  602. Rem Room 20 - Prison Chamber
  603. data "This is a dimly lit prison room."
  604. data "In the flickering torchlight you"
  605. data "observe a number of empty cells."
  606. data 106
  607. data 999,999,217,999,421,999,999,999
  608. data 102
  609. Rem Room 21 - Treasure Vault
  610. data "This is the treasure vault.  Gems,"
  611. data "gold and other precious objects"
  612. data "line the walls and floor."
  613. data 108
  614. data 999,999,999,420,999,999,999,999
  615. data 104
  616. Rem Room 22 - Throne Room
  617. data "This is a large throne room. A large"
  618. data "throne chair dominates the center of"
  619. data "the room."
  620. data 109
  621. data 999,999,999,999,523,999,999,999
  622. data 0
  623. Rem Room 23 - Guard Room
  624. data "This is the guard room.  Racks of"
  625. data "weapons, bows and arrows line the"
  626. data "walls."
  627. data 107
  628. data 999,319,999,522,999,999,999,999
  629. data 103
  630.  
  631. Rem Lever messages
  632. data "There's a lever next to the moat."
  633. data "There's a pulled lever next to the moat."
  634. data "You pull the lever."
  635. data "the lever"
  636. data "There's a blue switch on the wall."
  637. data "There's a thrown blue switch on the wall"
  638. data "You throw the switch."
  639. data "the switch"
  640. data "There's a cord hanging from the ceiling."
  641. data "There's a cord hanging low from the     ceiling."
  642. data "You pull the cord... you hear a noise."
  643. data "the cord"
  644. data "An iron wheel is mounted to a wall."
  645. data "An iron wheel sits loosely on the       wall."
  646. data "You turn the iron wheel."
  647. data "the iron wheel"
  648. data "A jewel is mounted to a control         panel."
  649. data "A glowing jewel is mounted to a         control panel."
  650. data "You touch the jewel."
  651. data "the jewel"
  652.  
  653. Rem Passageway messages
  654. data "An upright drawbridge"
  655. data "A drawbridge"
  656. data "A locked stairway door"
  657. data "An open stairway door"
  658. data "A closed portcullis"
  659. data "An open portcullis"
  660. data "A closed vault "
  661. data "An open vault "
  662. data "A shimmering barrier"
  663. data "An open walkway"
  664.  
  665. Rem Monster data
  666. data "Guard Dog"
  667. data 1,1,1,0
  668. data "Hungry Wolf"
  669. data 5,2,2,0
  670. data "Gnome Guard"
  671. data 10,3,5,1
  672. data "Dwarven Warrior"
  673. data 15,4,8,2
  674. data "Elven Archer"
  675. data 25,5,10,3
  676. data "Gnome Butcher"
  677. data 40,7,14,4
  678. data "Dwarf Dungeonmaster"
  679. data 50,9,20,5
  680. data "Elven Executioner"
  681. data 70,12,25,6
  682. data "Elven Ninja"
  683. data 100,15,30,7
  684. data "High Elf King"
  685. data 150,20,40,0
  686.  
  687. Rem Weapons
  688. data "Dagger"
  689. data 1,1
  690. data "Mace"
  691. data 3,4
  692. data "Broadsword"
  693. data 4,4
  694. data "Morning Star"
  695. data 6,4
  696. data "Battle Axe"
  697. data 8,5
  698. data "Two-Handed Sword"
  699. data 10,6
  700. data "Mystic Sword"
  701. data 12,12
  702.  
  703. Rem Direction Order
  704. data 6,7,8,4,5,1,2,3
  705. data "7","8","9","4","6","1","2","3"