Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: P6: OO Wizard Game (RPG kinda, sorta)

by Juerd (Abbot)
on May 13, 2005 at 13:09 UTC ( [id://456714]=note: print w/replies, xml ) Need Help??


in reply to P6: OO Wizard Game (RPG kinda, sorta)

my $person = Person.new(:life(100), :attack(1), :spell(2)); $person.weapons<a> = Weapon.new(:name<sword>, :powerLow(3), :powerHigh +(5) ); $person.weapons<s> = Weapon.new(:name<spell>, :powerLow(0), :powerHigh +(7) );
I suggest:
given my $person = Person.new(...) { given .weapons { .<a> = Weapon.new(...); .<b> = Weapon.new(...); } }
Or simply:
given my $person = Person.new(...) { .weapons = { a => Weapon.new(...), b => Weapon.new(...) }; }
Or maybe just
my $person = Person.new( ..., weapons => { a => Weapon.new(...), b => Weapon.new(...) } };
I personally think :pair() style should not be used for setting anything that's clearly key and value in a hash or object. :foo() is very nice for things that alter behaviour:
my $socket = Socket.new( localport => 80, localaddr => '127.0.0.1', :proto<tcp> :listen(5) :timeout(500) :reuse ); my @users = slurp '/etc/passwd' :chomp; my @even = 2..10 :by(2);

All code is untested.

Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://456714]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-04-18 21:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found