示例#1
0
 /**
  * Reads a specific array data to fill the key class properties.
  *
  * @param array $data
  * @return bool
  */
 public function load(array $data)
 {
     if (isset($data['isSunk'], $data['sunkShips'], $data['grid'], $data['shipsGrid'])) {
         $this->isSunk = $data['isSunk'];
         $this->sunkShips = $data['sunkShips'];
         $this->grid = $data['grid'];
         $this->shipsGrid = new Ships();
         $this->shipsGrid->load($data['shipsGrid']);
         return true;
     }
     return false;
 }
示例#2
0
 /**
  * This method retrieve the stored load by its name.
  */
 public function load()
 {
     $this->battlefield = new Battlefield();
     if (isset($_SESSION['shots'], $_SESSION['battlefield'])) {
         $this->shots = $_SESSION['shots'];
         $this->battlefield->load($_SESSION['battlefield']);
     } else {
         $shipsGrid = new Ships();
         $this->shots = 0;
         $shipsGrid->buildGrid();
         $this->battlefield->buildGrid();
         $this->battlefield->addShipGrid($shipsGrid);
     }
 }