Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

(ichi) Re: Dice Game

by ichimunki (Priest)
on Jun 03, 2002 at 22:41 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2024-04-16 09:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found