-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHand.php
More file actions
33 lines (29 loc) · 683 Bytes
/
Hand.php
File metadata and controls
33 lines (29 loc) · 683 Bytes
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
<?php
class Hand
{
public int $numCards;
public array $cards = [];
public function getCard(int $index): Card
{
$this->numCards--;
return array_splice($this->cards, $index, 1)[0];
}
public function addCard(Card $card): void
{
$this->cards[] = $card;
$this->numCards++;
}
public function sort(): void
{
usort($this->cards, function ($a, $b) {
/**
* @var Card $a
* @var Card $b
*/
if ($a->getRank() === $b->getRank()) {
return 0;
}
return $a->getRank() > $b->getRank() ? 1 : -1;
});
}
}