| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- require_once __DIR__ . '/MapTemplateInterface.php';
- if (!class_exists('UrbanTemplate')) {
- class UrbanTemplate implements MapTemplateInterface
- {
- public static function id(): string { return 'urban'; }
- public static function applyTemplate(Map $map): void
- {
- // Simple mise en place : construire un bloc central de bâtiments
- $w = $map->getWidth();
- $h = $map->getHeight();
- // calculer centre approximatif
- $centerQ = (int) floor($w / 2);
- $centerR = (int) floor($h / 2);
- // placer un petit quartier de bâtiments autour du centre
- for ($dq = -1; $dq <= 1; $dq++) {
- for ($dr = -1; $dr <= 1; $dr++) {
- $q = $centerQ + $dq;
- $r = $centerR + $dr;
- if ($map->isValidCoordinate($q, $r)) {
- $map->setTile($q, $r, new Tile(['type' => 'building']));
- }
- }
- }
- // tracer deux routes en croix
- for ($q = 0; $q < $w; $q++) {
- if ($map->isValidCoordinate($q, $centerR)) {
- $map->setTile($q, $centerR, new Tile(['type' => 'road']));
- }
- }
- for ($r = 0; $r < $h; $r++) {
- if ($map->isValidCoordinate($centerQ, $r)) {
- $map->setTile($centerQ, $r, new Tile(['type' => 'road']));
- }
- }
- }
- public static function tileDefinitions(): array
- {
- return [
- 'empty' => ['label' => 'Vide', 'walkable' => true],
- 'building' => ['label' => 'Bâtiment', 'walkable' => false],
- 'road' => ['label' => 'Route', 'walkable' => true],
- 'park' => ['label' => 'Parc', 'walkable' => true]
- ];
- }
- }
- }
|