UrbanTemplate.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. require_once __DIR__ . '/MapTemplateInterface.php';
  3. if (!class_exists('UrbanTemplate')) {
  4. class UrbanTemplate implements MapTemplateInterface
  5. {
  6. public static function id(): string { return 'urban'; }
  7. public static function applyTemplate(Map $map): void
  8. {
  9. // Simple mise en place : construire un bloc central de bâtiments
  10. $w = $map->getWidth();
  11. $h = $map->getHeight();
  12. // calculer centre approximatif
  13. $centerQ = (int) floor($w / 2);
  14. $centerR = (int) floor($h / 2);
  15. // placer un petit quartier de bâtiments autour du centre
  16. for ($dq = -1; $dq <= 1; $dq++) {
  17. for ($dr = -1; $dr <= 1; $dr++) {
  18. $q = $centerQ + $dq;
  19. $r = $centerR + $dr;
  20. if ($map->isValidCoordinate($q, $r)) {
  21. $map->setTile($q, $r, new Tile(['type' => 'building']));
  22. }
  23. }
  24. }
  25. // tracer deux routes en croix
  26. for ($q = 0; $q < $w; $q++) {
  27. if ($map->isValidCoordinate($q, $centerR)) {
  28. $map->setTile($q, $centerR, new Tile(['type' => 'road']));
  29. }
  30. }
  31. for ($r = 0; $r < $h; $r++) {
  32. if ($map->isValidCoordinate($centerQ, $r)) {
  33. $map->setTile($centerQ, $r, new Tile(['type' => 'road']));
  34. }
  35. }
  36. }
  37. public static function tileDefinitions(): array
  38. {
  39. return [
  40. 'empty' => ['label' => 'Vide', 'walkable' => true],
  41. 'building' => ['label' => 'Bâtiment', 'walkable' => false],
  42. 'road' => ['label' => 'Route', 'walkable' => true],
  43. 'park' => ['label' => 'Parc', 'walkable' => true]
  44. ];
  45. }
  46. }
  47. }