Exemplo n.º 1
0
 /**
  * Set your handler for each cell!
  *
  * @param callable $handler Callable handler
  * @param array    $additionalParams Additional params array to your handler
  */
 public function cellsHandler(callable $handler, array $additionalParams = array())
 {
     foreach ($this->map->getGrid() as $coordinates) {
         list($x, $y) = $coordinates;
         $cell = $this->getCell($x, $y);
         $handler($cell, $additionalParams);
     }
 }
Exemplo n.º 2
0
 /**
  * Визуализация всей карты
  *
  * @param IMap $map
  */
 public function render(IMap $map)
 {
     $type = $this->type;
     header(sprintf('Content-Type: image/%s', $type));
     $step = $this->tileSize + $this->borderSize;
     $sizeX = $map->getGrid()->getSizeX() * $step + $this->borderSize;
     $sizeY = $map->getGrid()->getSizeY() * $step + $this->borderSize;
     $this->imageResource = imagecreatetruecolor($sizeX, $sizeY);
     $borderColor = imagecolorallocate($this->imageResource, 0, 100, 50);
     imagefill($this->imageResource, 0, 0, $borderColor);
     foreach ($map->getGrid() as $coordinates) {
         list($x, $y) = array($coordinates[0], $coordinates[1]);
         foreach ($map->getLayerVisualisers() as $visualiser) {
             $color = $visualiser->renderCell($x, $y);
             imagefilledrectangle($this->imageResource, $x * $step + 1, $y * $step + 1, $x * $step + $this->tileSize, $y * $step + $this->tileSize, $color);
         }
     }
     $imageFunc = 'image' . $type;
     $imageFunc($this->imageResource);
     imagedestroy($this->imageResource);
 }