The topic has been discussed in depth but I'd like to share a couple of notes.

Follow Forsaken's advice about formatting. You can also find the perltidy program quite useful, it should be in the basic distribution and basically does the work. I was particularly curious about the following lines:

if($goblin<0){ $goblin=0; }if($wizard<0){ $wizard=0; }
The second if comes immediately after the closing block associated to the previous one, which makes it less readable - it may be taken for an elsif at first glance.

Another consideration deals with the way you eval the damage with the if/elsif/... checks. I'd rather use some kind of data structure here:

# Early in the code, i.e. in some configuration section my @max_damages = (0) x $number_of_rooms; @max_damages[ 1, 2, 3, 6 ] = ( 2, 3, 4, 5 ); # ... then $wizard -= 1 + int(rand($max_damages[$room]));
This should save you the bore to add new elsif branches when you add rooms.

One final question: what does it happen in rooms 4 and 5? Or is the test for room "6" just a typo, and you meant "4"? If so, note that there's even a simpler solution using rooms as numbers:

$wizard -= 1 + int(rand($room + 1));

Flavio (perl -e 'print(scalar(reverse("\nti.xittelop\@oivalf")))')

Don't fool yourself.

In reply to Re: Random Numbers? by polettix
in thread Random Numbers? by void_Anthony()

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.