1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GameDomain\Round\Step; |
4
|
|
|
|
5
|
|
|
use GameDomain\Player\PlayerInterface; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Step Result |
9
|
|
|
*/ |
10
|
|
|
final class StepResult |
11
|
|
|
{ |
12
|
|
|
/** @var \GameDomain\Player\PlayerInterface */ |
13
|
|
|
protected $player; |
14
|
|
|
|
15
|
|
|
/** @var \GameDomain\Round\Step\Answer */ |
16
|
|
|
protected $playerAnswer; |
17
|
|
|
|
18
|
|
|
/** @var \GameDomain\Round\Step\Answer */ |
19
|
|
|
protected $validAnswer; |
20
|
|
|
|
21
|
|
|
/** @var \GameDomain\Round\Step\Step */ |
22
|
|
|
protected $step; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param \GameDomain\Player\PlayerInterface $player |
26
|
|
|
* @param \GameDomain\Round\Step\Answer $playerAnswer |
27
|
|
|
* @param \GameDomain\Round\Step\Answer $validAnswer |
28
|
|
|
* @param \GameDomain\Round\Step\Step $step |
29
|
|
|
*/ |
30
|
|
|
public function __construct( |
31
|
|
|
PlayerInterface $player, |
32
|
|
|
Answer $playerAnswer, |
33
|
|
|
Answer $validAnswer, |
34
|
|
|
Step $step |
35
|
|
|
) { |
36
|
|
|
$this->player = $player; |
37
|
|
|
$this->playerAnswer = $playerAnswer; |
38
|
|
|
$this->validAnswer = $validAnswer; |
39
|
|
|
$this->step = $step; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return \GameDomain\Player\PlayerInterface |
44
|
|
|
*/ |
45
|
|
|
public function getPlayer() |
46
|
|
|
{ |
47
|
|
|
return $this->player; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return \GameDomain\Round\Step\Answer |
52
|
|
|
*/ |
53
|
|
|
public function getPlayerAnswer() |
54
|
|
|
{ |
55
|
|
|
return $this->playerAnswer; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return \GameDomain\Round\Step\Answer |
60
|
|
|
*/ |
61
|
|
|
public function getValidAnswer() |
62
|
|
|
{ |
63
|
|
|
return $this->validAnswer; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return \GameDomain\Round\Step\Step |
68
|
|
|
*/ |
69
|
|
|
public function getStep() |
70
|
|
|
{ |
71
|
|
|
return $this->step; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return bool |
76
|
|
|
*/ |
77
|
|
|
public function isValid() |
78
|
|
|
{ |
79
|
|
|
return $this->playerAnswer->isSameAs($this->validAnswer); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
|
|
public function __toString() |
86
|
|
|
{ |
87
|
|
|
$message = $this->isValid() |
88
|
|
|
? 'Player "%s" correctly answered "%s" at step #%s.' |
89
|
|
|
: 'Player "%s" failed by answering "%s" at step #%s. Correct answer was "%s".'; |
90
|
|
|
|
91
|
|
|
return vsprintf($message, array($this->player, $this->playerAnswer, $this->step, $this->validAnswer)); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|