Thank you for the reply. I'm probably going to subclass the Enemy, but only if the design shows that it's behaviour will extend upon the base class.

Right now, all the enemies behave in exactly the same way, in fact - there is only one enemy available. And even if I add another type of monster, and want to know what monster it is, I think that it's better to extend the traits (and make the name one of them) than to introduce inheritance.

If I find that I need to introduce a monster that does not choose it's attack at random, but follows an attack pattern like "first light, then light, then heavy" (and thus, has a choose_attack method that is different than the default), then this would be a good argument to introduce subclasses inheriting from Enemy. If not, I'll just initialize the same class, with the same behaviour, but with a different set of traits.

Right now, I'm not concerned with this. I'm focusing on the combat flow, and on the question of introducing attack types into the Enemy object in an elegant way, with the choose_attack() method behaving in my desired way. This is my foremost concern.

- Luke


In reply to Re^2: Game related OO design question by blindluke
in thread Game related OO design question by blindluke

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.