public function testSetGetValueTrimShot() { $this->event->setType(Event::TYPE_SHOT); // string to trim $this->event->setValue('A1'); $this->assertEquals('A1', $this->event->getValue()); // string with result to trim $this->event->setValue('A2|sunk'); $this->assertEquals('A2', $this->event->getValue()); // array to trim $this->event->setValue(["\t A3 \n", ' hit ']); $this->assertEquals('A3', $this->event->getValue()); }
/** * @param Event $shotEvent * @return string miss|hit|sunk * @throws UnexpectedEventTypeException */ public function getShotResult(Event $shotEvent) { if ($shotEvent->getType() !== Event::TYPE_SHOT) { throw new UnexpectedEventTypeException($shotEvent->getType(), Event::TYPE_SHOT); } $game = $shotEvent->getGame(); $enemyShipsCollection = new CoordsCollection($game->getOtherShips()); $shotCoord = $shotEvent->getValue(); if ($enemyShipsCollection->contains($shotCoord)) { $attackerShots = $this->getAttackerShots($shotEvent); $result = $this->isSunk($shotCoord, $enemyShipsCollection, $attackerShots) ? self::SHOT_RESULT_SUNK : self::SHOT_RESULT_HIT; } else { $result = self::SHOT_RESULT_MISS; } return $result; }