use strict; use integer; use Tom::Cardplay; my $play1 = Cardplay->new(); $play1->{NAME} = "Ergowolf"; print "$play1->{NAME}\n"; # add cards &Cardplay::deal; push(@{ $play1->{CARDS} }, $_); push(@{ $play1->{VALUES} }, $value); &Cardplay::deal; push(@{ $play1->{CARDS} }, $_); push(@{ $play1->{VALUES} }, $value); print "@{ $play1->{CARDS} }\n"; print "@{ $play1->{VALUES} }\n"; #### package Cardplay; use strict; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); use Exporter(); @ISA = qw(Exporter); @EXPORT_OK = qw( $value %deck &deal &total ); use vars qw( $value %deck &deal &total ); $VERSION = '1.00'; # import a scalar # It turns out I replaced this with # $_ so I didn't need it # my $card1 = $Cardplay::card; # print "The card is $card1.\n"; # $card = "Ace"; $value; # This is the card deck # You can test this with the code bellow # my %deck1 = %Cardplay::deck; # my $single = $deck1{'2 of spades'}; # print "The single card is $single.\n"; %deck = ( '2 of spades' => 2, '3 of spades' => 3, '4 of spades' => 4, '5 of spades' => 5, '6 of spades' => 6, '7 of spades' => 7, '8 of spades' => 8, '9 of spades' => 9, '10 of spades' => 10, 'Jack of spades' => 10, 'Queen of spades' => 10, 'King of spades' => 10, 'Ace of spades' => 11, '2 of hearts' => 2, '3 of hearts' => 3, '4 of hearts' => 4, '5 of hearts' => 5, '6 of hearts' => 6, '7 of hearts' => 7, '8 of hearts' => 8, '9 of hearts' => 9, '10 of hearts' => 10, 'Jack of hearts' => 10, 'Queen of hearts' => 10, 'King of hearts' => 10, 'Ace of hearts' => 11, '2 of clubs' => 2, '3 of clubs' => 3, '4 of clubs' => 4, '5 of clubs' => 5, '6 of clubs' => 6, '7 of clubs' => 7, '8 of clubs' => 8, '9 of clubs' => 9, '10 of clubs' => 10, 'Jack of clubs' => 10, 'Queen of clubs' => 10, 'King of clubs' => 10, 'Ace of clubs' => 11, '2 of diamonds' => 2, '3 of diamonds' => 3, '4 of diamonds' => 4, '5 of diamonds' => 5, '6 of diamonds' => 6, '7 of diamonds' => 7, '8 of diamonds' => 8, '9 of diamonds' => 9, '10 of diamonds' => 10, 'Jack of diamonds' => 10, 'Queen of diamonds' => 10, 'King of diamonds' => 10, 'Ace of diamonds' => 11, ); sub new { my $self = {}; $self->{NAME} = undef; $self->{TOTAL} = undef; $self->{CARDS} = []; $self->{VALUES} = []; bless($self); # but see below return $self; } # This is a routine to randomly deal cards # from the deck # You can test this with the code bellow # my @player = qw( red green ); # &Cardplay::deal; # push(@player, $_); # for (@player) { # print "list $_\n"; # } sub deal { $_ = (keys %deck)[rand keys %deck]; $value = $deck{"$_"}; return $_; return $value # I pushed two variables to @_ } # This subroutine compares for the larger score # I need to write the code for this based on how # OOP players turns out sub total { # if ($total > $dtotal) { # print "\n\nThe player wins with $total.\n"; # } else { # print "\n\nThe dealer wins with $dtotal.\n"; # } } END {}