-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRank.php
54 lines (43 loc) · 1.03 KB
/
Rank.php
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
<?php
namespace BlackJack;
class Rank
{
const RANK_ACE = 1;
const RANK_KING = 13;
const RANK_QUEEN = 12;
const RANK_JACK = 11;
const RANK = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];
public function __construct(private int $rank)
{
$this->rank = $rank;
}
public function getRank(): int
{
return $this->rank;
}
public function convertToString(): string
{
$string = '';
switch ($this->rank) {
case self::RANK_ACE:
$string = 'A';
break;
case self::RANK_JACK:
$string = 'J';
break;
case self::RANK_QUEEN:
$string = 'Q';
break;
case self::RANK_KING:
$string = 'K';
break;
default:
$string = $this->getRank();
}
return $string;
}
public function getScore()
{
return $this->rank < self::RANK_JACK ? $this->getRank() : 10;
}
}