template.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. if (!interface_exists('MapTemplateInterface')) {
  3. interface MapTemplateInterface
  4. {
  5. public static function id(): string;
  6. public static function applyTemplate($map): void;
  7. public static function tileDefinitions(): array;
  8. }
  9. }
  10. class UrbanTemplate implements MapTemplateInterface
  11. {
  12. public static function id(): string
  13. {
  14. return 'urban';
  15. }
  16. public static function applyTemplate($map): void
  17. {
  18. // Exemple simple : marquer quelques tuiles centrales comme buildings
  19. if (!method_exists($map, 'getHexes')) return;
  20. $hexes = $map->getHexes();
  21. $count = count($hexes);
  22. $i = 0;
  23. foreach ($hexes as $k => $h) {
  24. if ($i++ % 7 === 0) {
  25. if (method_exists($h, 'setTile')) $h->setTile('building');
  26. }
  27. if ($i > 30) break;
  28. }
  29. }
  30. public static function tileDefinitions(): array
  31. {
  32. return [
  33. ['id' => 'building', 'name' => 'Bâtiment', 'color' => '#b0b0b0'],
  34. ['id' => 'road', 'name' => 'Route', 'color' => '#d2b48c'],
  35. ['id' => 'park', 'name' => 'Parc', 'color' => '#7fc97f']
  36. ];
  37. }
  38. }