/** * @test */ public function it_hits_a_sunken_ship() { $data = ['startPoint' => ['x' => 2, 'y' => 2], 'endPoint' => ['x' => 2, 'y' => 4], 'hits' => 0]; $ship = Ship::fromArray($data); $ship->hit(); $ship->hit(); $ship->hit(); $ship->hit(); $this->assertTrue($ship->hasSunk()); }
/** * @test */ public function it_shoots_a_field_which_already_been_hit() { $data = ['startPoint' => ['x' => 2, 'y' => 2], 'endPoint' => ['x' => 2, 'y' => 4], 'hits' => 2]; $ship = Ship::fromArray($data); $field = Field::generate(1, 1); $field->shoot(); $field->place($ship); $this->setExpectedException(FieldAlreadyBeenShotException::class); $field->shoot(); }
/** * @test */ public function it_sinks_a_ship_in_fields_with_a_ship() { $fields = []; $data = ['startPoint' => ['x' => 1, 'y' => 1], 'endPoint' => ['x' => 1, 'y' => 2], 'hits' => 1]; $ship = Ship::fromArray($data); $field = Field::generate(1, 1); $field->place($ship); $fields[] = $field; $field = Field::generate(1, 2); $field->place($ship); $fields[] = $field; $fieldsClass = Fields::create($fields); $fieldsClass->shoot(Coords::create(1, 1)); $this->assertEquals(true, $fieldsClass->didShipSankAt(Coords::create(1, 1))); $this->assertEquals(true, $fieldsClass->didAllShipsSink()); }