Player.php
1.52 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
namespace FootyRoom\Core\Predictor;
use FootyRoom\Core\CoreException;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
/**
* @ODM\Document(collection="predictor.players")
*/
class Player
{
/** @var int Amount of points new player gets. */
public const STARTING_POINTS = 1000;
/**
* @ODM\Id
*
* @var string
*/
protected $id;
/**
* @ODM\Field(type="int")
*
* @var int
*/
protected $userId;
/**
* @ODM\Field(type="string")
*
* @var string
*/
protected $username;
/**
* @ODM\Field(type="int", strategy="increment")
*
* @var int
*/
protected $points;
public function __construct(int $userId, string $username)
{
$this->userId = $userId;
$this->username = $username;
$this->points = self::STARTING_POINTS;
}
public function getUserId(): int
{
return $this->userId;
}
public function getUsername(): string
{
return $this->username;
}
public function getPoints(): int
{
return $this->points;
}
public function bet(int $stake = 0)
{
if ($stake > $this->points) {
throw new CoreException('You don\'t have enough points to make this bet.');
}
$this->points -= $stake;
}
public function awardPoints(int $points)
{
if ($points < 0) {
throw new CoreException('You can\'t award less than 0 points.');
}
$this->points += $points;
}
}