Can you rewrite dragRectangle function to make it so when my mouse is on the other…
- User
Can you rewrite dragRectangle function to make it so when my mouse is on the other column, the picked up rectangle changes positions (so we change the styles from one column to another). So you need to search for the bottom-most rectangle that doesn't have any backgroundcolor and just make draggedRectangles[i] be that rectangle
code<script> const boardWidth = 10; const boardHeight = 17; const numFilledRows = 5; const backgroundMusic = new Audio('../music/backgroundmusic.mp3'); let isGameEnded = false; muteCount = 0; function mute(){ const btn = document.getElementById('mute'); if(muteCount%2 == 0){ btn.textContent = "Unmute"; backgroundMusic.muted = true; }else{ btn.textContent = "Mute"; backgroundMusic.muted = false; } muteCount++; }function restartGame() { // Stop the background music backgroundMusic.pause(); backgroundMusic.currentTime = 0;
// Clear the game board and reset the score document.getElementById("menu").style.display = "none"; const gameBoard = document.getElementById('game-board'); gameBoard.innerHTML = ''; const scoreElement = document.getElementById('score'); scoreElement.innerHTML = 'Score: 0';
// Reset the game variables click = 0; draggedRectangles = []; numberOfRectangles = 0; rectangleColor = null; i = 0; pickedUpRectangles = 0; isGameEnded = false; score = 0; cycle = 1;
// Start a new game startGame(); }
code - Assistant
}
function dragRectangle(event) { if (draggedRectangles.length > 0) { const gameBoard = document.getElementById("game-board"); const boardRect = gameBoard.getBoundingClientRect(); const columnWidth = gameBoard.offsetWidth / boardWidth;
code