Пример #1
0
 function setEndPoint($hexagon)
 {
     if (is_object($hexagon)) {
         $this->endPointX = $hexagon->getX();
         $this->endPointY = $hexagon->getY();
     } else {
         list($this->endPointX, $this->endPointY) = Hexagon::getHexPartXY($hexagon);
     }
 }
Пример #2
0
 function calculateHexpart()
 {
     // center = :, lower = _, lower left = \\, upper left = /
     //    since \ is a javascript escape char, need to check for \\
     $hexagon = new Hexagon();
     $hexagon->setNumber($this->name->substr(8, 4));
     $hexpartTypeLetter = $this->name->charAt(7);
     $this->refHexpartX = $hexagon->getX();
     $this->refHexpartY = $hexagon->getY();
     switch ($hexpartTypeLetter) {
         case ':':
             $this->hexpartType = 1;
             $this->x = $this->refHexpartX;
             $this->y = $this->refHexpartY;
             break;
         case '_':
             $this->hexpartType = 2;
             $this->x = $this->refHexpartX;
             $this->y = $this->refHexpartY + 2;
             break;
         case '\\':
             $this->hexpartType = 3;
             $this->x = $this->refHexpartX - 1;
             $this->y = $this->refHexpartY + 1;
             break;
         case '/':
             $this->hexpartType = 4;
             $this->x = $this->refHexpartX - 1;
             $this->y = $this->refHexpartY - 1;
             break;
         default:
             $this->hexpartType = 1;
             $this->x = $this->refHexpartX;
             $this->y = $this->refHexpartY;
             break;
     }
 }
Пример #3
0
 function terrainGen($mapDoc, $terrainDoc)
 {
     // code, name, displayName, letter, entranceCost, traverseCost, combatEffect, is Exclusive
     $this->terrain->addTerrainFeature("clear", "clear", "c", 1, 0, 0, true);
     $this->terrain->addTerrainFeature("offmap", "offmap", "o", 1, 0, 0, true);
     $this->terrain->addTerrainFeature("blocked", "blocked", "b", "blocked", 0, 0, true, true);
     $terrainArr = json_decode($terrainDoc->hexStr->hexEncodedStr);
     $mapId = $terrainDoc->hexStr->map;
     $map = $mapDoc->map;
     $this->terrain->mapUrl = $mapUrl = $map->mapUrl;
     $this->terrain->maxCol = $maxCol = $map->numX;
     $this->terrain->maxRow = $maxRow = $map->numY;
     $this->terrain->mapWidth = $map->mapWidth;
     $this->mapData->setData($maxCol, $maxRow, $mapUrl);
     Hexagon::setMinMax();
     $this->terrain->setMaxHex();
     $a = $map->a;
     $b = $map->b;
     $c = $map->c;
     $this->terrain->a = $a;
     $this->terrain->b = $b;
     $this->terrain->c = $c;
     $this->terrain->originY = $b * 3 - $map->y;
     $xOff = ($a + $c) * 2 - ($c / 2 + $a);
     $this->terrain->originX = $xOff - $map->x;
     for ($col = 100; $col <= $maxCol * 100; $col += 100) {
         for ($row = 1; $row <= $maxRow; $row++) {
             $this->terrain->addTerrain($row + $col, LOWER_LEFT_HEXSIDE, "clear");
             $this->terrain->addTerrain($row + $col, UPPER_LEFT_HEXSIDE, "clear");
             $this->terrain->addTerrain($row + $col, BOTTOM_HEXSIDE, "clear");
             $this->terrain->addTerrain($row + $col, HEXAGON_CENTER, "clear");
         }
     }
     foreach ($terrainArr as $terrain) {
         foreach ($terrain->type as $terrainType) {
             $name = $terrainType->name;
             $matches = [];
             if (preg_match("/SpecialHex/", $name)) {
                 $this->terrain->addSpecialHex($terrain->number, $name);
             } else {
                 if (preg_match("/^ReinforceZone(.*)\$/", $name, $matches)) {
                     $this->terrain->addReinforceZone($terrain->number, $matches[1]);
                 } else {
                     $tNum = sprintf("%04d", $terrain->number);
                     $this->terrain->addTerrain($tNum, $terrain->hexpartType, strtolower($name));
                 }
             }
         }
     }
 }