RuralTemplate.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. require_once __DIR__ . '/MapTemplateInterface.php';
  3. if (!class_exists('RuralTemplate')) {
  4. class RuralTemplate implements MapTemplateInterface
  5. {
  6. public static function id(): string { return 'rural'; }
  7. public static function applyTemplate(Map $map): void
  8. {
  9. // Simple rural: placer des zones de forêts dispersées
  10. $w = $map->getWidth();
  11. $h = $map->getHeight();
  12. for ($i = 0; $i < max(3, (int)floor(($w*$h)/50)); $i++) {
  13. $q = rand(0, max(0, $w-1));
  14. $r = rand(0, max(0, $h-1));
  15. if ($map->isValidCoordinate($q, $r)) {
  16. $map->setTile($q, $r, new Tile(['type' => 'forest']));
  17. }
  18. }
  19. }
  20. public static function tileDefinitions(): array
  21. {
  22. return [
  23. 'empty' => ['label' => 'Vide', 'walkable' => true],
  24. 'forest' => ['label' => 'Forêt', 'walkable' => false],
  25. 'field' => ['label' => 'Champ', 'walkable' => true]
  26. ];
  27. }
  28. }
  29. }