/**
  * @param Identifier $identifier
  * @return Game
  */
 public function get(Identifier $identifier)
 {
     $stmt = $this->pdo->prepare('SELECT data FROM games WHERE id = :id');
     $stmt->execute([':id' => (string) $identifier]);
     if (($column = $stmt->fetchColumn()) == null) {
         throw new \InvalidArgumentException('No game found with that identifier. [' . (string) $identifier . ']');
     }
     return Game::fromArray(json_decode($column, true));
 }
예제 #2
0
 /**
  * @test
  */
 public function it_sinks_a_ship()
 {
     $gridData = ['fields' => [['coords' => ['x' => 0, 'y' => 0], 'shot' => false], ['coords' => ['x' => 0, 'y' => 1], 'shot' => false], ['coords' => ['x' => 1, 'y' => 0], 'shot' => false], ['coords' => ['x' => 1, 'y' => 1], 'shot' => false]], 'ships' => [['startPoint' => ['x' => 0, 'y' => 0], 'endPoint' => ['x' => 0, 'y' => 1], 'hits' => 0], ['startPoint' => ['x' => 1, 'y' => 0], 'endPoint' => ['x' => 1, 'y' => 1], 'hits' => 0]]];
     $data = ['width' => 10, 'height' => 10, 'fields' => $gridData];
     $gameData = ['id' => Uuid::uuid4()->toString(), 'locked' => false, 'grid' => $data, 'fireResults' => []];
     $game = Game::fromArray($gameData);
     $result = $game->fire(Coords::create(0, 0));
     $this->assertEquals('HIT 0.0', (string) $result);
     $result = $game->fire(Coords::create(0, 1));
     $this->assertEquals('SANK 0.1 0.0 0.1', (string) $result);
 }