コード例 #1
0
 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;
 }
コード例 #2
0
 /**
  * @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)]);
 }
コード例 #3
0
 /**
  * @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;
 }
コード例 #4
0
ファイル: GridTest.php プロジェクト: restgames/battleship-php
 /**
  * @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());
 }
コード例 #5
0
 public function shotAt(Hole $hole)
 {
     return $this->grid->shot($hole);
 }