I'm playing around with a game concept. Here is my basic enemy.
package Enemy; use Moos; has wounds => (); has att_type => (); has def_type => (); sub BUILDARGS { my ($self, $type) = @_; my %monster = ( 'Rat' => { wounds => 1, att_type => 'light', def_type => 'dodge', }, ); die "Unknown monster type" unless exists $monster{$type}; $monster{$type}{'type'} = $type; return $monster{$type}; } 1; } my $monster = Enemy->new('Rat');
I'm having some trouble with the design of the attack / defense traits of an enemy. I would like to have multiple attacks with some statistics of their own. Something like this:
my %attack = ( basic_light => { type => 'light', damage => '1', defmod => { block + => '0', dodge => '0' } }, basic_heavy => { type => 'heavy', damage => '2', defmod => { block + => '0', dodge => '10' } }, );
During the fight, I will call something like:
$a = $attacker->choose_attack(); # with the intention of # $a == { type => 'light', damage => '1', defmod => { block => '0', do +dge => '0' } }
Still, I don't want to pass anything too complex to the constructor. I think that I have to keep the attack definitions within the Enemy class, and to have something to translate the attack type to a pattern.
For example: att_type => 'medium' would translate to an array of ( $attack{basic_light}, $attack{basic_heavy}), and the choose_attack() method would pick an attack from this array at random. Which would correspond to an enemy that hits heavy about 50% of the time.
How can I add it to the code in an elegant way? Should I drop the att_type and just initialize the monster with an attack pattern? I humbly seek your words of wisdom. Any advice will be welcome.
- Luke
In reply to Game related OO design question by blindluke
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |