/** * @param Hole $hole * * @return int */ public function shotAt(Hole $hole) { $res = $this->client->request('POST', $this->endpoint . '/battleship/game/' . $this->gameId . '/receive-shot/' . $hole->letter() . '/' . $hole->number()); $response = json_decode($res->getBody()); return $response->result; }
/** * @param Hole $hole * * @return int * * @throws AllShipsAreNotPlacedException */ public function shot(Hole $hole) { if (!$this->areAllShipsPlaced()) { throw new AllShipsAreNotPlacedException('All ships must be placed before shooting'); } $y = Hole::letterToNumber($hole->letter()) - 1; $x = $hole->number() - 1; $shipId = $this->grid[$y][$x]; if ($shipId !== 0) { $this->grid[$y][$x] = -abs($this->grid[$y][$x]); if ($this->isShipSunk($this->ships[abs($shipId)])) { return self::SUNK; } return self::HIT; } return self::WATER; }