3. First Player Selected
1<?php ...
2
3namespace Thunk\Verbs\Examples\Monopoly\Events\Setup;
4
5use Thunk\Verbs\Attributes\Autodiscovery\AppliesToState;
6use Thunk\Verbs\Event;
7use Thunk\Verbs\Examples\Monopoly\States\GameState;
8
9#[AppliesToState(GameState::class)]
10class FirstPlayerSelected extends Event
11{
12 public function __construct(
13 public int $game_id,
14 public int $player_id,
15 ) {}
16
17 public function validateGame(GameState $game)
18 {
19 $this->assert($game->activePlayer() === null, 'A player has already been selected.');
20 $this->assert($game->hasPlayer($this->player_id), 'This player is not part of the game.');
21 }
22
23 public function applyToGame(GameState $game)
24 {
25 $game->active_player_id = $this->player_id;
26 }
27}