You don't have a single subroutine in your script. I have coded lots of simple scripts without subroutines or modularisation, but even a simple game should be so complex that it becomes impossible to manage without some abstraction and structure.

For example, make a subroutine that does the monster selection. The subroutine should be called with the parameters $lvl and possibly location type (so that wild pigs are only encountered in forests, Mothers-in-Law only in towns). Also not every location should have a monster

Make a subroutine that is called whenever the player moves into a new location. It should select and print what the location is (hill, road, forest, town) and return the location type. Maybe add some special events that can happen

Make a subroutine that asks the player what to do when he enters a location without a monster. Possible things to do: Heal, select a different weapon, search the area, goto next location

Make a subroutine for fighting monsters. This subroutine should ask the player each round what to do (attack, change weapon, run away, make a special attack (more damage, but less defense on the counter attack of the monster), heal ...) and resolve that. Don't hesitate to put each action the player can do in its own subroutine.

Try to give each subroutine everything it needs as a parameter. Your main script should essentially be a few subroutine calls that show the structure of the game.

If you have done that your script has become more maintainable and your game is probably a bit more fun.

UPDATE: I forgot the usability hint: Don't let the player enter 1,2,3... to select the options, attack should be 'a' not '1'.


In reply to Re: Help making simple RPG game less boring by jethro
in thread Help making simple RPG game less boring by jms53

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.