1<?php ...
2
3namespace Thunk\Verbs\Examples\Monopoly\Events\Gameplay;
4
5use InvalidArgumentException;
6use Thunk\Verbs\Attributes\Autodiscovery\AppliesToState;
7use Thunk\Verbs\Event;
8use Thunk\Verbs\Examples\Monopoly\States\GameState;
9use Thunk\Verbs\Examples\Monopoly\States\PlayerState;
10
11#[AppliesToState(GameState::class)]
12#[AppliesToState(PlayerState::class)]
13class RolledDice extends Event
14{
15 use PlayerAction;
16
17 public function __construct(
18 public int $game_id,
19 public int $player_id,
20 public array $dice,
21 ) {
22 if (count($this->dice) !== 2) {
23 throw new InvalidArgumentException('You can only roll two dice.');
24 }
25
26 [$first, $second] = $this->dice;
27
28 if ($first < 1 || $first > 6 || $second < 1 || $second > 6) {
29 throw new InvalidArgumentException('You must roll six-sided dice.');
30 }
31
32 // TODO: If you roll doubles, you get to go again. If you roll 3 times, you go to jail.
33 }
34
35 public function validateGame(GameState $game)
36 {
37 $this->assert($game->last_roll === null, 'You already rolled the dice.');
38 }
39
40 public function applyToGame(GameState $game)
41 {
42 $game->last_roll = $this->dice;
43 }
44}