|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Stratadox\CardGame\Match; |
|
4
|
|
|
|
|
5
|
|
|
use DateTimeInterface; |
|
6
|
|
|
|
|
7
|
|
|
final class Turn |
|
8
|
|
|
{ |
|
9
|
|
|
private $currentPlayer; |
|
10
|
|
|
private $since; |
|
11
|
|
|
private $canPlay; |
|
12
|
|
|
private $canDefend; |
|
13
|
|
|
|
|
14
|
|
|
public function __construct(int $player, DateTimeInterface $since, bool $play = true) |
|
15
|
|
|
{ |
|
16
|
|
|
$this->currentPlayer = $player; |
|
17
|
|
|
$this->since = $since; |
|
18
|
|
|
$this->canPlay = $play; |
|
19
|
|
|
$this->canDefend = !$play; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function prohibitsPlaying(int $player, DateTimeInterface $when): bool |
|
23
|
|
|
{ |
|
24
|
|
|
return $this->currentPlayer !== $player || |
|
25
|
|
|
!$this->canPlay || |
|
26
|
|
|
$when->getTimestamp() - $this->since->getTimestamp() >= 20; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function prohibitsAttacking(int $player, DateTimeInterface $when): bool |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
// @todo check if time ran out |
|
32
|
|
|
return $this->currentPlayer !== $player; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function prohibitsDefending(int $player, DateTimeInterface $when): bool |
|
36
|
|
|
{ |
|
37
|
|
|
return $this->currentPlayer !== $player || |
|
38
|
|
|
!$this->canDefend || |
|
39
|
|
|
$when->getTimestamp() - $this->since->getTimestamp() >= 20; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function prohibitsStartingCombat(int $player, DateTimeInterface $when): bool |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->currentPlayer !== $player || |
|
45
|
|
|
!$this->canDefend || |
|
46
|
|
|
$when->getTimestamp() - $this->since->getTimestamp() >= 20; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function prohibitsEndingCardPlaying(int $player, DateTimeInterface $when): bool |
|
|
|
|
|
|
50
|
|
|
{ |
|
51
|
|
|
// @todo check if time ran out |
|
52
|
|
|
return $this->currentPlayer !== $player; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function endCardPlayingPhaseFor(int $player): Turn |
|
|
|
|
|
|
56
|
|
|
{ |
|
57
|
|
|
// @todo |
|
58
|
|
|
$this->canPlay = false; |
|
59
|
|
|
return $this; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function endCombatPhase(): Turn |
|
63
|
|
|
{ |
|
64
|
|
|
// @todo add time |
|
65
|
|
|
$this->canDefend = false; |
|
66
|
|
|
$this->canPlay = true; |
|
67
|
|
|
return $this; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function of(int $player, DateTimeInterface $since): Turn |
|
71
|
|
|
{ |
|
72
|
|
|
return new Turn($player, $since, false); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.