示例#1
0
文件: Hex.php 项目: bizley/imperium
 /**
  * Creates new hex based on params.
  * @param array|string $data
  * @param boolean $hidden
  * @param string $owner player
  * @return Hex
  */
 public static function create($data, $hidden = false, $owner = null)
 {
     $hex = new Hex();
     if (is_array($data)) {
         $hex->setType(self::TYPE_SPACE);
         if (!empty($data['planets'])) {
             foreach ($data['planets'] as $name) {
                 $hex->getPlanets()->add(Planet::create($name, $owner));
             }
         }
         if (!empty($data['wormhole'])) {
             $hex->setWormhole($data['wormhole']);
         }
     } else {
         switch ($data) {
             case self::WORMHOLE_ALPHA:
             case self::WORMHOLE_BETA:
                 $hex->setType(self::TYPE_SPACE);
                 $hex->setWormhole($data);
                 break;
             case self::TYPE_SPACE:
             case self::TYPE_NEBULA:
             case self::TYPE_ASTEROID:
             case self::TYPE_NOVA:
                 $hex->setType($data);
         }
     }
     if ($hidden) {
         $hex->setHidden($hidden);
     }
     return $hex;
 }