-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcard.pm
More file actions
100 lines (68 loc) · 1.49 KB
/
card.pm
File metadata and controls
100 lines (68 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package card;
use strict;
use Switch;
my @suits = qw (h d c s);
my @values = qw (2 3 4 5 6 7 8 9 T J Q K A);
sub new {
my $class = shift;
my $self = {
suit => shift,
value => shift,
};
bless $self;
}
# Getters and Setters -----------------------
sub get_suit {
my $self = shift;
return $self->{suit};
}
sub set_suit {
my $self = shift;
my $suit = shift;
$self->{suit} = $suit;
}
sub get_value {
my $self = shift;
return $self->{value};
}
sub set_value {
my $self = shift;
my $value = shift;
$self->{value} = $value;
}
# Functions ---------------------------------
sub value_of {
my $card = shift;
my $value = $card->get_value();
return $value if $value =~ /\d/;
return 10 if $value =~ /(T|J|Q|K)/;
return 11 if $value =~ /A/;
}
sub get_value_english {
my $card = shift;
my $value = $card->get_value;
switch ($value) {
case 'T' { return "Ten" }
case 'J' { return "Jack" }
case 'Q' { return "Queen" }
case 'K' { return "King" }
case 'A' { return "Ace" }
}
return $value;
}
sub get_suit_english {
my $card = shift;
my $suit = $card->get_suit;
switch ($suit) {
case 'h' { return "Hearts" }
case 's' { return "Spades" }
case 'd' { return "Diamonds" }
case 'c' { return "Clubs" }
}
}
sub is_an_ace {
my $self = shift;
return 1 if $self->get_value eq 'A';
return 0;
}
1;