Exemplo n.º 1
0
 /**
  * @param PersistableGameStateInterface $persistableGameState
  *
  * @return GameState
  */
 protected function createFromPersistableState(PersistableGameStateInterface $persistableGameState)
 {
     $gameState = new GameState();
     if ($pieceData = $persistableGameState->getPiece()) {
         $piece = PieceFactory::create($pieceData['type'], $pieceData['color'], array_key_exists('id', $pieceData) ? $pieceData['id'] : null);
         $gameState->setPiece($piece);
         $gameState->setColor($persistableGameState->getColor());
         $gameState->setFrom($persistableGameState->getFrom());
         $gameState->setTo($persistableGameState->getTo());
         $gameState->setMoveType($persistableGameState->getMoveType());
         if ($captureData = $persistableGameState->getCapture()) {
             $capturingPiece = PieceFactory::create($captureData['capturing_type'], $captureData['capturing_color'], $captureData['capturing_id']);
             $capturedPiece = PieceFactory::create($captureData['captured_type'], $captureData['captured_color'], $captureData['captured_id']);
             $capture = new Capture($capturingPiece, $capturedPiece, $captureData['position']);
             $gameState->setCapture($capture);
         }
     }
     return $gameState;
 }
Exemplo n.º 2
0
 /**
  * @param MoveInterface $move
  *
  * @return GameState
  */
 private function createStateFromMove(MoveInterface $move)
 {
     if (!$move->getFrom()) {
         return null;
     }
     $gameState = new GameState();
     $gameState->setFrom($move->getFrom());
     $gameState->setTo($move->getTo());
     $gameState->setPiece($move->getPiece());
     $gameState->setCapture($move->getCapture());
     $gameState->setMoveType($move->getType());
     return $gameState;
 }