public function testKey() { $point = new Point(6, 7); $secontPoint = new Point(2, 2); $pointCollection = new PointCollection([$point, $secontPoint]); $this->assertEquals(0, $pointCollection->key()); $pointCollection->next(); $this->assertEquals(1, $pointCollection->key()); }
/** * Used to check if game should end * @return boolean */ public function isThereNonSunkBattleship() { foreach ($this->placers as $placer) { foreach ($placer->getPoints() as $placerPoint) { if (!$this->shots->hasPoint($placerPoint)) { return true; } } } return false; }
/** * Get all point used by palcer. * * Placer with points [0.0] : [0.2] * have points [0.0], [0.1], [0.2] * @return \Model\Battlefield\Point\PointCollection */ public function getPoints() { $startX = $this->getStartPoint()->getX(); $startY = $this->getStartPoint()->getY(); $endX = $this->getEndPoint()->getX(); $endY = $this->getEndPoint()->getY(); /* * Horizontal placement */ $return = new Point\PointCollection(); if ($startY == $endY) { for ($i = $startX; $i <= $endX; $i++) { $return->addPoint(new Point\Point($i, $startY)); } } else { for ($i = $startY; $i <= $endY; $i++) { $return->addPoint(new Point\Point($startX, $i)); } } return $return; }