chess.html
You are currently viewing a revision titled "chess.html", saved on 2025年1月31日 9:23 PM by gyanu maya | |
---|---|
タイトル | chess.html |
コンテンツ | Chess Gameconst board = document.getElementById('chessboard'); // Define initial chess pieces const initialBoard = [ ['r', 'n', 'b', 'q', 'k', 'b', 'n', 'r'], ['p', 'p', 'p', 'p', 'p', 'p', 'p', 'p'], ['', '', '', '', '', '', '', ''], ['', '', '', '', '', '', '', ''], ['', '', '', '', '', '', '', ''], ['', '', '', '', '', '', '', ''], ['P', 'P', 'P', 'P', 'P', 'P', 'P', 'P'], ['R', 'N', 'B', 'Q', 'K', 'B', 'N', 'R'] ]; // Function to render the chessboard function renderBoard() { board.innerHTML = ''; for (let row = 0; row < 8; row++) { for (let col = 0; col handleSquareClick(row, col)); board.appendChild(square); } } } let selectedPiece = null; function handleSquareClick(row, col) { if (selectedPiece) { const [selectedRow, selectedCol] = selectedPiece; // Move piece logic here (just for now, moving it to the clicked square) initialBoard[row][col] = initialBoard[selectedRow][selectedCol]; initialBoard[selectedRow][selectedCol] = ''; renderBoard(); selectedPiece = null; } else { if (initialBoard[row][col]) { selectedPiece = [row, col]; } } } renderBoard(); |
抜粋 | |
脚注 |