private function playerWithValidGrid()
 {
     $battleshipGrid = Grid::fromString('0300222200' . '0300000000' . '0310000000' . '0010005000' . '0010005000' . '0010044400' . '0010000000' . '0000000000' . '0000000000' . '0000000000');
     $player = $this->getMockBuilder('Battleship\\Player\\Player')->getMock();
     $player->method('startGame')->will($this->returnValue(new Game(1, $battleshipGrid)));
     return $player;
 }
 /**
  * @return Hole
  */
 public function fire()
 {
     $this->nextShot += $this->shootingDirection;
     $letters = Grid::letters();
     $numbers = Grid::numbers();
     return new Hole($letters[$this->nextShot / count($numbers)], $numbers[$this->nextShot % count($numbers)]);
 }
 /**
  * @return Game
  */
 public function startGame()
 {
     $res = $this->client->request('POST', $this->endpoint . '/battleship/game');
     $response = json_decode($res->getBody());
     $this->game = new Game($response->gameId, Grid::fromString($response->grid));
     $this->gameId = $this->game()->gameId();
     return $this->game;
 }
Example #4
0
 /**
  * @test
  */
 public function givenAValidGridStringWhenBuildingAndShootingAllTheHolesThenAllShipsMustBeSunkAkaACompleteGame()
 {
     $this->grid = Grid::fromString('0300222200' . '0300000000' . '0310000000' . '0010005000' . '0010005000' . '0010044400' . '0010000000' . '0000000000' . '0000000000' . '0000000000');
     $shotResults = '0100111200' . '0100000000' . '0210000000' . '0010001000' . '0010002000' . '0010011200' . '0020000000' . '0000000000' . '0000000000' . '0000000000';
     $this->assertTrue($this->grid->areAllShipsPlaced());
     $this->assertFalse($this->grid->areAllShipsSunk());
     foreach (Grid::letters() as $l => $letter) {
         foreach (Grid::numbers() as $n => $number) {
             $this->assertSame((int) $shotResults[$l * 10 + $n], $this->grid->shot(new Hole($letter, $number)));
             $this->assertSame((int) $shotResults[$l * 10 + $n], $this->grid->shot(new Hole($letter, $number)));
         }
     }
     $this->assertTrue($this->grid->areAllShipsSunk());
 }
 public function shotAt(Hole $hole)
 {
     return $this->grid->shot($hole);
 }