height = $this->calculateMapHeight($coffeeMap); $this->width = $this->calculateMapWidth($coffeeMap); $this->remainingTiles = $coffeeMap; } /** * @return int */ public function getHeight() { return $this->height; } /** * @return int */ public function getWidth() { return $this->width; } /** * @return array */ public function getRemainingTiles() { return $this->remainingTiles; } /** * @param $map * @return int */ private function calculateMapHeight($map) { // Count the level 1 array elements return count($map); } /** * @param $map * @return int */ private function calculateMapWidth($map) { $widestRow = 0; foreach ($map as $row) { // Count the level 2 array elements $colWidth = count($row); if ($colWidth > $widestRow) { $widestRow = $colWidth; } } return $widestRow; } /** * @param Tile $tile * @return bool */ public function isValidForTile(Tile $tile) { if ($tile->getX() < 0 || $tile->getY() < 0) { return false; } // Dimensions start from 1 but coordinates from 0, need to compensate if ($tile->getX() > ($this->getWidth() - 1) || $tile->getY() > ($this->getHeight() - 1)) { return false; } return true; } }