Beispiel #1
0
 public function parse($string)
 {
     $map = new Map();
     $parsedLines = explode("\n", $string);
     $lineNumber = sizeof($parsedLines);
     $maxString = 0;
     foreach ($parsedLines as $index => $line) {
         if (strlen($line) > $maxString) {
             $maxString = strlen($line);
         }
     }
     $horizontalAreaNumber = $maxString % 16 == 0 ? $maxString / 16 : ($maxString - $maxString % 16) / 16 + 1;
     $verticalAreaNumber = $lineNumber % 16 == 0 ? $lineNumber / 16 : ($lineNumber - $lineNumber % 16) / 16 + 1;
     $zoneNumber = $verticalAreaNumber * $horizontalAreaNumber;
     for ($i = 0; $i < $verticalAreaNumber; $i++) {
         $areaLine = new AreaLine();
         for ($j = 0; $j < $horizontalAreaNumber; $j++) {
             $area = new Area();
             for ($ii = 0; $ii < 16; $ii++) {
                 $coordinateLine = new CoordinateLine();
                 for ($jj = 0; $jj < 16; $jj++) {
                     $x = $i * 16 + $ii;
                     $y = $j * 16 + $jj;
                     $coordinate = new Coordinate();
                     if (array_key_exists($i * 16 + $ii, $parsedLines) && array_key_exists($y, str_split($parsedLines[$x]))) {
                         $coordinate->setGround($this->findGround(str_split($parsedLines[$x])[$y]));
                     } else {
                         $coordinate->setGround($this->findGround("#"));
                     }
                     $coordinateLine->addCoordinate($coordinate);
                 }
                 $area->addCoordinateLine($coordinateLine);
             }
             $areaLine->addArea($area);
         }
         $map->addAreaLine($areaLine);
     }
     return $map;
 }
 /**
  * Add coordinates
  *
  * @param \Zeldoh\AppBundle\Entity\Map\Coordinate $coordinates
  * @return CoordinateLine
  */
 public function addCoordinate(\Zeldoh\AppBundle\Entity\Map\Coordinate $coordinates)
 {
     $this->coordinates[] = $coordinates;
     $coordinates->setCoordinateLine($this);
     return $this;
 }