Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

(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]
[Corion]: A good morning and weekstart to you too, Discipulus!

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2018-06-25 07:16 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.