Exemplo n.º 1
0
 /**
  * @param array $data
  * @param array $fields
  * @param object $object
  */
 private function read(array $data, array $fields)
 {
     foreach ($fields as $field => $type) {
         $value = Arrays::getOrThrow($data, $field, new \Exception("missing required '{$field}'"));
         $this->{$field} = $this->valueToType($value, $type);
     }
 }
Exemplo n.º 2
0
 /**
  * @return Hero
  */
 function winner()
 {
     $players = Arrays::sortBy($this->state->game->heroes, function ($hero) {
         return $hero->gold;
     });
     return end($players);
 }
Exemplo n.º 3
0
 /**
  * Reference:
  *     ## Impassable wood
  *     @1 Hero number 1
  *     [] Tavern
  *     $- Gold mine (neutral)
  *     $1 Gold mine (belonging to hero 1)
  *
  * @param string $chars
  * @return Tile
  */
 private static function readTile(Position $pos, $chars)
 {
     static $TILE_CLASSES = array('  ' => 'Vindinium\\Board\\EmptyTile', '##' => 'Vindinium\\Board\\Wood', '[]' => 'Vindinium\\Board\\Tavern', '$-' => 'Vindinium\\Board\\GoldMine');
     if ($Tile = Arrays::get($TILE_CLASSES, $chars)) {
         return new $Tile($pos);
     }
     $heroId = (int) substr($chars, 1);
     if ('@' === $chars[0]) {
         return new Avatar($pos, $heroId);
     }
     if ('$' === $chars[0]) {
         return new GoldMine($pos, $heroId);
     }
     throw new \InvalidArgumentException("Invalid tile: '{$chars}'");
 }
Exemplo n.º 4
0
 /**
  * @internal
  */
 protected function init(array $data)
 {
     $this->userId = Arrays::get($data, 'userId');
     $this->elo = (int) Arrays::get($data, 'elo');
 }
Exemplo n.º 5
0
 /**
  * @param array $data [description]
  */
 function __construct(array $data)
 {
     $this->x = Arrays::getOrThrow($data, 'x');
     $this->y = Arrays::getOrThrow($data, 'y');
 }