Пример #1
0
 public function renderGameBoard(Player $player, $checkSquareKey)
 {
     $board = $player->getGame()->getBoard();
     $squares = $board->getSquares();
     $isGameStarted = $player->getGame()->getIsStarted();
     if ($player->isBlack()) {
         $squares = array_reverse($squares, true);
     }
     $x = $y = 1;
     $html = '<div class="lichess_board">';
     foreach ($squares as $squareKey => $square) {
         $html .= sprintf('<div class="lcs %s%s" id="%s" style="top:%dpx;left:%dpx;">', $square->getColor(), $checkSquareKey === $squareKey ? ' check' : '', $squareKey, 64 * (8 - $x), 64 * ($y - 1));
         $html .= '<div class="lcsi"></div>';
         if ($piece = $board->getPieceByKey($squareKey)) {
             if ($isGameStarted || $piece->getPlayer() === $player) {
                 $html .= sprintf('<div class="lichess_piece %s %s"></div>', strtolower($piece->getClass()), $piece->getColor());
             }
         }
         $html .= '</div>';
         if (++$x === 9) {
             $x = 1;
             ++$y;
         }
     }
     $html .= '</div>';
     return $html;
 }