in reply to Moose class design for game
Keep the common BadGuy stuff in a role, and compose that into different subclasses for the client and server.
package TheGame::Roles::BadGuy { use Moose::Role; has 'name' => (is => 'ro', isa => 'Str'); requires 'health'; } package TheGame::Client::BadGuy { use Moose; with 'TheGame::Roles::BadGuy'; sub health { my $self = shift; my $health = do { ... }; return int($health/10)*10; # round to nearest 10% } } package TheGame::Server::BadGuy { use Moose; with 'TheGame::Roles::BadGuy'; has health => (is => 'rw', isa => 'Num'); has inventory => (is => 'rw', isa => 'ArrayRef'); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Moose class design for game
by wanna_code_perl (Friar) on Sep 06, 2013 at 10:00 UTC |