Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Problems with passing arguments to a subroutine in a perl package

by Anonymous Monk
on Jul 17, 2013 at 01:54 UTC ( #1044696=note: print w/ replies, xml ) Need Help??


in reply to Problems with passing arguments to a subroutine in a perl package

check out the class build-up of the following example i once made for a blackjack game, i couldn't find another example. Compare that with yours.

package Bank; our %kaarten = qw/2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 J 10 Q 10 K 10 + A 11/; our @kaarten = keys(%kaarten); our $totaal; our $azen = 0; our $cor; sub new{ $self = shift; $getal = int(rand(13)); $kaart = @kaarten[$getal]; $waarde = $kaarten{$kaart}; if($waarde == 11){ $azen +=1;} print "Bank heeft een $kaart. Puntentotaal = $waarde.\n"; $totaal += $waarde; return $self; } sub bankspeel{shift; $inze = shift; $to = shift; $saldo = shift; while($totaal<17){ $getal = int(rand(13)); $kaart = @kaarten[$getal]; $waarde = $kaarten{$kaart}; $totaal += $waarde; print "Bank heeft een $kaart. Puntentotaal = $totaal.\n"; if($totaal > 21){ if($azen != 0){ $cor = 10 * $azen; if(($totaal-$cor)>21){ print "Busted, u wint $inze.\n" } else {$totaal = $totaal - $cor; if($totaal<12){$totaal += 10;}} }} if($totaal > 21){ print "Busted.U wint $inze.\n";$saldo+=$inze;print "Uw saldo is $saldo +\n"; exit; } sleep(2); } if($to > $totaal){print "U wint $inze\n";$saldo+=$inze;print "Uw saldo + is $saldo\n"} elsif($to < $totaal){print "U verliest $inze\n";$saldo-=$inze;print "U +w saldo is $saldo\n"} else{ print "stand-off\n";} } sub kaart{ $self = shift; $tot = shift; $getal = int(rand(13)); $kaart = @kaarten[$getal]; print "U heeft een $kaart gekregen\n"; $waarde = $kaarten{$kaart}; $tot += $waarde; return $tot; } sub double{ shift; $to = shift; $getal = int(rand(13)); $kaart = @kaarten[$getal]; print "U heeft een $kaart gekregen\n"; $waarde = $kaarten{$kaart}; $to+=$waarde; print "U past op $to.\n"; return $to; } 1;


Comment on Re: Problems with passing arguments to a subroutine in a perl package
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2014-08-29 03:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (275 votes), past polls