in reply to Re: (ichimunki) Re (tilly) 1: Dice::Dice
in thread Dice::Dice
If you really want to be able to know every roll this particular Di has ever yielded you could add History => (), to the new method and push $newface onto that during Roll(). I would avoid this unless it were heavily restricted in the implementation. Also, using the wantarray function (or even detecting the presence of an argument) you can easily have the Roll() method detect whether or not it should act like the Rolls() function and return a list, or just roll once and return that as a scalar. Does this help?sub new { my $Di = { Sides => 6, Face => 1 }; #default six sider, sitting with 1 up bless $Di, "Dice::Di"; } sub Roll { my $self = shift; my $newface = int( rand( $self->{'Sides'} ) + 1); $self->{'Face'} = $newface; return $newface; } sub Rolls { #call with @results = $Di->Rolls( integer ); my $self = shift; my $times = shift; my @faces; for (1..$times) { my $rolled = $self->Roll(); push( @faces, $rolled ); } return @faces; } sub CurrentFace { my $self = shift; return $self->{'Face'}; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: (ichimunki) Re (tilly) 1: Dice::Dice
by coreolyn (Parson) on Jan 08, 2001 at 20:48 UTC | |
by ichimunki (Priest) on Jan 08, 2001 at 20:57 UTC |