Ejemplo n.º 1
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)]);
 }
Ejemplo n.º 2
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());
 }