Advertisement
LBASIC

THEWOODS.BAS

Jun 5th, 2023
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QBasic 13.79 KB | None | 0 0
  1. '_|_|_|   THEWOODS.BAS         ( part 1 of 4 )
  2. '_|_|_|   A simple game to demonstrate some basic principles.
  3. '_|_|_|   No warrantee or guarantee given or implied.
  4. '_|_|_|   PUBLIC DOMAIN   by Kurt Kuzba.  (6/19/1997)
  5. TYPE character: Pname AS STRING * 32: hits AS LONG
  6.    magic AS LONG: strength AS LONG: gold AS LONG
  7.    Weapon AS INTEGER: experience AS LONG: END TYPE
  8. DIM SHARED Player AS character, Enemy AS character
  9. RANDOMIZE TIMER
  10. SCREEN 0: WIDTH 80, 25: COLOR 9,0: CLS: LOCATE 3
  11. LOCATE , 10: PRINT "Your goal is to gain 2,000 experience."
  12. LOCATE , 10: PRINT "Upon doing this, you will have won.   "
  13. LOCATE , 10: PRINT "It will NOT, however, be easy.        "
  14. LOCATE , 10: PRINT "You will meet many malevolent forces. "
  15. COLOR 11 : LOCATE 14, 1: INPUT "What is your name? ", plyr$
  16. IF plyr$ > "" THEN
  17.    DO: Player.Pname = plyr$: Player.hits = 30: Player.magic = 0
  18.       Player.strength = 0: Player.gold = 100: Player.Weapon = 0
  19.       Player.experience = 0: Gameplay
  20.       PRINT : PRINT "Would you like to play again (YN)? ";
  21.       DO: k$ = UCASE$(INKEY$): LOOP WHILE INSTR(" YN", k$) < 2
  22.       PRINT k$: LOOP WHILE k$ = "Y"
  23. END IF
  24. PRINT : PRINT "Goodbye, then...": PRINT "Hit any key to continue."
  25. WHILE INKEY$ > "": WEND: WHILE INKEY$ = "": WEND: SYSTEM
  26. SUB Armory : DIM price(1 TO 8) AS INTEGER
  27.    price(1) = 75: price(2) = 200: price(3) = 400: price(4) = 600
  28.    price(5) = 900: price(6) = 1500: price(7) = 2500: price(8) = 4000
  29.    DO: COLOR 10, 0: PRINT
  30.       PRINT " Would you like to Sell or Buy a weapon (S/B/Q)? ";
  31.       DO: k% = INSTR(" SBQ" + CHR$(13), UCASE$(INKEY$))
  32.       LOOP WHILE k% < 2
  33.       PRINT MID$(" SBQQ", k%, 1): PRINT
  34.       SELECT CASE k%
  35.          CASE 2: money% = Player.Weapon * 30
  36.             IF money% = 0 THEN
  37.                PRINT " You cannot sell your hands here, friend!"
  38.             ELSE
  39.                PRINT " I will give you"; money%; "gold for your ";
  40.                PRINT Weapon$(Player.Weapon)
  41.                PRINT " Is it a deal (Y/N)? ";
  42.                DO: k% = INSTR(" YN", UCASE$(INKEY$))
  43.                LOOP WHILE k% < 2
  44.                PRINT MID$(" YN", k%, 1): PRINT
  45.                IF k% = 2 THEN
  46.                   Player.gold = Player.gold + money%
  47.                   Player.Weapon = 0
  48.                END IF
  49.             END IF
  50.          CASE 3: PRINT "--==**[  PRICES  ]**==--"
  51.             FOR t% = 1 TO 8: PRINT STR$(t%); "->";
  52.                PRINT LEFT$(STR$(price(t%)) + "    ", 6);
  53.                PRINT Weapon$(t%): NEXT
  54.             PRINT " Hit ENTER to buy nothing"
  55.             PRINT " You have"; Player.gold; "gold."
  56.             PRINT "Which would you buy (1-8)? ";
  57.             DO: k% = INSTR(" 12345678" + CHR$(13), UCASE$(INKEY$))
  58.             LOOP WHILE k% < 2
  59.             k% = k% - 1: PRINT MID$("12345678", k%, 1)
  60.             IF k% < 9 THEN
  61.                money% = k% * 90
  62.                IF money% > Player.gold THEN
  63.                   PRINT " You can not afford "; Weapon$(k%)
  64.                ELSE
  65.                   PRINT " Sold! I hope that "; Weapon$(k%)
  66.                   PRINT " will serve you well."
  67.                   Player.gold = Player.gold - money%
  68.                   Player.Weapon = k%
  69.                END IF
  70.             END IF
  71.          CASE 4, 5: EXIT SUB
  72.       END SELECT
  73.    LOOP: END SUB
  74. '_|_|_|   end   THEWOODS.BAS         ( part 1 of 4 )
  75. '_|_|_|   THEWOODS.BAS         ( part 2 of 4 )
  76. '_|_|_|   A simple game to demonstrate some basic principles.
  77. '_|_|_|   No warrantee or guarantee given or implied.
  78. '_|_|_|   PUBLIC DOMAIN   by Kurt Kuzba.  (6/19/1997)
  79. SUB FightMonster : level% = GetLevel%(Player.experience)
  80.    MakeEnemy level%: menu% = 1
  81.    WHILE (Player.hits > 0) AND (Enemy.hits > 0)
  82.       COLOR 4, 0: PRINT
  83.       IF menu% > 0 THEN
  84.          PRINT " F-> Fight": PRINT " R-> Run Away"
  85.          PRINT " S-> Surrender": PRINT " Y-> Your Stats"
  86.          PRINT " V-> View Enemy"
  87.       END IF
  88.       COLOR 15, 0: PRINT Player.hits; : COLOR 5, 0: PRINT Player.Pname
  89.       COLOR 15, 0: PRINT Enemy.hits; : COLOR 5, 0: PRINT Enemy.Pname
  90.       COLOR 4, 0: PRINT " [ F : R : S : Y : V : ? ]=> ";
  91.       DO: k% = INSTR(" FRSYV?", UCASE$(INKEY$)): LOOP WHILE k% < 2
  92.       PRINT MID$(" FRSYV?", k%, 1)
  93.       level% = GetLevel%(Player.experience)
  94.       SELECT CASE k%
  95.          CASE 2
  96.             PlayerAtt! = 1 + Player.Weapon
  97.             PlayerAtt! = PlayerAtt! * (1 + (Player.strength / 10))
  98.             PlayerAtt! = 5 + (RND * PlayerAtt! * 5 * level%)
  99.             PlayerDef! = 1 + (Player.strength / 100)
  100.             EnemyAtt! = Enemy.Weapon * (1 + (Enemy.strength / 10))
  101.             EnemyDef! = 1 + (Enemy.strength / 100)
  102.             IF RND > .5 THEN
  103.                PRINT " You move fast and hit first."
  104.                hits% = PlayerAtt! / EnemyDef!
  105.                IF hits% > Enemy.hits THEN hits% = Enemy.hits
  106.                Enemy.hits = Enemy.hits - hits%
  107.                PRINT " You hit for"; hits%; "points."
  108.                Player.experience = Player.experience + hits%
  109.                IF Enemy.hits > 0 THEN
  110.                   hits% = EnemyAtt! / PlayerDef!
  111.                   IF hits% > Player.hits THEN hits% = Player.hits
  112.                   Player.hits = Player.hits - hits%
  113.                   PRINT " You are hit for"; hits%; "points."
  114.                END IF
  115.             ELSE
  116.                PRINT " You move slow and get hit first."
  117.                hits% = EnemyAtt! / PlayerDef!
  118.                IF hits% > Player.hits THEN hits% = Player.hits
  119.                Player.hits = Player.hits - hits%
  120.                PRINT " You are hit for"; hits%; "points."
  121.                IF Player.hits > 0 THEN
  122.                   hits% = PlayerAtt! / EnemyDef!
  123.                   IF hits% > Enemy.hits THEN hits% = Enemy.hits
  124.                   Enemy.hits = Enemy.hits - hits%
  125.                   Player.experience = Player.experience + hits%
  126.                   PRINT " You hit for"; hits%; "points."
  127.                END IF
  128.             END IF
  129.             IF Enemy.hits = 0 THEN
  130.                PRINT " You have defeated the "; Enemy.Pname
  131.                Player.magic = Player.magic + Enemy.magic \ 10
  132.                Player.gold = Player.gold + Enemy.gold
  133.             END IF
  134.             IF Player.hits = 0 THEN
  135.                PRINT " You were defeated by a "; Enemy.Pname
  136.             END IF
  137.          CASE 3:
  138.             PRINT " You manage to escape, but all your strength"
  139.             PRINT " and magic are lost, and some experience points."
  140.             Player.magic = 0: Player.strength = 0
  141.             Player.experience = Player.experience * .9
  142.             EXIT SUB
  143.          CASE 4:
  144.             PRINT " You give all your gold to the "; Enemy.Pname
  145.             Player.gold = 0: EXIT SUB
  146.          CASE 5: Stats Player
  147.          CASE 6: Stats Enemy
  148.          CASE 7: menu% = 1
  149.       END SELECT: WEND: END SUB
  150. '_|_|_|   end   THEWOODS.BAS         ( part 2 of 4 )
  151. '_|_|_|   THEWOODS.BAS         ( part 3 of 4 )
  152. '_|_|_|   A simple game to demonstrate some basic principles.
  153. '_|_|_|   No warrantee or guarantee given or implied.
  154. '_|_|_|   PUBLIC DOMAIN   by Kurt Kuzba.  (6/19/1997)
  155. SUB Gameplay : menu% = 1: Stats Player
  156.    DO
  157.       IF Player.hits > 0 THEN
  158.          PRINT
  159.          IF menu% > 0 THEN
  160.             COLOR 15, 0: PRINT " W->  Woods": PRINT " H->  Healer"
  161.             PRINT " A->  Armory": PRINT " S->  Your Stats"
  162.             PRINT " Q->  Quit Game"
  163.          END IF: COLOR 11, 0: LOCATE , , 0: menu% = 0
  164.          PRINT " [ W : H : A : S : Q : ? ]=> ";
  165.          DO: k% = INSTR(" WHASQ?", UCASE$(INKEY$)): LOOP WHILE k% < 2
  166.          PRINT MID$(" WHASQ", k%, 1)
  167.          SELECT CASE k%
  168.             CASE 2: Woods
  169.             CASE 3: Healer
  170.             CASE 4: Armory
  171.             CASE 5: Stats Player
  172.             CASE 6: PRINT : PRINT "Leave the Woods (YN)? ";
  173.                DO: k$ = UCASE$(INKEY$)
  174.                LOOP WHILE INSTR(" YN", k$) < 2
  175.                PRINT k$: IF k$ = "Y" THEN EXIT DO
  176.             CASE 7: menu% = 1
  177.          END SELECT
  178.       ELSE
  179.          IF Player.experience < 2000 THEN
  180.             PRINT "Sorry... You have perished in battle."
  181.             FOR t% = 200 TO 150 STEP -1: SOUND t%, .1: NEXT
  182.          ELSE
  183.             PRINT "You have defeated all enemies! You WIN!!"
  184.             FOR t% = 100 TO 999 STEP 10: SOUND t%, .03: NEXT
  185.             FOR t% = 1000 TO 500 STEP -10: SOUND t%, .03: NEXT
  186.          END IF: PRINT "You had"; Player.experience; "points."
  187.          EXIT DO
  188.       END IF: LOOP: END SUB
  189. FUNCTION GetLevel% (e&)
  190.    SELECT CASE e&
  191.       CASE IS < 100: level% = 1
  192.       CASE 101 TO 500: level% = 2
  193.       CASE ELSE: level% = 3
  194.    END SELECT: GetLevel% = level%: END FUNCTION
  195. SUB Healer : Totalhits% = Player.experience \ 10 + 30
  196.    ToHeal% = Totalhits% - Player.hits
  197.    IF ToHeal% <= 0 THEN
  198.       PRINT " You do not require healing!"; CHR$(7)
  199.    ELSE
  200.       PRINT " Each point costs 3 gold to heal."
  201.       PRINT " You can afford to heal"; Player.gold \ 3; "hit points."
  202.       PRINT " You need to heal"; ToHeal%
  203.       INPUT " How many would you heal? ", heal%
  204.       IF heal% > ToHeal% THEN heal% = ToHeal%
  205.       IF heal% > (Player.gold \ 3) THEN heal% = Player.gold \ 3
  206.       Player.hits = Player.hits + heal%
  207.       Player.gold = Player.gold - (heal% * 3)
  208.       PRINT " I have healed you for"; heal%; "hit points."
  209.    END IF: END SUB
  210. SUB MakeEnemy (l%) : DIM EN(1 TO 3) AS STRING, EP(1 TO 3) AS STRING
  211.    EP(1) = "Ferocious ": EP(2) = "Snarling ": EP(3) = "Evil "
  212.    SELECT CASE l%
  213.       CASE 1: EN(1) = "Squirrel": EN(2) = "Bunny": EN(3) = "Hedgehog"
  214.       CASE 2: EN(1) = "Bear": EN(2) = "Boar": EN(3) = "Troll"
  215.       CASE 3: EN(1) = "Demon": EN(2) = "Dragon": EN(3) = "Wizard"
  216.    END SELECT
  217.    Enemy.Pname = EP(l%) + EN(RND * 2 + 1)
  218.    Enemy.hits = ((RND * 10 + 20) * l%)
  219.    Enemy.magic = ((RND * 10 + 10) * l%)
  220.    Enemy.strength = ((RND * 10 + 10) * l%)
  221.    Enemy.gold = ((RND * 100 + 100) * l%)
  222.    Enemy.Weapon = (RND * 2 + l% * 2): END SUB
  223. '_|_|_|   end   THEWOODS.BAS         ( part 3 of 4 )
  224. '_|_|_|   THEWOODS.BAS         ( part 4 of 4 )
  225. '_|_|_|   A simple game to demonstrate some basic principles.
  226. '_|_|_|   No warrantee or guarantee given or implied.
  227. '_|_|_|   PUBLIC DOMAIN   by Kurt Kuzba.  (6/19/1997)
  228. SUB Stats (P AS character) : COLOR 15, 0: PRINT
  229.    COLOR 15, 1: PRINT " Name       : "; P.Pname;
  230.    COLOR 15, 0: PRINT : COLOR 15, 1: PRINT " Hits       :";
  231.    PRINT LEFT$(STR$(P.hits) + SPACE$(32), 33);
  232.    COLOR 15, 0: PRINT : COLOR 15, 1: PRINT " Magic      :";
  233.    PRINT LEFT$(STR$(P.magic) + SPACE$(32), 33);
  234.    COLOR 15, 0: PRINT : COLOR 15, 1: PRINT " Strength   :";
  235.    PRINT LEFT$(STR$(P.strength) + SPACE$(32), 33);
  236.    COLOR 15, 0: PRINT : COLOR 15, 1: PRINT " Gold       :";
  237.    PRINT LEFT$(STR$(P.gold) + SPACE$(32), 33);
  238.    COLOR 15, 0: PRINT : COLOR 15, 1: PRINT " Weapon     : ";
  239.    PRINT LEFT$(Weapon$(P.Weapon) + SPACE$(32), 32);
  240.    COLOR 15, 0: PRINT : COLOR 15, 1: PRINT " Experience :";
  241.    PRINT LEFT$(STR$(P.experience) + SPACE$(32), 33);
  242.    COLOR 15, 0: PRINT : END SUB
  243. SUB UseMagic : COLOR 12, 0: PRINT : PRINT : menu% = 1
  244.    DO
  245.       IF menu% <> 0 THEN
  246.          PRINT " H-> Healing Spell   (4 magic)"
  247.          PRINT " S-> Strength Spell  (9 magic)"
  248.          PRINT " Q-> Quit this menu"
  249.       END IF: PRINT " You have"; Player.magic; "spell points."
  250.       menu% = 0: PRINT " [ H : S : Q : ? ]=> ";
  251.       DO: k% = INSTR(" HSQ?" + CHR$(13), UCASE$(INKEY$))
  252.       LOOP WHILE k% < 2: PRINT MID$(" CST?", k%, 1): PRINT
  253.       SELECT CASE k%
  254.          CASE 2
  255.             IF Player.magic < 4 THEN
  256.                PRINT " You haven't the magic!"
  257.             ELSE
  258.                m% = 1 + RND * 9
  259.                Player.magic = Player.magic - 4
  260.                Player.hits = Player.hits + m%
  261.                PRINT " Your spell yields"; m%; "hits."
  262.             END IF
  263.          CASE 3
  264.             IF Player.magic < 9 THEN
  265.                PRINT " You haven't the magic!"
  266.             ELSE
  267.                m% = 1 + RND * 9
  268.                Player.magic = Player.magic - 9
  269.                Player.strength = Player.strength + m%
  270.                PRINT " Your spell yields"; m%; "strength."
  271.             END IF
  272.          CASE 4, 6: EXIT SUB
  273.          CASE 5: menu% = 1
  274.       END SELECT: LOOP: END SUB
  275. SUB WalkInWoods
  276.    SELECT CASE (RND * 99)
  277.       CASE 0 TO 9: Player.gold = Player.gold + 1
  278.          COLOR 14, 0: PRINT "You found a piece of gold!"
  279.       CASE 10 TO 19: Player.magic = Player.magic + 1
  280.          COLOR 13, 0: PRINT "A faerie gives you one magic!"
  281.       CASE 20 TO 29: m% = 1 + RND * 9
  282.          Player.hits = Player.hits + m%
  283.          COLOR 9, 0: PRINT "A friendly Elf heals"; m%; "hit";
  284.          IF m% = 1 THEN PRINT "!":  ELSE PRINT "s!"
  285.       CASE 30 TO 89
  286.          COLOR 6, 0: PRINT "The path continues before you."
  287.       CASE ELSE: FightMonster
  288.    END SELECT: END SUB
  289. FUNCTION Weapon$ (w%)
  290.    SELECT CASE w%
  291.       CASE 0: Weapon$ = "Your Bare Hands"
  292.       CASE 1: Weapon$ = "A Stick"
  293.       CASE 2: Weapon$ = "A Quarterstaff"
  294.       CASE 3: Weapon$ = "A Small Knife"
  295.       CASE 4: Weapon$ = "A Big Knife"
  296.       CASE 5: Weapon$ = "A Machete"
  297.       CASE 6: Weapon$ = "A Shortsword"
  298.       CASE 7: Weapon$ = "A Longsword"
  299.       CASE 8: Weapon$ = "A Two-Handed Sword"
  300.    END SELECT: END FUNCTION
  301. SUB Woods : menu% = 1
  302.    DO: level% = GetLevel%(Player.experience)
  303.       IF Player.experience > 2000 THEN Player.hits = 0
  304.       COLOR 2, 0: PRINT : IF Player.hits = 0 THEN EXIT SUB
  305.       IF menu% <> 0 THEN
  306.          PRINT " C-> Continue": PRINT " T-> Go to Town"
  307.          PRINT " S-> Cast a Spell": PRINT " Y-> Your Stats"
  308.       END IF: menu% = 0: PRINT " [ C : S : T : Y : ? ]=> ";
  309.       DO: k% = INSTR(" CTSY?", UCASE$(INKEY$)): LOOP WHILE k% < 2
  310.       PRINT MID$(" CSTY?", k%, 1)
  311.       SELECT CASE k%
  312.          CASE 2: WalkInWoods
  313.          CASE 3: EXIT SUB
  314.          CASE 4: UseMagic
  315.          CASE 5: Stats Player
  316.          CASE 6: menu% = 1
  317.       END SELECT: LOOP: END SUB
  318. '_|_|_|   end   THEWOODS.BAS         ( part 4 of 4 )
  319.  
  320.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement