/** * @test */ public function it_should_win_the_game_when_all_ships_have_sunk() { $game = Game::create(1, 2, [2]); $result = $game->fire(Coords::fromArray(['x' => 0, 'y' => 0])); $this->assertFalse($result->isWon()); $result = $game->fire(Coords::fromArray(['x' => 0, 'y' => 1])); $this->assertTrue($result->isWon()); }
/** * @param array $fireResult * * @return static */ public static function fromArray(array $fireResult) { return new static($fireResult['result'], Coords::fromArray($fireResult['target']), array_key_exists('x', $fireResult['startPoint']) ? Coords::fromArray($fireResult['startPoint']) : null, array_key_exists('y', $fireResult['endPoint']) ? Coords::fromArray($fireResult['endPoint']) : null); }
/** * @param array $field * @return static */ public static function fromArray(array $field) { return new static(Coords::fromArray($field['coords']), $field['shot']); }
/** * @param array $ship * @return static */ public static function fromArray(array $ship) { return new static(Coords::fromArray($ship['startPoint']), Coords::fromArray($ship['endPoint']), $ship['hits']); }