Verbs

1. Game Started

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\Game\Bank;
8use Thunk\Verbs\Examples\Monopoly\Game\Board;
9use Thunk\Verbs\Examples\Monopoly\States\GameState;
10 
11#[AppliesToState(GameState::class)]
12class GameStarted extends Event
13{
14 public function __construct(
15 public ?int $game_id = null,
16 ) {}
17 
18 public function validate(GameState $game)
19 {
20 $this->assert(! $game->started, 'The game has already started');
21 }
22 
23 public function applyToGame(GameState $game)
24 {
25 $game->started = true;
26 $game->started_at = now()->toImmutable();
27 $game->player_ids = [];
28 $game->board = new Board;
29 $game->bank = new Bank;
30 }
31}