Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

(ichi) Re: Dice Game

by ichimunki (Priest)
on Jun 03, 2002 at 22:41 UTC ( #171354=note: print w/replies, xml ) Need Help??

in reply to Dice Game

This isn't a very fun game, and for the record my 8 year old daughter learned to code this much Perl in less than four hours. You ought to buy a good book on Perl, like "Learning Perl" and then you could do this yourself.
#!/usr/bin/perl -w use strict; my $bet = 20; my $play = 1; while( $play ) { print "You are betting like $bet tokens\n"; my @dice = ( &roll, &roll, &roll ); print "You rolled: ", join( '-', @dice ), "\n"; if( $dice[0] == $dice[1] and $dice[1] == $dice[2] ) { print "That is 3 of a kind\n"; $bet *= 2; } elsif( $dice[0] == $dice[1] or $dice[1] == $dice[2] or $dice[0] == $dice[2] ) { print "That is a pair\n"; $bet *= 2; } else { print "Sorry you didn't win try again\n"; } print "try again? (type 'y' or 'n' and press Enter)\n"; my $try = <STDIN>; chomp $try; $play = $try eq 'y' ? 1 : 0; } sub roll { return int( 6*rand ) + 1; }

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2016-10-21 22:42 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (291 votes). Check out past polls.