Seems like the method display as written would actually print all the cells in one row -- method iterate doesn't have an explicit hook for "reached end of line". That's fine, since we have $.max available within the object.
I think method display should actually look like this:
method display
{
iterate
{
print $.grid[$^x][$^y] ?? '+' :: '.';
print "\n" if ($^x == $.max);
# print each row on own line
}
print "\n"; # blank line follows grid
print "Turn $(++$.count), press enter to continue"
print " or ctl-c to quit";
<$*IN>;
.calculate();
} # end method display
A separate style comment: wouldn't it be a bit cleaner to remove the .calculate(); line from method display and change the loop at the top so that it reads:
loop { $life.display(); $life.calculate(); }
Then there's no nasty surprise when someone does:
# somewhere far, far, away
$life.display;
`shell-script;clear`; # weird stuff on screen tty
$life.display; # refresh terminal *only*
later. I recognize that's personal preference, but Side Effects Are Scary.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|