Category: games
Author/Contact Info blumongo@m-net.arbornet.org
Description: this is one of my first small scripts as I am just learning perl. I will clean it up later as I continue my studies. It is just a simulation of a craps game which starts you off with 500 dollars and you bet from there to test your luck, keeps a scoreboard also.
#!/usr/bin/perl
use warnings;
# crapz script by blumongoos
# blumongo@m-net.arbornet.org
# please keep credit to me if distributed

# setting variables and accessing bankfile information

$nick = "";
$fstroll = "0";
$scdroll = "0";
open(BANK, "bank.data") or die "Bank file innaccessable: $!\n";
$bank = <BANK>;
$bet = "0";

# print banner
print '***********************';
print "\n";
sleep 1;
print '***********************';
print "\n";
print '***$$$**|CRAPZ|**$$$***';
print "\n";
sleep 1;
print '********|-----|********';
print "\n";
print '***********************';
print "\n";
sleep 1;
print '***********************';
print "\n";
print 'to exit enter quit';
print "\n";
print 'You have $';
print "$bank\n";

print 'What is your handle (name): ';
chomp($nick = <STDIN>);

# loop for the game
while () {
    print 'Win or go home (type your bet or quit): ';
    chomp($bet = <STDIN>);

if (($bet eq "quit") or ($bet eq "exit")) {
    open(SCORES, ">>scores.data");
    print SCORES "$nick $bank\n";
    print "\n";
    print "SCOREBOARD\n";
    print '----------';
    print "\n";
    open(RSCORES, "scores.data");
    @scores = <RSCORES>;
    print @scores;    
    last;

}

if ($bet > $bank) {
    print 'No cheating you are kicked out of the casino!';
    print "\n";
    last;
}

# generating random first roll
srand;
$fstroll = int(rand 11) + 1;

if ( ($fstroll == '7') or ($fstroll == '11')) {
    sleep 1;
    print "You rolled a $fstroll\n";
    $bank += $bet;         
    print 'You stand at $';
        print "$bank dollars\n";
} 
else {
    print "First roll was $fstroll\n";
    $scdroll = int(rand 11) + 1;

if ($scdroll != $fstroll) {
    $bank -= $bet;    
    sleep 2;
    print "second  roll $scdroll\n";
    print 'You now have $';
    print "$bank dollars\n"; 
    sleep 2; 
}

else {
    $bank += $bet;
}
}
}