Exemple #1
0
 /**
  * Generate and shows a battlefield global map
  */
 public function showMap()
 {
     $battlefieldId = filter_input(INPUT_GET, 'battlefieldId', FILTER_SANITIZE_NUMBER_INT);
     $battlefield = new Battlefield($this->_DI, $battlefieldId);
     $battlefieldData = $battlefield->getData();
     $this->picturePath = $battlefield->generateMap();
     $this->battlefieldName = $battlefieldData['name'];
     $this->hives = $battlefieldData['hives'];
 }
 /**
  * Create battlefield with specific size.
  * Randomly place given battleships
  * @param array $battleships battleships to place
  * @param int $sizeX Field x size
  * @param int $sizeY Field y size
  * @return \Model\Battlefield\Battlefield
  */
 public function createBattlefield(array $battleships = [], $sizeX = 10, $sizeY = 10)
 {
     $battlefield = new Battlefield($sizeX, $sizeY);
     foreach ($battleships as $battleship) {
         $validPlacers = $battlefield->getValidPlaces($battleship);
         $randomPlacerKey = array_rand($validPlacers);
         $randomPlacer = $validPlacers[$randomPlacerKey];
         $battlefield->addBattleship($randomPlacer);
     }
     return $battlefield;
 }