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

(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; }


Comment on (ichi) Re: Dice Game
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (10)
As of 2014-08-21 20:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (143 votes), past polls