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:
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.if($goblin<0){ $goblin=0; }if($wizard<0){ $wizard=0; }
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:
This should save you the bore to add new elsif branches when you add rooms.# 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]));
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()
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |