コード例 #1
0
ファイル: MapLoader.php プロジェクト: Charlie-Lucas/Zeldoh
 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;
 }
コード例 #2
0
ファイル: Area.php プロジェクト: Charlie-Lucas/Zeldoh
 /**
  * Add coordinateLines
  *
  * @param \Zeldoh\AppBundle\Entity\Map\CoordinateLine $coordinateLines
  * @return Area
  */
 public function addCoordinateLine(\Zeldoh\AppBundle\Entity\Map\CoordinateLine $coordinateLines)
 {
     $this->coordinateLines[] = $coordinateLines;
     $coordinateLines->setArea($this);
     return $this;
 }