G
Guest
Guest
Archived from groups: rec.games.roguelike.misc (More info?)
Hey .. i'm playing around with the silly idea (yah I know) of writing a
roguelike in Perl, and had a quick question about dynamic multiple
inheritance.
I have a main IO Handler object called Handler. When the game is started,
it checks your OS, and returns you an object of class Handler::Win or
Handler::Linux depending on what $^O contains. So far, so good.
The main Handler super-object contains methods to return objects like
player, map, etc for the child handler, so he can know how to paint the
screen and such.
I've decided that I'd like to be able to subclass the handler on levels
other than the OS. I'd like to have:
Handler:ungeonMovement
Handler:layerCreation
Handler::Inventory
Handler:rompt
etc....
What I was thinking I would do is morph the object as I needed to change the
handler object. For instance, When the game starts, the win32 handler adds
Handler:layerCreation to its @ISA list so that one can choose
name/class/etc ... Once that's complete, I was hoping I could remove
Handler:layerCreation from the @ISA list, and push on
Handler:ungeonMovement so that the process_key method would know how to
properly interprate the keystrokes to move the player around the dungeon.
I'm having a tough time dynamically modifying the Handler::Win32's @ISA list
for a blessed object instance...
Here's some code that demonstrates a constuctor for the main super Handler
class that will create the proper OS handler, then TRY to immediatly throw
them into 'movement' mode, by trying to twiddle @ISA:
sub new ($$) {
my ($handler, $mode) = @_;
if ($^O =~ /win/i) {
$handler = Handler::Win -> new;
} else {
$handler = Handler::Unix -> new;
}
if ($mode eq 'movement') {
push @$handler::ISA => 'Movement';
}
return $handler;
}
I KNOW that push line is ridiculously wrong syntactically, but I wanted to
give you an idea of what I was trying to do...
What's the proper syntax to do this, and is the whole architecture lame?
Thanks VERY much in advance for help
Hey .. i'm playing around with the silly idea (yah I know) of writing a
roguelike in Perl, and had a quick question about dynamic multiple
inheritance.
I have a main IO Handler object called Handler. When the game is started,
it checks your OS, and returns you an object of class Handler::Win or
Handler::Linux depending on what $^O contains. So far, so good.
The main Handler super-object contains methods to return objects like
player, map, etc for the child handler, so he can know how to paint the
screen and such.
I've decided that I'd like to be able to subclass the handler on levels
other than the OS. I'd like to have:
Handler:ungeonMovement
Handler:layerCreation
Handler::Inventory
Handler:rompt
etc....
What I was thinking I would do is morph the object as I needed to change the
handler object. For instance, When the game starts, the win32 handler adds
Handler:layerCreation to its @ISA list so that one can choose
name/class/etc ... Once that's complete, I was hoping I could remove
Handler:layerCreation from the @ISA list, and push on
Handler:ungeonMovement so that the process_key method would know how to
properly interprate the keystrokes to move the player around the dungeon.
I'm having a tough time dynamically modifying the Handler::Win32's @ISA list
for a blessed object instance...
Here's some code that demonstrates a constuctor for the main super Handler
class that will create the proper OS handler, then TRY to immediatly throw
them into 'movement' mode, by trying to twiddle @ISA:
sub new ($$) {
my ($handler, $mode) = @_;
if ($^O =~ /win/i) {
$handler = Handler::Win -> new;
} else {
$handler = Handler::Unix -> new;
}
if ($mode eq 'movement') {
push @$handler::ISA => 'Movement';
}
return $handler;
}
I KNOW that push line is ridiculously wrong syntactically, but I wanted to
give you an idea of what I was trying to do...
What's the proper syntax to do this, and is the whole architecture lame?
Thanks VERY much in advance for help