1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Cards; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* CardGraphic. |
7
|
|
|
*/ |
8
|
|
|
class CardGraphic extends Card |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Constant array containing the UTF-8 characters for the cards in a card playing deck. |
12
|
|
|
*/ |
13
|
|
|
public const GRAPHIC_REPRESENTATION = [ |
14
|
|
|
'A' => ['♥' => '🂱', '♦' => '🃁', '♣' => '🃑', '♠' => '🂡'], |
15
|
|
|
'2' => ['♥' => '🂲', '♦' => '🃂', '♣' => '🃒', '♠' => '🂢'], |
16
|
|
|
'3' => ['♥' => '🂳', '♦' => '🃃', '♣' => '🃓', '♠' => '🂣'], |
17
|
|
|
'4' => ['♥' => '🂴', '♦' => '🃄', '♣' => '🃔', '♠' => '🂤'], |
18
|
|
|
'5' => ['♥' => '🂵', '♦' => '🃅', '♣' => '🃕', '♠' => '🂥'], |
19
|
|
|
'6' => ['♥' => '🂶', '♦' => '🃆', '♣' => '🃖', '♠' => '🂦'], |
20
|
|
|
'7' => ['♥' => '🂷', '♦' => '🃇', '♣' => '🃗', '♠' => '🂧'], |
21
|
|
|
'8' => ['♥' => '🂸', '♦' => '🃈', '♣' => '🃘', '♠' => '🂨'], |
22
|
|
|
'9' => ['♥' => '🂹', '♦' => '🃉', '♣' => '🃙', '♠' => '🂩'], |
23
|
|
|
'10' => ['♥' => '🂺', '♦' => '🃊', '♣' => '🃚', '♠' => '🂪'], |
24
|
|
|
'J' => ['♥' => '🂻', '♦' => '🃋', '♣' => '🃛', '♠' => '🂫'], |
25
|
|
|
'C' => ['♥' => '🂼', '♦' => '🃌', '♣' => '🃜', '♠' => '🂬'], |
26
|
|
|
'Q' => ['♥' => '🂽', '♦' => '🃍', '♣' => '🃝', '♠' => '🂭'], |
27
|
|
|
'K' => ['♥' => '🂾', '♦' => '🃎', '♣' => '🃞', '♠' => '🂮'], |
28
|
|
|
'Joker' => ['Red' => '🂿', 'Black' => '🃏︎', 'White' => '🃟'], |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Constant character for blank card. |
33
|
|
|
*/ |
34
|
|
|
public const BLANK_CARD = '🂠'; |
35
|
|
|
|
36
|
|
|
private string $graphic; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* __construct. |
40
|
|
|
* |
41
|
|
|
* Constructor of the class |
42
|
|
|
* |
43
|
|
|
* @return void |
44
|
|
|
*/ |
45
|
44 |
|
public function __construct(string $rank, string $suite) |
46
|
|
|
{ |
47
|
44 |
|
parent::__construct($rank, $suite); |
48
|
|
|
|
49
|
44 |
|
$this->findGraphic(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* findGraphic. |
54
|
|
|
* |
55
|
|
|
* Finds graphic char that matches the cards rank and suite |
56
|
|
|
*/ |
57
|
44 |
|
private function findGraphic(): void |
58
|
|
|
{ |
59
|
44 |
|
(Card::NO_RANK == $this->rank or Card::NO_SUIT == $this->suit) ? |
60
|
3 |
|
$this->graphic = self::BLANK_CARD : |
61
|
43 |
|
$this->graphic = self::GRAPHIC_REPRESENTATION[$this->rank][$this->suit]; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* setRank. |
66
|
|
|
* |
67
|
|
|
* Sets the rank of the card and updates the graphic |
68
|
|
|
*/ |
69
|
1 |
|
public function setRank(string $rank): void |
70
|
|
|
{ |
71
|
1 |
|
parent::setRank($rank); |
72
|
|
|
|
73
|
1 |
|
$this->findGraphic(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* setSuite. |
78
|
|
|
* |
79
|
|
|
* Sets the suite of the card and updates the graphic |
80
|
|
|
*/ |
81
|
1 |
|
public function setSuit(string $suit): void |
82
|
|
|
{ |
83
|
1 |
|
parent::setSuit($suit); |
84
|
|
|
|
85
|
1 |
|
$this->findGraphic(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* getString. |
90
|
|
|
* |
91
|
|
|
* Returns the graphic |
92
|
|
|
*/ |
93
|
33 |
|
public function getString(): string |
94
|
|
|
{ |
95
|
33 |
|
return $this->graphic; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|